File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

const in java

 
Nancy Antony
Ranch Hand
Posts: 145
Java Linux Oracle
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 15150
31
Android IntelliJ IDE Java Scala Spring
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"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 ]
 
Diego Fernandez
Greenhorn
Posts: 1
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The same thing happens with keyword goto
 
Nancy Antony
Ranch Hand
Posts: 145
Java Linux Oracle
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic