This:
This key work used to distinguise between local variables and global variables when both names r same...
public class SecondTest {
public String BankName;
public int Acct;
//create constructor
public SecondTest(String BankName,int Acct) {
this.BankName=BankName;
this.Acct=Acct;
Arrays:
String str[]= new String[5];
str[0]="meeraja ";
str[1]="is ";
str[2]="a software ";
System.out.println(str[1]);
for(int x=0;x<str.length;x++)
System.out.print(str[x]);
System.out.println();
print in reverse:
for(int y=str.length-1;y>=0;y--)
System.out.print(str[y]);
Interface:
//interface delcare method but wont implement
//the variables declared inside interface not changeble
//no static functions inside
//mandatory to initialise variables
//variables in interface are default Static..
public interface Bank {
int amount = 200;
public void transfermoney();
public void debit();
//interface can not be instantited..
//public Bank = new Bank // not possible
//advantage of interface:
//have to use implements for sub class which implement the interface
Object Array:
//object array stores d/f type of data types
Object obj[]=new Object[4];
obj[0]="meeraja";
obj[1]=94582;
obj[2]=67.9;
obj[3]=true;
Object Reference:
public class ObjReference {
//if one of reference pointing to obj changes all the other obj pointing to ref will also chnge)
a.price=2000; b.price=3000; c.price=4000;
a=b;// a is not pointint to a now pointing to where b is pointing i.e 3000
b=c; // b is pointing to where c is pointing i.e. 4000
c=a;// c is pointing to where a is poinitng which is 3000 in memory
System.out.println(a.price); //3000
System.out.println(b.price); //4000
System.out.println(c.price); //3000
if we change a.price=8000;
System.out.println(a.price); //8000
System.out.println(b.price); //4000
System.out.println(c.price); //8000
Overloading:
//same name with d/f paramters
// constructors with same name & d/f parameters
//constructor helps u initialise objects
//this is keyword in java refer to current
//when global variable name and local variable name same, then use this.var name to diffretaite between
car c1= new car();
car c2= new car(a,b);
//When both super and sub class has the same method signature- over riding
//when both super and sub class has same method name but differernt parameters in like
// car(), and car (a,b) - overloading
//global variable name and local variable has same name, to refer the method or variable in parent class use 'This'..
//when variable is defined private use accessor methods like get and set and aceess in sub clss
Static & Non Static:
public class StaticNonstatic {
int x;//global- used across all
String name;
//static global-static functions only can acess static variables
static int phone;
public static void main(String[]args){
sum(4,5);
// cal(5);//can't call non static
phone = 510-777-7765;
//x = 455;
//name="meeraja"
// cant acess non static in static methods
Utility function:
generate a random number in 30's
// System.out.println(Math.random());
generateRandom(35);
// double d=Math.random()*10;
//double e=Math.random()*100;
// System.out.println("Random number is " +d);
// System.out.println("Random number is " +e);
}
public static void generateRandom(int v){
double e=Math.random()*v;
System.out.println(e);
SWAP:
swap s = new swap();
s.x=1;
s.y=2;
//swap.swapp(s.x,s.y);
System.out.println( +s.x +"----"+s.y);
swapp(s);
System.out.println(s.x +"----"+ s.y);
}
public static void swapp(swap s)
{
int temp=s.x;
s.x=s.y;
s.y=temp;
String concat:
String str1= "meeraja";
String str2= "anasuri";
int a1=100;
int a2 =200;
System.out.println(str1+str2); //meerajaanasuri
System.out.println(a1+a2);//300
System.out.println(str1+str2+a1+a2); //meerajaanasuri100200
System.out.println(a1+a2+str1+str2);//meerajaanasuri300
WHILE:
while (i<10)
{
System.out.println(i);
i= i+1;
}