Developed at Sun Microsystems in 1991 James Gosling, initially named “OAK” Formally announced...
-
Upload
tracy-booker -
Category
Documents
-
view
214 -
download
0
Transcript of Developed at Sun Microsystems in 1991 James Gosling, initially named “OAK” Formally announced...
Object Oriented Programming
Developed at Sun Microsystems in 1991
James Gosling, initially named “OAK”Formally announced java in 1995Object oriented and cant write
procedural programsFunctions are called methodsUnit of a program is the class from
which objects are createdAutomatic garbage collectionSingle inheritance only
Each class contains data and methods which are used to manipulate the data
Programs are small and portableMultithreaded which allows several
operations to be executed concurrently
A rich set of classes and methods are available in java class libraries
Platform IndependentCase sensitive
Edit – use any editorCompile – use command ‘javac’ if
your program compiles correctly, will create a file with extension .class
Execute – use the command ‘java’
Java program development
Keywords are special reserved words in java that you cannot use as identifiers for classes, methods or variables. They have meaning to the compiler, it uses them to understand what your source code is trying to do.
Java language keywords
class FirstPro { public static void main(String args[]) { System.out.println("Hello World!“); } }
First java Program
All java source files must end with the extension ‘.java’
Generally contain at most one top level public class definition
If a public class is present, the class name should match the file name
Java Source files
If these are present then they must appear in the following order.Package declarationsImport statementsClass definitions
Top level elements appears in a file
An identifier is a word used by a programmer to name a variable, method class or label.Keywords may not be used as an identifierMust begin with a letter, a dollar sign($) or an
underscore( _ ).Subsequent character may be letters, digits, _
or $.Cannot include white spaces. ref: Note
Identifiers
Type identifier;Type identifier=initial value;
Declaring Variables
Primitive Data TypesType Bits Range
boolean 1 true, false
char 16 0 to 65,535
byte 8 -128 to +127
short 16 -32,768 to +32,767
int 32 -232 to +232-1
long 64 -264 to +264-1
float 32 -3.4E+38 to +3.4E+38 (approx)
double 64 -1.8E+308 to +1.8E+308 (approx)
int grade; // an integer to hold a grade, no initial value
int grade = 0; // an integer to hold a grade with initial value 0
char answer; // an answer to something – one character
String name; // a string to hold a nameString name = "Gumboot"; // as above, with an
initial valueboolean finished; // to hold "true" if finishedboolean finished = false; // as above, but with
an initial value
Declarationsint grade;char answer;String name;
Assignmentsgrade = 70;answer = 'a';name = "alan turing";
Declarations and Assignments
Default Values
Data Type Default Value (for fields)
byte 0
short 0
int 0
long 0L
float 0.0f
double 0.0d
char '\u0000'
String (or any object) null
boolean false