What is Deprecation Meaning?
"Deprecation", warning raised, by the Java compiler, is very common to a Java programmer. It is raised when the programmer uses a method that is found faulty or problematic. A substitute method will be available in the later versions. For example, readLine() method of DataInputStream was deprecated in JDK 1.1 and in its place readLine() method of BufferedReader is advised to use. The deprecated method can be removed from JDK in the future versions.
Following list gives the reasons for a method to deprecate by the designers.
- A substitute feature may exist which is more robust. For example, the readLine() method of DataInputStream of JDK 1.0 is deprecated in favor of readline() method of BufferedReader in JDK 1.1
- The feature may result in bugs. For example, StringBufferInputStream class of byte streams is deprecated in favor of StringReader of character streams as StringBufferInputStream does not convert the characters properly into bytes. In the same way, LineNumberInputStream is replaced with LineNumberReader.
- Better code may be available to support a feature. Introduction of generics is good example introduced in JDK 1.5.
- When structural changes are made in the language design. PrintStream constructors are deprecated and advised to discontinue its usage in favor of PrintWriter.
- Present day requirements may demand better compatibility. HttpServlet was introduced for GenericServlet to support standard HTTP protocol.
Whenever a programmer finds a deprecation warning while compilation, to know which method is deprecated in his program, he may compile as follows.
General compilation: javac DateDemo.java
Present Compilation: javac –deprecation DateDemo.java
Now the compiler displays a list of methods, if exist, that are deprecated used in the program.