Win a copy of Terraform in Action this week in the Cloud forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Rob Spoor
  • Bear Bibeault
Saloon Keepers:
  • Jesse Silverman
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • Al Hobbs
  • salvin francis

assert a Keyword?

 
Piyush Jain
Ranch Hand
Posts: 60
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
According to Kathy S and Bert B book java will treat assert as a legal identifier if the assertion is not turned on.

now in the exam if its asked about whether assert is a keyword or used assert as an identifier. What the answer should be, if they don't say anything about turning on the assertion.

Thanks
 
Jay Pawar
Ranch Hand
Posts: 411
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I believe if nothing is mentioned then ASSERT should be treated as keyword.
Anybody with different opinion ?
 
Tom Tolman
Ranch Hand
Posts: 83
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The answer is no- it is not a keyword. Here are the keywords:

http://java.sun.com/docs/books/tutorial/java/nutsandbolts/_keywords.html
 
Piyush Jain
Ranch Hand
Posts: 60
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Tom.

How about the legal identifier thing? what would be the answer in case nothing is said about whether assert is enabled or not?
 
Gian Franco
blacksmith
Posts: 979
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
WAIT

I would say it is a keyword (assertions)

A simple test with your java 1.4.x version gives the result.
Try to name a member variable 'assert' and you will get
something like the following:


C:\projects\misc>javac Test.java
Test.java:10: warning: as of release 1.4, assert
is a keyword, and may not be used as an identifier
String assert = "XXX";
^
1 warning


That's if you are going for SCJP1.4.

Cheers,

Gian Franco Casula
[ September 08, 2004: Message edited by: Gian Franco Casula ]
 
Piyush Jain
Ranch Hand
Posts: 60
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for the reply.

do you see any different behavior if you switch on the assertions? or assert is a keyword "always"?

this is confusing. can anybody confirm this please.
 
Kathy Sierra
Cowgirl and Author
Posts: 1589
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You should definitely treat "assert" as a keyword, for the exam. It has been officially added as a keyword, even though the option exists to "act" as though you are using an earlier version of the language in which you might have used assert as an identifier since it wasn't yet a keyword.

But for the exam, "assert" is absolutely considered a keyword.

cheers,
Kathy
 
JulianInactive KennedyInactive
Ranch Hand
Posts: 823
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
assert is a reserved word (keyword if you like) as of Java 1.4. This is the case regardless of whether assertions are enabled or disabled. In previous versions of Java assert is not a reserved word.

I would suggest that if you're doing the latest version of SCJP (i.e. 1.4), and you are asked if assert is a reserved word (keyword) then you should answer yes.

Jules
 
Piyush Jain
Ranch Hand
Posts: 60
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks a lot Kathy, Julian.

I can close the topic now.
 
Barry Gaunt
Ranch Hand
Posts: 7729
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
To be really, really sure:

The addition of the assert keyword to the Java programming language does not cause any problems with preexisting binaries (.class files). If you try to compile an application that uses assert as an identifier, however, you will receive a warning or error message. In order to ease the transition from a world where assert is a legal identifier to one where it isn't, the compiler supports two modes of operation in this release:

* source mode 1.3 (default) � the compiler accepts programs that use assert as an identifier, but issues warnings. In this mode, programs are not permitted to use the assert statement.
* source mode 1.4 � the compiler generates an error message if the program uses assert as an identifier. In this mode, programs are permitted to use the assert statement.

Unless you specifically request source mode 1.4 with the -source 1.4 flag, the compiler operates in source mode 1.3. If you forget to use this this flag, programs that use the new assert statement will not compile. Having the compiler use the old semantics as its default behavior (that is, allowing assert to be used as an identifier) was done for maximal source compatibility. Source mode 1.3 is likely to be phased out over time.



Comes from here.
 
Piyush Jain
Ranch Hand
Posts: 60
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Barry.

Thats exactly what the book says.

But for the exam, I will go with what Kathy and Julian said.

assert is a "KEYWORD" FOR SCJP 1.4
 
Ramesh Kumar Koyya
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Piyush Jain wrote:According to Kathy S and Bert B book java will treat assert as a legal identifier if the assertion is not turned on.

now in the exam if its asked about whether assert is a keyword or used assert as an identifier. What the answer should be, if they don't say anything about turning on the assertion.

Thanks



Before 1.4 version or lower version like 1.3 or 1.2 versions assert is treated as a identifier

In 1.4 version assert is a keyword

so use lower versions to compile the keyword

you can't compile 1..4 or above version assert is a identifier it gives compile time error

example
class Test
{
public static void main(String args[])
{
int assert=10;
System.out.println(assert);
}
}

compile javac -source 1.3 Test.java
it shows some warnings but it works

run it java Test

i hope you understand it

 
Henry Wong
author
Posts: 23909
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Ramesh Kumar Koyya wrote:
Before 1.4 version or lower version like 1.3 or 1.2 versions assert is treated as a identifier

In 1.4 version assert is a keyword

so use lower versions to compile the keyword

you can't compile 1..4 or above version assert is a identifier it gives compile time error

example
class Test
{
public static void main(String args[])
{
int assert=10;
System.out.println(assert);
}
}

compile javac -source 1.3 Test.java
it shows some warnings but it works

run it java Test

i hope you understand it




Thanks... but ... This topic is over 10 years old. I am pretty sure that the OP is no longer interested in this question. Also, the certification for Java 1.4 has been end-of-life'd many years ago. You can't get a Java 1.4 certification (or 1.2 or 1.3 either) anymore.

Henry
 
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic