Posts

Implementation single linked list.

  package L inked L ist ; class Sll {     Node head ;     Node tail ;     int size ;     void length (){         System . out . println ( "length is = " + size );     }     void insertAtStart ( int val ){     Node temp = new Node ( val );     if ( head == null ){         head = tail = temp ;         size ++ ;         return ;     }     temp . next = head ;     head = temp ;     size ++ ;     }     void insertAtEnd ( int val ){     Node temp = new Node ( val );     if ( tail == null ){         head = tail = temp ;         size ++ ;         return ;     }     tail . next = temp ;     tail = temp ;     size ++ ;     } ...

Multi Threading.

create thread method 1- package M ulti_ T hreading ; class A extends Thread {     @ Override     public void run (){     try {     for ( int i = 0 ; i < 5 ; i ++ ){     System . out . println ( "thread" );     Thread . sleep ( 1000 );     }     } catch ( InterruptedException e ){         System . out . println ( e );     }     } } public class createThread1 { public static void main ( String [] args ) throws InterruptedException { A t = new A (); t . start (); for ( int i = 0 ; i < 5 ; i ++ ){ System . out . println ( "main" ); Thread . sleep ( 1000 ); } }   } create thread method 2- package M ulti_ T hreading ; class B implements Runnable { public void run (){ for ( int i = 0 ; i < 5 ; i ++ ){     System . out . println ( "thread ji" ); } } } public class createThread2 { public static void main ( String [] args ) ...

oops.

class and object package program ; class demo { int age = 22 ; String name = "ved varshney" ; void show (){     System . out . println ( "age is : " + age + " name is : " + name ); } } public class code { public static void main ( String [] args ) { demo r = new demo (); r . show (); } }   constructor -  Constructor is a special method which name is same as class name .  The main purpose of constructor is to initialize the objects. every java class has constructor. A constructor is automatically called at the time of object creation. A constructor never contain any return type including void. Types- 1 copy 2 default 3 parameterized 4 private parameterized constructor  -  class demo{ int age; String name; demo(int a , String s){ age=a; name=s; System.out.println("age is : "+age +"\nname is : "+name); } } public class Main{ public static void main(String[] args) { demo r = new demo(22,"...