class : Java Glossary

go to home page C words local find full screen, hide local find menu Google search web for more information on this topic jump to foot of page translate this page with Babelfish by Roedy Green ©1996-2009 Canadian Mind Products
index page for letter ⇒ punctuation 0-9 A B C D E F G H I J K L M N O P Q R S T U V W X Y Z (all)
class
A class in Java is much like one in C++. It consists of a group of related methods and variables lumped together under one name. The static class variables are for class-as-a-whole data. They are allocated only once at load time and are shared by all instances of objects of that class. The instance variables, are allocated inside each object of that class. Static class methods work when there is no current object. They can only reference static class variables and static methods, unless of course they allocate an object and then use explicit references to the instance variables. Instance methods work by default on the fields of the current this object.

Let’s say you had a TV class to deal with television sales. There are two kinds of variables:

  1. static variables that track facts about all televisions in general, e.g. total sold or a list of manufacturers.
  2. instance (non-static) variables that track facts about individual televisions, e.g. manufacturer, serial number, diagonal, type LCD/CRT etc.
The facts about televisions in general are stored in static variables, only one copy of the variable for the whole TV class. The facts about individual televisions are stored in instance variables TV objects instantiated with new. There is one copy of each instance field per TV object.

Similarly, there are static methods about televisions in general and instance methods about particular televisions. Unless you have a TV object, you can’t call any of the instance methods. You don’t need a TV object to call one of the TV static methods. static methods may only look at the static fields. Instance methods may look at either the static or instance fields.

There can be only one public class in each source file. If your class was called HelloWorld the name of the source file must be precisely HelloWorld.java with every letter exactly matching even in case. In Java, there is no such thing as a method or variable that does not belong to some class. Java comes with a built-in set of classes arranged in a class hierarchy.

Class is also a class that will tell you various facts about a given class.

Where Did that Class Come From?

Sometimes you want to know where a class or resource came from. Which jar, which directory. This may help track down problems with duplicates or obsolete versions.

Learning More

Sun’s Javadoc on the Class hierarchy class : available:
Sun’s Javadoc on the all classes class : available:
Sun’s Javadoc on the Class class : available:

CMP homejump to top
CMP logo
feedback Please email your feedback for publication, errors, omissions, broken/redirected link reports
and suggestions to improve this page to Roedy Green : feedback email
made with CSS
HTML Checked!
ICRA ratings logo
mindprod.com IP:[65.110.21.43]
Your face IP:[38.103.63.62] The information on this page is for non-military use only.
You are visitor number 26,713. Military use includes use by defence contractors.
You can get a fresh copy of this page from: or possibly from your local J: drive (Java virtual drive/mindprod.com website mirror)
http://mindprod.com/jgloss/class.html J:\mindprod\jgloss\class.html