Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

about variable defining

 
Ali Gilani
Ranch Hand
Posts: 137
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic