Escolar Documentos
Profissional Documentos
Cultura Documentos
Features of Java
1 OOL Object Oriented Language
2 platform Independance
3. Architectural neutral Independent of OS
4. JVM
5. ByteCode intermediate code JVM can understand
6. PAcakages is dierectory in file system and collection of class.
7. interfaces; purely abstract nothing defined in interface.
8. JNI - To access system resources
9. Exception Handling
10. MultiThreading
11. Two Types of Program
A. Application Program or Stand alone program always starts at paticular
point hich is Main function
B. Applet Program
When we compile java file we get class file, class file consists of ByteCode.
JVM can understand only ByteCode.
Java is multilevel single inhertance.
A
B E
C
D
we cannot have A and B both being parent of C
A B
C not possible.
Data types
Character
Floating
char
(2)
float
(4)
double
(8)
Integer
Boolean
short (2)
boolean (1) value true/false
int
long
byte
(4)
(8)
(1)
Arrays
Arrays are object in java
ex
int num[] = new int[5];
A arr[] = new A[5]; intial value of array is null; starts from zero
A arr[][] = new A[5][] each row can have different length her 5 rows
arrr[0][3] = { new A(), new A(10),new A(20,'xx') }
Modifiers
abstract
static
final
native
transient
synchronized
access Specifiers.
access Specifiers
{
f need to have instance
}
NAtive Modifiers
NAtive modifier used in JNI concept
public class A
{
public native void f1(); declare only and no defnition. Definition will be in o
ther language like C or C++
}
abstract modifier
public class A
{
public abstract void f1(); declare only and no defnition. Definition will be su
b/child class in java
}
static modifier
static can be give any member of the class but not class itself.
static means global for all the objects.
static memory allocation will be in method allocation area.
instance variable non static will be allocated in heap
static variable get only once when the class is loaded into jvm in the method a
rea;
similarly static method which can be used globaly across all the objects.
static members are accessed through class names itself. A.disp();
you can also access use object A a1 = new A(); a1.disp(); internal java will ch
eck the access specifier
and since it is static it will access through class.
all non static members are accessed through object variables. A a1 = new A(); a
1.i;
there two types of members in a class
instance member any non static variable in a instance is instance member
class member any static variable in a instance is class member
similarly methods instance methods and class methods
you cannot/donot access the instance member or instance variable directly in st
atic method.
you have to create instance of the object and then you have to access
or you have to pass the instance object and the access the member through that
object
in instance method you can access both static and non-static members.
public class A
{
static double pi;
int A;
char ch;
Void set() { }
void get() {}
static void disp() {}
}
Instance block and static block
you can have any number of Instance block and static block any where in the cla
ss.
Static block written using the keyword static
static {
}
instance block no keyword
{
}
static block executed when it is loaded into jvm after creating static variable
s then static block is executed only once for a class.
instance block executed every time when instance of a class is created and bef
ore constructor is called
since you can have any number of static and instance block the sequence of exec
ution is sequence of appearance in the class