This week's book giveaways are in the Java EE and JavaScript forums.
We're giving away four copies each of The Java EE 7 Tutorial Volume 1 or Volume 2(winners choice) and jQuery UI in Action and have the authors on-line!
See this thread and this one for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Help needed with class literal Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Help needed with class literal" Watch "Help needed with class literal" New topic
Author

Help needed with class literal

Ranjitha Serginaro
Greenhorn

Joined: Jan 10, 2013
Posts: 2
I was going through literals in javadocs where i came across this sentence "Finally, there's also a special kind of literal called a class literal, formed by taking a type name and appending ".class"; for example, String.class. This refers to the object (of type Class) that represents the type itself." which doesn't make any sense to me even though i paid attention to all the other topics prior to this. If any one could explain with examples or references it would be greatly appreciated. The link to the javadocs page displaying this is below.
http://docs.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html
Jeanne Boyarsky
internet detective
Marshal

Joined: May 26, 2003
Posts: 30356
    
150

You can write without having to use the new operator. This is true for the class object too.

No "new" to be found in that code. The Class class isn't used much until you do more advanced Java like reflection. At which point, it is used for Reflection to look up methods/fields on the Class.


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
 
wood burning stoves
 
subject: Help needed with class literal