DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

+ Reply to Thread
Results 1 to 8 of 8
  1. #1
    Join Date
    Oct 2002
    Posts
    6

    Smile Why do I have to use -d to compile?

    Here I have a file named Hello1.java but when i compile it, it generates a message. So, I compile it again with -d.

    javac -d Hello1.java

    Why do i have to use '-d'?
    Is there any other ways to compile the file?

    -------------Hello1.java-------------
    import java.awt.Frame;
    import java.awt.FlowLayout;
    import java.awt.Label;

    public class Hello1 extends Frame
    {
    private String message = "";
    private Label messageLabel = new Label("Message Text");

    public static void main(String args[])
    {
    Hello1 me = new Hello1("Hello World");
    me.printMessage(args[0]);
    }

    public Hello1(String message)
    {
    this.message = message;

    setLayout(new FlowLayout());
    add(messageLabel);
    resize (200, 50);
    show();
    }

    private void printMessage(String messageType)
    {
    GeneralMessagePrinter newPrinter = null;

    if (messageType.equals("l"))
    newPrinter = new LowerCaseMessagePrinter(message);
    else if (messageType.equals("u"))
    newPrinter = new UpperCaseMessagePrinter(message);

    messageLabel.setText(newPrinter.getMessage());
    }
    }

    class GeneralMessagePrinter
    {
    private String message;

    public GeneralMessagePrinter(String message)
    {
    this.message = message;
    }

    public String getMessage()
    {
    return (message);
    }
    }

    class LowerCaseMessagePrinter extends GeneralMessagePrinter
    {
    public LowerCaseMessagePrinter(String message)
    {
    super(message.toLowerCase());
    }
    }

    class UpperCaseMessagePrinter extends GeneralMessagePrinter
    {
    public UpperCaseMessagePrinter(String message)
    {
    super(message.toUpperCase());
    }
    }
    -----------end of Hello1.java--------

  2. #2
    Join Date
    Nov 2002
    Posts
    138
    that -d option puts the class file in a specified directory if i remember it right. hmmm... so you don't have to do that unless you want to. is it a compile-error message? or just a warning? like maybe it's warning you of a deprecated class? you should be able to compile normally by just using javac. are there user paths set or packages anywhere?

  3. #3
    Join Date
    Oct 2002
    Posts
    6
    Originally posted by xylex_blaiste
    that -d option puts the class file in a specified directory if i remember it right. hmmm... so you don't have to do that unless you want to. is it a compile-error message? or just a warning? like maybe it's warning you of a deprecated class? you should be able to compile normally by just using javac. are there user paths set or packages anywhere?
    It shows this message:
    Note: Hello1.java uses or overrides a deprecated API.
    Note: Recompile with -deprecation for details.

  4. #4
    Join Date
    Nov 2002
    Posts
    138
    note that not all warnings mean error and the compiler will stop compiling your class. that particular error just tells you that your class uses a deprecated API. it still compiles as it should. if you want to know which parts are deprecated use that option as advised by the message. - d is not -deprecation. compile a class with no deprecated parts in it and see if the message still apears.

  5. #5
    Join Date
    Oct 2002
    Posts
    6
    Originally posted by xylex_blaiste
    note that not all warnings mean error and the compiler will stop compiling your class. that particular error just tells you that your class uses a deprecated API. it still compiles as it should. if you want to know which parts are deprecated use that option as advised by the message. - d is not -deprecation. compile a class with no deprecated parts in it and see if the message still apears.
    what is deprecation API?

  6. #6
    Join Date
    Mar 2003
    Posts
    834

    Thumbs up

    OK. Deprecated APIs are classes and methods which were supplied with an earlier version of Java. However, use of these methods and classes is now discouraged, usually because a serious design flaw has been found in them and new classes and/or methods have been written to replace them.

    If you use a deprecated API, the java compiler will warn you. If you want to find out *which* deprecated classes and methods you're using, you should re-compile the classes with the -deprecation switch (not -d, that's something different).

    Hope this is clear,

    ArchAngel.
    ArchAngel.
    O:-)

  7. #7
    Join Date
    Mar 2003
    Posts
    834
    C:\docs\forums\deprecation_test>javac -deprecation Hello1.java
    Hello1.java:22: warning: resize(int,int) in java.awt.Component has been deprecated
    resize (200, 50);
    ^
    1 warning


    This means that the method 'resize(int, int)' in the Java class java.awt.Component should no longer be used. If you look at the Java API:

    file:///C:/bin/Java/SDK/1.3.1/docs/api/java/awt/Component.html#resize(java.awt.Dimension)

    You see that you should now call resize() with a Dimension object.
    ArchAngel.
    O:-)

  8. #8
    Join Date
    Nov 2002
    Posts
    138
    ya, better to heed these warnings as they (deprecated methods/classes) will soon be phased-out...but javac still compiled your classes and it can be run. like i said, it's not an error. only a warning.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


Top DevX Stories

Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL


Sponsored Links