File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Datatype and variables?? 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 "Datatype and variables??" Watch "Datatype and variables??" New topic

Datatype and variables??

geetha nagarajan
Ranch Hand

Joined: Jul 13, 2001
Posts: 94
Does every java variable use a datatype?
I thought the answer was ,Yes:each variable must be declared with it's datatype.
But, the answer given,datatypes r optional.Pl.clarify.
Jose Botella
Ranch Hand

Joined: Jul 03, 2001
Posts: 2120
Can you give us the question in its context? Otherwise I agree with you. Every variable has an associated type. Even though, sometimes the type is not declared:
int[] array = new int[2];
The declared type of the variable array is int[]. However there are also two variables created.
array[0] and array[1] are variables with no names. In order to access them we use array access expressions. Both variables still have an associated type int, though such type was not declared. This is a subtlety anyway

SCJP2. Please Indent your code using UBB Code
geetha nagarajan
Ranch Hand

Joined: Jul 13, 2001
Posts: 94
There was no specific context ,it was just a random question.Check out Question 4 in the below link.
[ Corrected URL ]
[ May 31, 2002: Message edited by: Jessica Sant ]
I agree. Here's the link:
subject: Datatype and variables??
jQuery in Action, 3rd edition