Вы находитесь на странице: 1из 4

Identifiers and literls:

Identifiers : which will identify themslves in the program, uniquely (var)


Literals : Integer (10,20,30 <- baase 10 <- decimals) (10101101 <- base 2 <-
binary), hexa, oct, floats, char (a,b,c)

Identifiers :
1. byte
2. short
3. int , long
4. float , double
5. char

Octal : 0-7
00001 = 1 00007 = 7
00010 = 8
00011 = 9

** Control Structures
1. Loops (for , while , do-while)
2. Non loops -> decision control structures (if , if-else, switch)

int a = 3;
if(a == 3){ //true
if(a > 3){
/-/------1
}else{
//-------2 -------------------------------
}
if(a < 5){ // true
//--------3 --------------------------------
}else{
//--------4
}

if(a == 3){ //----------------only one in the structure can be true


/---------------1
}else if( a < 5){
//--------------2
}else if( a >2 ){
//------------3
}else if(a == 5){
//------------------4
}

Class and Object :


Class : IS A COLLECTION OF OBJECT
Object : TEMPLATE OF A CLASS

Class :
1. attributes ( properties ) <---- member of a class
2. methods ( behaviour ) <---- member of a class

Ex : Vehicles <--- classification


vehicle has-a cost -- ( has-a relationship is used to test for
attributes)
------------- color
------------- company
------------- no of whleels

* has-a is a relationship betn class and attributes

behaviours <--- methods


--------------- speed
--------------- avg

* always keep set and get methods inside the class to


access the class members( attributes )

Array Example :
int[] ar = new int[3]; // it constructs the array with def val as 0
ar[0] = 10;

Table[] tar = new Table[3]; // it constructs the array of type table with def
val null
tar[0] = new Table();

***Access Modifier :
1. public
2. private -------------( Class level access ONLY )
3. protected
4. default ( there is no keyword as default, so if the modifier is not
applied means it is in default access )

Non-Access Modifier :
1. Abstract ( only method and class can be marked abstract )
2. Final ( methods, calss and attributes can be marked final )
final method ==> can not override
final variable ==> can be changed once init
final class ===> can not be inherited( extend )
3. static

Casting :
1. Implicit
2. Explicit

byte (8) ranges =---- ?????


short (16)
int (32)
long (64)
float (32)
double (64)
char (32)

^ byte |
| short | down
Casting( implicit ) auto / loss-less
UP Casting | char<--->int ---->float |
(Explicit) | long ----> double |
Lossy

Ex : byte b = (int) 131;


131 bin (8 bit) = 1000 0011
131 bin (32 bit) = 0000 0000 0000 0000 0000 0000 1000 0011
Byte (8 bit) = // only Higher order bits get removed ...
= 1000 0011 ( Higher order bit represents -ve sign (sign
bit))
= 1 <-- sign bit 000 0011 <--- number
= 1000 0011 => 0111 1101 --- > -125

*Inheritance :
1. is-a relationship.
2. Car is-a Vehicle.

A <----- Single level ( Becoz One class has only one Parent )
^
|
|
X Y Z B <----- Single level
|
|
C
|
|
D <---- allowed

A B
| |
| |
C C <---- NOT allowed (Multi-level relationship)

X
|
|
Y
|
|
Z

Costructor :

1. if you are able to write the const---or, then java will not provide any
Cont--or.
2. In every const---or JAVA will insert a call to super Const---or.
3. super() -----> Call to super class Const---or
4. To insert the appropriate call to spuer() Const--or is in programmers
hand.. Otherwise compiler will insert a call to super as call to default super
constructor [ex : super();]

5. this ===> current class instance


6. super ===> Super class instance
7. super() ====> super class Constructor
8. this() ====> current class Constructor..

* Ubuntu Software update and install JDK


1. sudo apt-get update (Sudo --> Super User Do -->> also may ask you the root
passwd if u r not a root)
2. sudo apt-get install default-jdk
For Test : Check Version ($javac -version) and ($java -version)
3. sudo apt-get install g++ ( <--- for c++ compiler )

==============***===================

*Final Class
1. final class can never be extended. (<====== ***)
2. final variable can not change its value.
3. you can never override the final method.

*Abstract Class :
1. Abstract class must be subclassed.
2. You can never create the instance of a abstract class.
3. Abstract class may or may not contain the abstract methods.
4. Abstract class may also contain its own concrete(Non-abstract) methods.

NOTE : 1. You can never mark a class as abstract and final both
2. You can never mark a method as abstract and private both

***Variable
a. local --> ( inside the method )
b. instance ---> ( inside the class but outside the method ) ... Attr
c. static ---> ( it is a class specific functionality )

***Static : Method or instance variables(Attr)


Note : static : class-spec.. ( can be accessed with Class Name)
Non - Static : instance method or attr

1. Statics get loaded when the class get loaded by JVM.


2. Static get init..ed simillar to normal instance variables with default
values.
3. you can-not access the non-static member in the static context.

***Interface :
1. interface is 100% abstract super class
2. so, interface will contain only abstract methods.
3. interface methods are always public abstract.
4. variables in interface are always static and final. (they are constants)

Вам также может понравиться