Posts

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,"...

file handling.

  package F ile_ H andling ; import java . io .* ; public class CreateFile { // public static void main(String[] args) { // File f= new File("C:\\Users\\vedva\\OneDrive\\Desktop\\ved.txt"); // try{ // if(f.createNewFile()){ //     System.out.println("file successfully created"); // }else{ //     System.out.println("file already exixts.."); // } // }catch(IOException e){ //     System.out.println("ioexception handled.."); // } //} public static void main ( String [] args ) throws IOException { File f = new File ( "C: \\ Users \\ vedva \\ OneDrive \\ Desktop \\ ved.txt" ); if ( f . createNewFile ()){   System . out . println ( "file successfully created" ); } else {     System . out . println ( "file already exixts.." ); } } } package F ile_ H andling ; import java . io .* ; public class FileInfo { public static void main ( String [] args ) { File f = new File ( "C: \\ Users \\ vedva \\ One...