Pages

Saturday, April 18, 2009

public static void

public - access the method from outside of the class
static - help access the method with out creating object( obj A of classname , a.main?

void - no return value

jvm access main as entry point from out side

System.out.println
System is a class, println is a method of printstream, printstream is class in java.io package ,
out is a static member data of type java.io.printstream present in system class

datatypes

premitive(fundamenal and abstract dt

premitive -- numberic, character,boolean

numeric - integer, real/floating pt
integer - byte, short, int, long   1,2,4,8 bytes

flaoting pt - float, double,  4,8   - float f=12.34 is wrong, number with decimal is double, this can not be assigned to flaot(only 4 bites)

Character- char 2 bytes

float f=12.34F or float f=(float)12.34(explicit type casting) is correct
1 byte = 8 bit  
Range of values that can be stored in integer variable ->  -2 to power(n-1) to +2 power(n-1)  -2 power 7--> -128 to 127

wrapper class built in class typ3 represent premitive datatype--> eg byte-->java.Lang.Byte

System.out.println("Min vlue =" +Byte.MIN_VALUE);
System.out.println("byte =" +Byte.BYTES);
System.out.println("its =" +Byte.SIZE);

long l=999999999999999; error with out decimal it is treated as integer, implement type casting
long l=999999999999999L; ok specified as long by suffix L

char c=65 --> letter A, implicit type casting
n=012; is considered as Octal number, since it is starting with 0(number system with 0 to 7 digit), this will kae n=10; 2 x 8 to power 0+2 x 8 to power 1
number starting with 0x is hexadecimal, ob is binary

\u0041 letter A in hexadecimal form

math
System.out.println(10/3) =3, not 3.333 since bith are integer

mod, modulus remainder
System.out.println(10%3); =1
System.out.println(-10%3); =-1
System.out.println(10%-3); =1
System.out.println(-10%-3); =-1
Only the first sign considered

10/0 Java.lang.Arithmeticexception /0
=10.0/0.0=infinity   double

int n=10;
int k=10;
System.out.println(n++); -->10 increments but returns old value
System.out.println(++k);-->11 increments and returns new value


int n=10;

System.out.println(n++); -->10 increments but returns old value
System.out.println(++n);--> 12 increments and returns new value


Conditional
if else simple(if else inside
nested if
ladder if, if else if


swith case break, break is mandatory otherwise next line is executed

char c='A';
switch(c)'

{
case 'A';
 do;
break;
:

default;
}

for loop
while loop -executed only if true

do wile loop - executed once and executed second time only if true

for (x int: marks) --marks is integer array
{
sop(x);
}



Araay
int[] arr; preferred way, int arr[]'; is also correct
arrayindexoutofboundexception
arr.length()
initialization int[] marks=new int[6];

null an nothing is value not keyword

multi dimentional array arr[][]
arra of arrays, length is first arry length
do a sample

jacked arrsys, sub array has different size
int[][]={{1,2,3},{3,4},{5,6,7,8}}

call by value
call by reference

method overloading, methods with different types of arguements, can be same of different return type
Strinh, java.jang.String, Java.Lang.StringBuffer, Java.Lang.StringBuilder
String is not mutable buffer and builder is mutable,--can change value
String s1="Test" String s2="Test"   both will point to same location in String Constant pool

hashcode(), both s1 and s2 will have same hash code; memory location

s1="abc"
s1="cde"   s1 will now point to an new memory location with value "cde", "abc" is not replace by "cde"

int nteger.parstInt(String);
ParstString
parstFloat...

String.length


Use Stringbuffer when lot of modifications are done to the string, other wise lot of memory use
sb.appnd, sb.insert
String s="Abc", s.charat(5), string Index outof biund exception

Stringbuilder and Sbuffer are same but StringBuilder is not synchronized, can run multiple threads,  buffer is slow, buildr is not threadsafe when multipe threads running

procedure oriented pro, object op , aspect op
pop ata and functions are treated seperately, and procedure is more important, complex, huge

oop created to reduce complexity of pop

class is a concept or blue print, a user defined dat typedt abstract data type
object is a real instance of a class


Constructor--method of a class, same name as class,used to initialize data,executed automatically when object of a class is created. no return type

Default constructer is ceated at compile or we can write code

final is used to declare constant;
final int n-10;

final class can not be inherrited, no extends
final method can not override
final variable can not be modified
variable must be initialied if declared as final
outer class can not be declared as static
static variable is initialized and shared by objects
static method is executed before main

abstract class can not be initiated, can be subclassed
incomplete class, can have abstract methods
abstract void Test(args);  -- no immplementation, if a method is abstract class must be abstracts

interface -very useful

used to support multiple inherittance

class can extend only from one class, but can implement from multiple interfaces
interface keyword iis used , all methods are abstracts and public 100%
 abstraction

implements keyword
class a implements B
interface can be extended from more than one interface, multiple inherritance
only method specificayions, no implememntation
variable in interface gets automatically converted to public static final, methods are converted to public abstract

Implementation should contain public access modifier for methods, can not declare weaker access methods

package is a collection of classes, abstracts etc
package is a directory
rt.jar contains all builtin classes  in jre/lib folder

import static java.lang.math, usic static you do nt need t write math.pi, just pi is enough


access modifiers
public, private, protected, defaukt or package
outer class can not be private  

default is private to package