File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Beginning Java and the fly likes Strange class declaration Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Strange class declaration" Watch "Strange class declaration" New topic

Strange class declaration

Panseer Kaur
Ranch Hand

Joined: Nov 01, 2007
Posts: 44
Hey, I've been reading the forum for a while trying to learn Java. More recently I thought it would be a good idea to try to read the Java source code to the libraries. This has been pretty helpful but then I came across this line in

public static final Class TYPE = Class.getPrimitiveClass("int");

This really confused me because I thought if we are defining a class it had to be:

public static final Class TYPE {

TYPE () {

return Class.getPrimitiveClass("int");


I know there are anonymous classes, is it possible this is what this is?

Thanks ahead of time
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14074

Welcome to JavaRanch.

public static final Class TYPE = Class.getPrimitiveClass("int");

Note that it says "Class" with a capital C, not "class" with a lower-case c.

The word "class" with a lower-case c is a Java keyword that is used to declare new classes, but the word "Class" with a capital C is something completely different: it's the class named "Class" in the java.lang package.

So, TYPE is an instance of class Class in the line of code above. It's not a class declaration at all. Do you see?

Look up the API documentation of class java.lang.Class.
[ November 01, 2007: Message edited by: Jesper Young ]

Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 7 API documentation
Scala Notes - My blog about Scala
Panseer Kaur
Ranch Hand

Joined: Nov 01, 2007
Posts: 44
Yup I get it. Makes perfect sense now.

Should have been obvious to me. Thanks though
subject: Strange class declaration
Similar Threads
Data Type Mappings
public static final int in javafx
Defining values(URGENT)
Inner Classes - Static Declaration
how to use main xml file in layout-land folder ?