Posts

Showing posts from August, 2019

JAVA CLASSES

CLASSES — An object is an instance of a class. — A class is a template or blueprint from which objects are created. — An object is  a real-world entity . — An object is  a runtime entity . — The object is  an entity which has state and behavior . — The object is  an instance of a class . CLASS DECLARATION Syntax to declare a class: class  < class_name > {       field;       method;   }   INSTANCE VARIABLE IN JAVA — A variable which is created inside the class but outside the method is known as an instance variable. — Instance variable doesn't get memory at compile time. — It gets memory at runtime — when an object or instance is created. — That is why it is known as an instance variable. NEW OPERATOR — The new keyword is used to allocate memory at runtime. — All objects get memory in Heap memory area. OBJECT CREATI...

JAVA LOOPS

FOR LOOP   — When you know exactly how many times you want to loop through a block of code. — Syntax — for ( statement 1 ;  statement 2 ;  statement 3 )     {    // code block to be execute } —   EXAMPLE FOR LOOP Public class test { Public ctatic void main(string args []) {   for ( int   i = 0; i < 5; i ++)     {    System.out.println ( i ); } } } Output 0 1 2 3 4 WHILE LOOP — Loops can execute a block of code as long as a specified condition is reached. Syntax — while ( condition )     {   // code block to be executed } — WHILE EXAMPLE Public class test {   public static void main(String args [])   {   int i =0;   while( i ==5)   {   System.out.println (“ hai ”);   i ++;   }   } } DO WHILE — This loop ...

JAVA FLOW CONTROLS

Image
FLOW CONTROL AND CLASSES EXAMPLE IF   public class MyClass  {   public static void main(String[] args ) {     if (20 > 18) {       System.out.println ("20 is greater than 18"); // obviously    }    } } OUTPUT 20 is greater than 18 IF ELSE — Use the else statement to specify a block of code to be executed if the condition is false. Syntax — if ( condition )  {    // block of code to be executed if the condition is true }  else  {    // block of code to be executed if the condition is false }  IF ELSE IF EXAMPLE public class  gasc2 {   public static void main(String args [])   {   int a=10;   if(a==10)   {   System.out.println (" gobi ");   }   else if(a<10)   {   System.out...