0% found this document useful (0 votes)
52 views15 pages

Object Oriented Programming

- Java was developed at Sun Microsystems in 1991 and formally announced in 1995. It is an object-oriented language where the unit of a program is the class from which objects are created. - Java programs are compiled to bytecode that can run on any Java Virtual Machine, making Java platform independent. The main method is where program execution begins. Key features include automatic memory management and single inheritance. - Common Java elements include variables declared with a type, methods, classes, and primitive data types like int, boolean, and char. Comments are denoted with // for single-line or /* */ for multi-line.

Uploaded by

Pragash rishi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
52 views15 pages

Object Oriented Programming

- Java was developed at Sun Microsystems in 1991 and formally announced in 1995. It is an object-oriented language where the unit of a program is the class from which objects are created. - Java programs are compiled to bytecode that can run on any Java Virtual Machine, making Java platform independent. The main method is where program execution begins. Key features include automatic memory management and single inheritance. - Common Java elements include variables declared with a type, methods, classes, and primitive data types like int, boolean, and char. Comments are denoted with // for single-line or /* */ for multi-line.

Uploaded by

Pragash rishi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 15

www.hndit.

com

Object Oriented Programming


www.hndit.com
www.hndit.com

Developed at Sun Microsystems in 1991


James Gosling, initially named “OAK”
Formally announced java in 1995
Object oriented and cant write procedural
programs
Functions are called methods
Unit of a program is the class from which
objects are created
Automatic garbage collection
Single inheritance only
www.hndit.com

Each class contains data and methods


which are used to manipulate the data
Programs are small and portable
Multithreaded which allows several
operations to be executed concurrently
A rich set of classes and methods are
available in java class libraries
Platform Independent
Case sensitive
www.hndit.com

Java program development


Edit – use any editor
Compile – use command ‘javac’ if your program
compiles correctly, will create a file with extension
.class
Execute – use the command ‘java’
www.hndit.com

Java language keywords


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.
www.hndit.com

First java Program

class FirstPro {
public static void main(String args[]) {
System.out.println("Hello World!“);
}
}
www.hndit.com

Java Source files


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
www.hndit.com

Top level elements appears in a file


If these are present then they must appear in the
following order.
 Package declarations
 Import statements
 Class definitions
www.hndit.com

Identifiers
An identifier is a word used by a programmer to name
a variable, method class or label.
 Keywords may not be used as an identifier
 Must begin with a letter, a dollar sign($) or an
underscore( _ ).
 Subsequent character may be letters, digits, _ or $.
 Cannot include white spaces.
ref: Note
www.hndit.com

Declaring Variables

Type identifier;
Type identifier=initial value;
www.hndit.com

Primitive Data Types


Type 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)
www.hndit.com

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 name
String name = "Gumboot"; // as above, with an initial
value
boolean finished; // to hold "true" if finished
boolean finished = false; // as above, but with an initial
value
www.hndit.com

Declarations and Assignments


Declarations
int grade;
char answer;
String name;

Assignments
grade = 70;
answer = 'a';
name = "alan turing";
www.hndit.com

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

You might also like