• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
annamaneni sampath
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3159
33
Google App Engine Java Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
annamaneni sampath
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
 
Matthew Brown
Bartender
Posts: 4567
8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 20545
56
Chrome Eclipse IDE Java Windows
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Campbell Ritchie
Sheriff
Pie
Posts: 49361
62
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 12143
30
Chrome Java Linux
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Matthew Brown
Bartender
Posts: 4567
8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Edit: too slow (and predictable)!
 
Campbell Ritchie
Sheriff
Pie
Posts: 49361
62
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you, both of you.

Fred rarely beats me . . . now, Rob Spoor, that's a different story.
 
Rob Spoor
Sheriff
Pie
Posts: 20545
56
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It's my biggest hobby, beating Campbell. I especially like it when the difference is just a few seconds.
 
Campbell Ritchie
Sheriff
Pie
Posts: 49361
62
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
But very occasionally, I manage to get in before Rob
 
Rob Spoor
Sheriff
Pie
Posts: 20545
56
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Usually when I'm off doing real work, instead of, well, being Campbell
 
Campbell Ritchie
Sheriff
Pie
Posts: 49361
62
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Rob Spoor wrote: . . . well, being Campbell
Have you ever been Campbell?
 
Rob Spoor
Sheriff
Pie
Posts: 20545
56
Chrome Eclipse IDE Java Windows
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I tried, but I didn't really like it
 
Campbell Ritchie
Sheriff
Pie
Posts: 49361
62
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I tried it too, but seem to have liked it more than you.
 
Rob Spoor
Sheriff
Pie
Posts: 20545
56
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I would definitely hope so!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic