| Introduction | Java Syntax |
| Object-Oriented Programming |

The fundamental unit of programing in Java is the class. A class is a collection of data and methods that operate on that data. The data and methods, taken together, serve as a blueprint for several objects with similar characteristics. The following example is taken from Java In A Nutshell by David Flanagan.
Suppose we wanted to define a class that describes the properties of circles. Every circle can be described by the (x,y) coordinate of its center and also by its radius. Each circle may have a unique center and radius, but as a class, circles have certain intrinsic properties that can be captured in a definition. The following is a very simple definition of the class of circles in Java.
public class Circle {
public double x,y; //coordinates of the center
public double r; //radius
//Methods that return the circumference and area of a circle
public double circumference() {return 2*3.14159*r;}
public double area() {return 3.14159*r*r}
}
Objects
An object is simply an instance of a class. Above we defined the class Circle, and
want to use it. But we can't work with the general class of circles themselves, we need
a particluar circle to work with. We need an instance of the class, a single circular
object:
Circle c = new Circle(); //initilize our circle to have center (2,2) and radius = 1.0 c.x = 2.0; c.y = 2.0; c.r = 1.0; //invoke the area method a = c.area();
The first line creates an instance of the Circle class a circle object. The next three lines initialize variables. The last line invokes the area method. The area method has no arguments because it is implicit in the language that a method operates on an instance of the class in which it is defined.
The beauty of object-oriented programming, particularly Java, lies in its organization of classes and objects. Every time I want to calculate the area and/or of a circle, I don't have to rewrite the same code. I can simply create an instance of the Circle class (a circle object) to make calculations pertaining to a particular circle. Java programmers can use a class over and over again to create many objects.

The most important thing to remember about statements is that they must end in a semicolon.int L =20; import java.applet.Applet; nFigures = 0;
Variable Names
Variable names in Java can start with a letter, an underscore (_), or a dollar
sign ($). Also, note that Java is case-sensitive, so "Hello" is different from "hello".
The naming convention in Java is to use meaningful variable names often consisting of
several words, the first word lowercase but the first letter of each following word is
capitalized. An example:
int thisIsAReallyLongVariableName;
Declaring Variables
Variables are usually declared at the beginning of a method definition. Variable
declarations must include a type and name, such as:
int x1; String lastName;
Variable Types
The variable type defines what values that variable can hold, and can be one of the
following:
There are 8 basic primitive data types which handle integers, floating point numbers, characters, and boolean values (true or false). They are called primitive because they're built into the language and are not actual objects.
| Type | Size | Range |
|---|---|---|
| byte | 8 bits | -128 to 127 |
| short | 16 bits | -32,768 to 32,767 |
| int | 32 bits | -2,147,483,648 to 2,147,483,647 |
| long | 64 bits | -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807 |