aspose file tools*
The moose likes Beginning Java and the fly likes about variable defining Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "about variable defining" Watch "about variable defining" New topic
Author

about variable defining

Ali Gilani
Ranch Hand

Joined: Mar 01, 2002
Posts: 137
hello,

1)Is

'Long variable' the same as 'long variable'? will they both compile?

2) i wrote a small program, and the named the CLASS Fruit. I then saved the file as fruit.java (notice the capitalization) . When i typed javac fruit.java, an error was given, however when i type javac Fruit.java(even thought the file doesnt exist), the program complies to a class file. why is that??

3) In a program i declare ' long ali=1L'

later in the program i wish to change the value of 'ali' to 8

do i type ali=8 or ali=8L?


thanks
Stan James
(instanceof Sidekick)
Ranch Hand

Joined: Jan 29, 2003
Posts: 8791
1) Long and "long" are not the same. The all lower case "long" is a primitive type. The variable really holds the bits of a longish number. The capitalized "Long" is a class so your variables holds a pointer to an object of type Long. The bits for the number are inside that object.

Why have a Long class? The Long class has instance and class methods that may be useful, and there are times like putting values in a List where you must use objects, not primitives. Long, Integer, and others like that are often called "wrapper" classes, because they wrap primitive numbers with real objects. Java 5 can automatically convert between primitives and wrappers some times, but it still pays to be fully aware of the difference.

2) Neat experiment. Here's what I get from it: The name you give to Javac must exactly match the class declaration in the file. Windows however ignores case and can find the file "fruit" even when you say "Fruit". I'm a bit surprised the compiler doesn't do more checking, but maybe the Windows version is a bit lazy.

3) Try it and see!
[ June 09, 2005: Message edited by: Stan James ]

A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: about variable defining