aspose file tools*
The moose likes Beginning Java and the fly likes What is -Xlint in compiling java program?why this is done? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "What is -Xlint in compiling java program?why this is done?" Watch "What is -Xlint in compiling java program?why this is done?" New topic
Author

What is -Xlint in compiling java program?why this is done?

annamaneni sampath
Greenhorn

Joined: Mar 15, 2011
Posts: 4
when i compile my sql program. i come across these error please help me
\\code
public class main {
^
Note: C:\Users\Admin\Desktop\MySQLAccess.java uses or overrides a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
1 error
\\code
Mohamed Sanaulla
Saloon Keeper

Joined: Sep 08, 2007
Posts: 3071
    
  33

From the javac page-

-deprecation
Show a description of each use or override of a deprecated member or class. Without -deprecation, javac shows a summary of the source files that use or override deprecated members or classes. -deprecation is shorthand for -Xlint:deprecation.


can you show us the code? You have used some deprecated methods or classes due to which the compiler is suggesting to compile with the deprecation option so that you can remove these deprecated usages. Deprecated code is the one that would be removed in the next release of JDK.


Mohamed Sanaulla | My Blog
annamaneni sampath
Greenhorn

Joined: Mar 15, 2011
Posts: 4
Matthew Brown
Bartender

Joined: Apr 06, 2010
Posts: 4460
    
    8

I tried compiling that. Firstly I hit an error because main is a public class, so needs to be in its own file. That can be fixed just by removing the public, though.

Then, with -Xlint:deprecation added to the compiler arguments, you get this message:
warning: [deprecation] Date(int,int,int) in java.sql.Date has been deprecated
preparedStatement.setDate(4, new java.sql.Date(2009, 12, 11));


Looking at the Javadocs for java.sql.Date, you can see that the constructor that takes a year/month/day has been deprecated. You should use the other constructor that takes a long value. And you can construct the long value using the Calendar class. Something like:

By the way, before you get caught up in the trap - your month value is 12. Months are zero-indexed in Java!
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19759
    
  20

To be more precise, months are Calendar.JANUARY based. Now that happens to be 0, but it shows you that you should use Calendar.JANUARY, Calendar.FEBRUARY, ..., Calendar.DECEMBER instead of 0, 1, ..., 11. The latter will confuse people (they'll think 11 is November, not December), using Calendar.DECEMBER won't.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39784
    
  28
The tool lint is a long-established tool for finding errors and bugs in code. I don't know why it is called lint.
fred rosenberger
lowercase baba
Bartender

Joined: Oct 02, 2003
Posts: 11475
    
  16

Campbell Ritchie wrote:The tool lint is a long-established tool for finding errors and bugs in code. I don't know why it is called lint.

The term was derived from the name of the undesirable bits of fiber and fluff found in sheep's wool.
--Wikipedia


There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
Matthew Brown
Bartender

Joined: Apr 06, 2010
Posts: 4460
    
    8

Edit: too slow (and predictable)!
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39784
    
  28
Thank you, both of you.

Fred rarely beats me . . . now, Rob Spoor, that's a different story.
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19759
    
  20

It's my biggest hobby, beating Campbell. I especially like it when the difference is just a few seconds.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39784
    
  28
But very occasionally, I manage to get in before Rob
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19759
    
  20

Usually when I'm off doing real work, instead of, well, being Campbell
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39784
    
  28
Rob Spoor wrote: . . . well, being Campbell
Have you ever been Campbell?
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19759
    
  20

I tried, but I didn't really like it
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39784
    
  28
I tried it too, but seem to have liked it more than you.
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19759
    
  20

I would definitely hope so!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: What is -Xlint in compiling java program?why this is done?