This week's book giveaway is in the Mac OS forum.
We're giving away four copies of a choice of "Take Control of Upgrading to Yosemite" or "Take Control of Automating Your Mac" and have Joe Kissell on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes const in java Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "const in java" Watch "const in java" New topic
Author

const in java

Nancy Antony
Ranch Hand

Joined: Sep 06, 2007
Posts: 145

Can anyone tell how to use const keyword in java. If it could be used, then what is the difference b/w const and final. If it const cannot be used then why there is a keyword available ?
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14193
    
  20

"const" is a reserved word, but it has no function in Java. You cannot use it.

The most likely reason why it's there is because it was inherited from C++. In the first version of Java, the language designers decided to reserve the word "const", with the idea of maybe implementing it in a later version of Java. But to date, it hasn't been implemented.
[ April 09, 2008: Message edited by: Jesper Young ]

Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 8 API documentation
Diego Fernandez
Greenhorn

Joined: Apr 10, 2008
Posts: 1
The same thing happens with keyword goto
Nancy Antony
Ranch Hand

Joined: Sep 06, 2007
Posts: 145

You are right.

I tried this code

class GotoDemo {

public static void main(String args[]){
System.out.println("prints hello 5 times");
int n=1;

printing5times:
System.out.println("Hello Nancy");
if ( n < 5) {
n++;
goto printing5times;
}
}
}

it gives compile time error.

Thanks for sharing knowledge.
 
GeeCON Prague 2014
 
subject: const in java