Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

What is "Recompile with depreciation"?

Posted on 1999-07-04
7
Medium Priority
?
661 Views
Last Modified: 2008-03-17
Using JDK.1.1.7 on my PC I try to compile a series of classes called calculator.java. When compiling these classes The compiler keeps giving me a "Warning", which goes as follows:

 calculator.java uses a deprecated API. recompile with  "-depreciation" for details.

I don't know what that means. What do I do? Do I need a newer version of JDK, or do I need to add some extra arguments into the command line? Either way I feel like a complete idiot and would like some help!
0
Comment
Question by:luinzi
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
7 Comments
 
LVL 1

Expert Comment

by:figueira
ID: 1245224
You need to compile with the "-deprecation" command line option for the javac; it will indicate you the lines of the files that contain invocations to "deprecated" methods (or methods that can be removed in future versions, so you shouldn't use them).
0
 

Author Comment

by:luinzi
ID: 1245225
Sorry figueira, that hasn't really told me anything more than what the compiler said. You can have 60 points if you could explain in a little more detail what I would need to type into the command line and what is happening with the methods. Thanks.....
0
 
LVL 1

Expert Comment

by:figueira
ID: 1245226
Well, let's go a little further. Most of the "what to do when I find a deprecation message?" can be found in the URL
http://java.sun.com/products/jdk/1.1/docs/guide/awt/HowToUpgrade.html
because most of the changes were made in the AWT. I guess an example will be better.

Supposing I'm trying to compile the following class:

public class MyApplet extends Applet {
   private Label l;
   public void init() {
      this.setLayout(null);
      Button b = new Button("Show");
      b.reshape(10, 10, 50, 20);
      add(b);
      b = new Button("Hide");
      b.reshape(100, 10, 50, 20);
      add(b);
      l = new Label("Test");
      l.reshape(10, 50, 100, 20);
      add(l);
   }

   public boolean handleEvent(Event evt, Object obj) {
      if (evt.target instanceof Button) {
         String name = (String) evt.arg;
         if (name.equals("Show")) {
            l.show();
         } else {
            l.hide();
         }
         return true;
      }
      return false;
   }
}

Compiling it with the -deprecation flag in the javac, I'll get the following messages:

-------
MyApplet.java:9: Note: The method void reshape(int, int, int, int) in class java
.awt.Component has been deprecated.
      b.reshape(10, 10, 50, 20);
               ^
MyApplet.java:12: Note: The method void reshape(int, int, int, int) in class jav
a.awt.Component has been deprecated.
      b.reshape(100, 10, 50, 20);
               ^
MyApplet.java:15: Note: The method void reshape(int, int, int, int) in class jav
a.awt.Component has been deprecated.
      l.reshape(10, 50, 100, 20);
               ^
MyApplet.java:23: Note: The method void show() in class java.awt.Component has b
een deprecated.
            l.show();
                  ^
MyApplet.java:25: Note: The method void hide() in class java.awt.Component has b
een deprecated.
            l.hide();
                  ^
Note: MyApplet.java uses a deprecated API.  Please consult the documentation for
 a better alternative.
-------
Looking for the specification for the method in the class java.awt.Component (in the API, which can be found at http://www.javasoft.com/products/jdk/1.1/docs/api/packages.html, following the links to java.awt package, and then to the Component class), you can see the following comment in the reshape(int,int,int,int) method:
------
Note: reshape() is deprecated. As of JDK version 1.1, replaced by setBounds(int, int, int, int).
------
so, if I replace the call to reshape to an equivalent call to setBounds, this problem will be solved. Most of the deprecated methods have similar notes when you look in the documentation.

correcting all problems found, let's try to compile the class again:
------
public class MyApplet extends Applet {
   private Label l;
   public void init() {
      this.setLayout(null);
      Button b = new Button("Show");
      b.setBounds(10, 10, 50, 20);
      add(b);
      b = new Button("Hide");
      b.setBounds(100, 10, 50, 20);
      add(b);
      l = new Label("Test");
      l.setBounds(10, 50, 100, 20);
      add(l);
   }

   public boolean handleEvent(Event evt, Object obj) {
      if (evt.target instanceof Button) {
         String name = (String) evt.arg;
         if (name.equals("Show")) {
            l.setVisible(true);
         } else {
            l.setVisible(false);
         }
         return true;
      }
      return false;
   }
}
------
Depending on your compiler, the compilation at this time will succeed, or fail due to the overriding of the handleEvent method. In the latter case, you should change the class design to conform with the new event model introduced in JDK 1.1. Those changes are documented in the first URL I gave you.

A final version of the class could be as follows:
------
public class MyApplet extends Applet implements ActionListener {
   private Label l;
   public void init() {
      this.setLayout(null);
      Button b = new Button("Show");
      b.setBounds(10, 10, 50, 20);
      add(b);
      b.addActionListener(this);
      b = new Button("Hide");
      b.setBounds(100, 10, 50, 20);
      add(b);
      b.addActionListener(this);
      l = new Label("Test");
      l.setBounds(10, 50, 100, 20);
      add(l);
   }

   public void actionPerformed(ActionEvent evt) {
      String name = evt.getActionCommand();
      if (name.equals("Show")) {
         l.setVisible(true);
      } else {
         l.setVisible(false);
      }
   }

}
------
is it ok now?
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
LVL 6

Expert Comment

by:Holger101497
ID: 1245227
Just a quick hint (although I think figueira has answered this one pretty well) that might help a bit:

You said "depreciation" - in fact, it is "deprecated", which (kind of) means "made obsolete". Some of the methods you use have been replaced. Therefore, you theoretically wouldn't need a newer JDK, but an older one. *g*

That wouldn't make sense, of course. You can easily ignore those warnings for the moment, but your code might not "compile" any more in even newer JDKs. It's better (style and such) to adjust your code as described above.

Good luck!
0
 

Author Comment

by:luinzi
ID: 1245228
Thanks people......That was most helpful figueira. I would like to try and award you 70 points for that......I,m fairly new to this so if you don't get the points (as I have probably done something wrong!) please email me at luinz@hotmail.com. Once again ....Thanks
0
 
LVL 1

Accepted Solution

by:
figueira earned 280 total points
ID: 1245229
Well, thank you for the points! We'll be here for anything you need.
0
 

Author Comment

by:luinzi
ID: 1245230
THANK YOU..........
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
In this post we will learn different types of Android Layout and some basics of an Android App.
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.
Suggested Courses

730 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question