• 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

about variable defining

 
Ranch Hand
Posts: 137
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
(instanceof Sidekick)
Posts: 8791
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
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