Deprecation Meaning

Deprecation Meaning

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.

Deprecation Reasons

Following list gives the reasons for a method to deprecate by the designers.

  1. 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
  2. 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.
  3. Better code may be available to support a feature. Introduction of generics is good example introduced in JDK 1.5.
  4. When structural changes are made in the language design. PrintStream constructors are deprecated and advised to discontinue its usage in favor of PrintWriter.
  5. 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
Present Compilation: javac –deprecation

Now the compiler displays a list of methods, if exist, that are deprecated used in the program.

One thought on “Deprecation Meaning

Leave a Reply

Your email address will not be published. Required fields are marked *