File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes doubt in assert... Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "doubt in assert..." Watch "doubt in assert..." New topic
Author

doubt in assert...

Ganeshkumar cheekati
Ranch Hand

Joined: Oct 13, 2008
Posts: 362


assert can be used as an identifier in java1.3 and lower versions.
but it is not allowed to use it higher of java1.4 versions because it is a keyword.

when i am compiling above code using java1.3

javac -source 1.3 AssertTest1.java

it is giving compilation error as

AssertTest.java:6: warning: as of release 1.4, 'assert' is a keyword, and may not be used as an identifier
(use -source 1.4 or higher to use 'assert' as a keyword)
int assert;
^


why?


[ November 06, 2008: Message edited by: Ganeshkumar cheekati ]

SCJP5 and SCWCD1.5
Think Twice Act Wise...
Jayachandran Natarajan
Greenhorn

Joined: Nov 06, 2008
Posts: 1
Hi Ganesh,

It looks like a warning, not an Error..

Regards
Jay
[ November 06, 2008: Message edited by: Jay ]
Ganeshkumar cheekati
Ranch Hand

Joined: Oct 13, 2008
Posts: 362
what should we do to remove this warning ?
[ November 06, 2008: Message edited by: Ganeshkumar cheekati ]
Ankit Garg
Sheriff

Joined: Aug 03, 2008
Posts: 9317
    
  17

well you are using a 1.4 compiler or higher. That compiler knows that assert is now a keyword. So when you use -source 1.3, it warns you (not gives error) that assert is now a keyword.

If you use actual 1.3 or older compiler, you will get no warnings.

To remove this warning you will have to change the name of the variable in main method (however than the question will be of no use)...


SCJP 6 | SCWCD 5 | Javaranch SCJP FAQ | SCWCD Links
Ganeshkumar cheekati
Ranch Hand

Joined: Oct 13, 2008
Posts: 362
eventhough i am using
javac -source 1.3 AssertTest1.java it is giving warning at compile time and finally i got output at runtime.
Vijitha Kumara
Bartender

Joined: Mar 24, 2008
Posts: 3858

eventhough i am using
javac -source 1.3 AssertTest1.java it is giving warning at compile time and finally i got output at runtime


Warnings are not Errors. They are like well, Warnings !!! Just to keep you informed about some important things compiler won't held responsible?


SCJP 5 | SCWCD 5
[How to ask questions] [Twitter]
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14423
    
  23

Jay, welcome to JavaRanch. Please check your private messages. You can see them by clicking My Private Messages.


Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 8 API documentation
krishna pr
Greenhorn

Joined: Oct 28, 2008
Posts: 8
Try Giving Java -version
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: doubt in assert...