Posts

Showing posts from July, 2017

isoceles unix

read a read b read c if [ $a -eq $b -a $b -eq $c ] then echo "EQUILATERAL" elif [ $a -eq $b -o $b -eq $c -o $c -eq $a ] then echo "ISOSCELES" else echo "SCALENE" fi

finall

dynamic binding

prashanth sriatsva

class AbstractDemo { void display() { System.out.println("display() called from AbstractDemo class"); } void fun() { System.out.println("fun() called from AbstractDemo class"); } } class ConcreteDemo extends AbstractDemo { void bar() { System.out.println("fun() called from ConcreteDemo class"); } @Override void display() { System.out.println("display() called from ConcreteDemo class"); } public static void main(String[] args) { AbstractDemo abstractDemo=new AbstractDemo();   //handle: AbstractDemo, object:AbstractDemo abstractDemo.display(); abstractDemo.fun(); ConcreteDemo concreteDemo=new ConcreteDemo();    //handle: ConcreteDemo, object:ConcreteDemo concreteDemo.display(); concreteDemo.bar(); /*DYNAMIC BINDING EXAMPLE*/ /*USING HANDLE OF PARENT_CLASS TO DEAL WITH OBJECTS OF BOTH (PARENT_CLASS AND CHILD_CLASS) */ abstractDemo=new ConcreteDemo();  //handle: AbstractDemo, obje...

nitin

public class AbstractDemo { void display2() { System.out.println("display() called in Parent class"); } void fun() { System.out.println("fun() called in Parent class"); } } class ConcreteDemo extends AbstractDemo { void bar() { // TODO Auto-generated method stub System.out.println("bar() called in concrete class class"); // super.fun(); } @Override void display2() { // TODO Auto-generated method stub System.out.println("display2() called in concrete class class"); // super.display2(); } public static void main(String[] args) { AbstractDemo abstractdemo = new AbstractDemo(); abstractdemo.display2(); abstractdemo.bar(); } }

overriding is a runtime polymorphism

STATIC

IF WE ARE developing a libraray managment system.. we have to give school name as static class Student { string name; int roll no static school name} so if we create 100 instance(students) ..it is a shared variable...all the insatnaces refers to the class.. static doesnot work inside a function in java..because it is local variable cannot be refernced using a constroctor..is not economicall so we create a static block

constructor

public class Stone { int size; float weight; String colour; // this is called instance variables beacuse property is specific for that instance // this is a class } // what is a constructor //method is same as a function...here stone is a function (method) //constructor doesnot have a return type //constroctor automatically gets invoked and assigns the same value in the callee // here stone is a default constroctor //eg:1stone(){ //abc //} //name of the constroctor must be same a class // constructor with passing parameters // eg2: stone(int size, int w, string colour){ //       this size =size;   //  "no need of this"           weight=w; //}      this colour=colour // if we have multiple methods of same name with different arguments it is called overloading // swapping the sequence also can be done //but if we have two concecutive like.. int int then it doesnt allow overloading class testSton...

array

allocating memory is done using new operator string s[]=new string[3] int[]x =new int[10]  //integer declaration int y[]={4,5,6,7,8} //array declartion public static void main(string s[]){ system.out.println("first  arg is " s[]); ------------------------------------------ system.out.println("first  arg is " s[5]); ---------leads to exception------------ passing parameters java hello a b 1 2 344 we can add strings so we need to convert them to integer Integer present(s[2]);
cntrl shift r to find the resource control shift l to find all the shortcuts contol f6 to open file

eg 1

Hello Program DataTypes (Primitive and Reference/Object) int intVal; float floatVal; double doubleVal; boolean booleanVal; char charVal; String StrVal; Operators Arithmetic (+, -, *, /, ++, --) Relational (==, !=, >, <, >=, <=) Bitwise (&, |, !, ~, ^, <<, >>, >>>) Logical (&&, ||, !) Assigment (=, +=, -=, *=, /=, %=, <<=, >>=, &=, ^=, |=) Conditional Operator ( ? : ) Condtional Statements Loop Types int[] intArray = new int[10]; float[] floatArray = new float[10]; double[] doubleArray = new double[10]; boolean[] booleanArray = new boolean[10]; char[] charArray = new char[10]; String[] StrArray = new String[10]; public class QuotesTest {    public static void main(String args[]) {       System.out.println("She said \"Hello!\" to me.");    } } public class ArithmeticOperatorsTest {   public static void main(String args[]) {   ...

basic

JAVA BUILD CNTL n CL class...will give yo structure cntrol+D delete type the command ..cntl+spacebar cntrl+F11 to run the code window//wshow view//navigator// refactor is used to find and replace eg complement of 40 is -41

bhalaram

class greaterNum {       int a=25,b=75,c=115,greater; void largestUsingLogicalOpeartor(){ if(a>b && a>c){ System.out.println(a); } else if(b > c){ System.out.println(c);} else{ System.out.println(b);} } void largestUsingLoping(){       if( a>b) greater=a;       else greater=b;    if (greater > c) System.out.println("greater number is "+greater);  else { System.out.println("greater number is "+c);       }     } int usingTernary(){ int large=(a > b && a >c )? a:((b>c)? b:c); return (large); }    public static void main(String args[])    {    } }

To reverse the numbers

class ReverseNumber {    public static void main(String args[])    {       int n, reverse = 0;                   n = 123;       while( n != 0 )       {           reverse = reverse * 10;           reverse = reverse + n%10;           n = n/10;       }       System.out.println("Reverse of entered number is "+reverse);    } }

literals

even if we declare a variable long the compiler assigns it a as a integer.. when u give L gives                                                                                                                                                                                                                                                            

commenting in java

Image
class  HELLO{    public static void main(String k[]){         System.out.println("hello \"RAGHAVENDRA\" "); int a=25;    float f= 2.5F ;    long l=1818181816767678L;    }      }

using "\"

Image
class  HELLO{    public static void main(String k[]){         System.out.println("hello \"RAGHAVENDRA\" ");    }      }

public

Image
when the class is public filename should be same as classname if not you will get a error

Running a java program

class raghav{    public static void main(String k[]){         System.out.println("hello....");    }      } for compling use javac filename to run give : java CLASSNAME if you give java filename when you are running error:could not find or load the main class

How to run a program if you have changed the parent directory(program files)

path=%path%;D:\installs\java\filemname\bin change this in dos (this is specially for java)