File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes about .class for primitive types and void Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "about .class for primitive types and void" Watch "about .class for primitive types and void" New topic
Author

about .class for primitive types and void

Gasan Guseynov
Ranch Hand

Joined: Jan 03, 2006
Posts: 67
Hello, everyone.

I found that .class could be applied to primitives and void. I completely don't understand what . means then. I always thought that . is like c++ ->, so it returning a reference to a field and then dereferecing it. But how this can be applied to the primitive types? Or does this mean that primitive types in java are also objects? Please, advise. Many thanks.
Vijitha Kumara
Bartender

Joined: Mar 24, 2008
Posts: 3829

Gasan Gouseinov wrote:Or does this mean that primitive types in java are also objects?


No. They are not. People debate that java is not 100% object oriented because of this.

SCJP 5 | SCWCD 5
[How to ask questions] [Twitter]
Gasan Guseynov
Ranch Hand

Joined: Jan 03, 2006
Posts: 67
What . (dot) means then?
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24184
    
  34

The C language has been called "high level assembler", because there's almost always a one-to-one correspondence between a language construct and specific assembly instructions. Since the first C++ compiler was a special preprocessor for a C compiler, C++ is pretty much the same way. The dot operator does indeed translate into a very specific kind of dereferencing.

But Java is different; it's a somewhat higher level language, and many language constructs don't map directly onto virtual machine instructions. Many operators give rise to different code depending on how they're used. The dot operator in Java is definitely one of those.

In Java, "dot class" construct is handled entirely by the compiler. Although it might look like it, no class actually has a member named "class", and could not, of course, since "class" is a reserved word in Java. Anyway, when the compiler sees ".class" attached to a type name, it know how to substitute the appropriate Class object. For primitives, there are Class objects available as constants named TYPE in the corresponding wrapper classes -- i.e. int.class is changed to java.lang.Integer.TYPE . For other types, the compiler creates a private member variable in the class being compiled to hold the Class object, and generates code to initialize that member using Class.forName() .


[Jess in Action][AskingGoodQuestions]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: about .class for primitive types and void