wood burning stoves
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

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: 15092

"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

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;

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

it gives compile time error.

Thanks for sharing knowledge.
I agree. Here's the link: http://aspose.com/file-tools
subject: const in java
It's not a secret anymore!