Tuesday, January 12, 2016

WATER-MARK ENCRYPTION AND DECRYPTION IN JAVA



WATER-MARK ENCRYPTION AND DECRYPTION IN JAVA


Crypter.JAVA

import java.awt.Color;

public class Crypter {

    private Picture copy;
    private Picture key;
    private int bytes;
    private int countc; //count chars at text, when crypting

    public Crypter(String key) {
        this.key = new Picture(key);
        copy = new Picture(key);
        bytes = this.key.width() * this.key.height() - 2;

    }

   
    public String deCrypt(String file) {
        if (file.length() < 1) {
            return null;
        }
        copy = new Picture(file);
        int allowed = deCalcAllowed(1, 1);
        int count = 0;
        String text = "";

        for (int i = 0; i < key.width(); i++) {
            for (int j = 0; j < key.height(); j++) {
                if (!(i == 1 && j == 1)) {
                    count++;
                    if (count == allowed) {
                        text += deCryptChar(i, j);
                        count = 0;
                    }
                }
            }
        }

        return text;
    }


    public boolean encrypt(String text, String file) {
        copy = new Picture(key.toString());
        countc = 0;
        int count = 0;

        if (text.length() == 0) {
            return false; // Nothing to encrypt
        }
        if (text.length() > bytes) {
            return false; // The string is too long
        }
        int allowed = (int) Math.floor(bytes / text.length()); // bytes between characters. includes char.              
        allowed(allowed, 1, 1);

        //int badData = (int)Math.floor(bytes/allowed)-text.length();
        try {
            for (int i = 0; i < key.width(); i++) {
                for (int j = 0; j < key.height(); j++) {
                    if (!(i == 1 && j == 1)) {
                        count++;
                        if (count == allowed) {
                            cryptChar(i, j, next(text));
                            count = 0;
                        } else {
                            cryptChar(i, j, 0);
                        }
                    }
                }
            }

            copy.save(file);
        } catch (Exception e) {
            System.out.println("I'm sorry, something went wrong, probably invalid character, try using characters present in 8-bit ASCII");
            return false;
        }

        return true;
    }

    private char deCryptChar(int x, int y) {
        Color d = difference(x, y);
        int a = d.getRed() + d.getGreen() + d.getBlue();
        return (char) a;
    }

    private void cryptChar(int x, int y, int a) {
        Color pix = key.get(x, y);
        int blue = pix.getBlue();
        int red = pix.getRed();
        int green = pix.getGreen();

        if (a == 0) {
            int intensity = 30; // close to 40 is most secure
            int r = (int) (Math.random() * intensity);
            if (blue >= 128) {
                blue -= r;
            } else {
                blue += r;
            }
            r = (int) (Math.random() * intensity);
            if (green >= 128) {
                green -= r;
            } else {
                green += r;
            }
            r = (int) (Math.random() * intensity);
            if (red >= 128) {
                red -= r;
            } else {
                red += r;
            }
        } else {
            Coord c = split3(a);
            int r = c.x;
            if (blue >= 128) {
                blue -= r;
            } else {
                blue += r;
            }
            r = c.y;
            if (green >= 128) {
                green -= r;
            } else {
                green += r;
            }
            r = c.z;
            if (red >= 128) {
                red -= r;
            } else {
                red += r;
            }
        }
        pix = new Color(red, green, blue);
        copy.set(x, y, pix);

    }

    private int next(String text) {
        char a = 0;
        if (text.length() > countc) {
            a = text.charAt(countc);
            countc++;
        }
        return a;
    }

    private void allowed(int allowed, int x, int y) {
        Color pix = key.get(x, y);
        int blue = pix.getBlue();
        int red = pix.getRed();
        int green = pix.getGreen();

        int count = 0;
        while (allowed > 127) {
            count++;
            allowed -= 127;
        }
        if (count > 0) {
            Coord e = split2(count);
            if (red < 128) {
                red += e.x;
            } else {
                red -= e.x;
            }
            if (green < 128) {
                green += e.y;
            } else {
                green -= e.y;
            }
        }
        if (allowed <= 127) {
            if (blue < 128) {
                blue += allowed;
            } else if (blue >= 128) {
                blue -= allowed;
            }

        }

        pix = new Color(red, green, blue);
        copy.set(x, y, pix);

    }

    private int deCalcAllowed(int x, int y) {
        Color d = difference(x, y);
        return (d.getRed() * 127 + d.getGreen() * 127) + d.getBlue();
    }

    private Color difference(int x, int y) {
        Color pix = key.get(x, y);
        int blue = pix.getBlue();
        int red = pix.getRed();
        int green = pix.getGreen();
        Color c = copy.get(x, y);
        int Cblue = c.getBlue();
        int Cred = c.getRed();
        int Cgreen = c.getGreen();
        return new Color(Math.abs(red - Cred), Math.abs(green - Cgreen), Math.abs(blue - Cblue));
    }

    private Coord split2(int a) {
        int r = (int) (Math.random() * a);
        a -= r;
        Coord c = new Coord(a, r);
        return c;
    }

    private Coord split3(int a) {
        int z = 0;
        int r = (int) (Math.random() * a);
        a -= r;
        if (a > r) {
            z = (int) (Math.random() * a);
            a -= z;
        } else {
            z = (int) (Math.random() * r);
            r -= z;
        }

        Coord c = new Coord(a, r, z);
        return c;
    }

}

class Coord {

    public int x;
    public int y;
    public int z;

    public Coord(int x, int y) {
        this.x = x;
        this.y = y;
    }

    public Coord(int x, int y, int z) {
        this.x = x;
        this.y = y;
        this.z = z;
    }

}

-------------------------------------------------------------------------------------------------------------------------

public class Test 
{

    public static void main(String[] args) {
        Crypter c = new Crypter("key.PNG"); // Key picture.

        //Crypt
         c.encrypt("JAVA stegnography tech..", "secret.PNG");
        //Decrypt
        System.out.println(c.deCrypt("Secret.PNG"));

    }
}

--------------------------------------------------------------------------------------------------------------------------

                   ORIGINAL IMAGE WITHOUT ANY ENCRYPTION:








SECRET IMAGE WITH ENCRYPTION WORD "JAVA stegnography tech."







Monday, January 11, 2016

AUTO READER FROM TEXT FILE:



AUTO READER FROM TEXT FILE:

import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.RandomAccessFile;
import java.util.Timer;
import java.util.TimerTask;

public class ConsoleReader {


    public static void main(String[] args) {
        File file = new File("D:\\template_link.txt");
        try {
            RandomAccessFile r = new RandomAccessFile(file, "r");
            //First time read
            String str = null;
            while ((str = r.readLine()) != null) {
                System.out.println(str);
            }
            r.seek(r.getFilePointer());
            startTimer(r);
        } catch (FileNotFoundException e) {
        } catch (IOException e) {
        }
    }

    private static void startTimer(final RandomAccessFile r) {
        Timer timer = new Timer();
        timer.scheduleAtFixedRate(new TimerTask() {
            @Override
            public void run() {
                String str = null;
                try {
                    while ((str = r.readLine()) != null) {
                        System.out.println(str);
                    }
                    r.seek(r.getFilePointer());
                } catch (IOException e) {
                }
            }
        }, 0, 1000);
    }
}

Sunday, January 10, 2016

AUTOMATIC NAVIGATION FROM ONE ACTIVITY TO ANOTHER ACTIVITY IN ANDROID


AUTOMATIC NAVIGATION FROM ONE ACTIVITY TO ANOTHER ACTIVITY WITH NEEDED DELAY IN SECONDS (ANDROID)..



USE THIS CODE IN ONCREATE METHOD:


int secondsDelayed = 1;
            new Handler().postDelayed(new Runnable() {
                    public void run() {
                            startActivity(new Intent(Splash.this, ActivityB.class));
                            finish();
                    }
            }, secondsDelayed * 1000);

RETRIEVING LIST OF FILES NAME WITH EXTENSION IN SPECIFIED FOLDER:


RETRIEVING LIST OF FILES NAME WITH EXTENSION IN SPECIFIED FOLDER:



import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
public class FileHandler 
{
    public static void main(String[] args) throws IOException
    {
        List<String> files=new ArrayList<>();
        String folderPath="D:\\DOWNLOADS\\";

File folder = new File(folderPath);

if (folder.isDirectory()) {
File[] listOfFiles = folder.listFiles();
if (listOfFiles.length < 1)
System.out.println("There is no File inside Folder");
else
System.out.println("List of Files & Folder");
 for (File file : listOfFiles) {
                               if(!file.isDirectory())
                               {
                     files.add(file.getCanonicalPath().toString());
                               }
                              
                             
}
 System.out.println(files);
 filesearch(files);
}
else
System.out.println("There is no Folder @ given path :" + folderPath);
byte[] data = new byte[20];
                System.in.read(data);
}
    public static void filesearch(List<String> files)
    {
        for(int i=0;i<files.size();i++)
        {
            System.out.println("FILE NAME..:"+files.get(i));
        File file =new File(files.get(i));
    Scanner in = null;
        try {
            in = new Scanner(file);
            while(in.hasNext())
            {
                String line=in.nextLine().trim();
               if(line.contains("hello"))
                    System.out.println(line);
            }
        }
catch (FileNotFoundException e) {
            e.printStackTrace();
        }
        }

       
    }
   
   

}
OUTPUT:

D:DOWNLODS/


List of Files & Folder
[D:\DOWNLOADS\09c-DataStructuresListsArrays.ppt, D:\DOWNLOADS\BLUETOOTH CODING.docx, D:\DOWNLOADS\Chrysanthemum.jpg, D:\DOWNLOADS\client_server_krm_01may2002.ppt, D:\DOWNLOADS\data.pdf, D:\DOWNLOADS\DataBase.docx, D:\DOWNLOADS\Dclient_server_krm_01may2002.ppt, D:\DOWNLOADS\des.docx, D:\DOWNLOADS\Desert.jpg, D:\DOWNLOADS\Granizo.pdf, D:\DOWNLOADS\style.css, D:\DOWNLOADS\Thumbs.db, D:\DOWNLOADS\~$taBase.docx]
FILE NAME..:D:\DOWNLOADS\09c-DataStructuresListsArrays.ppt
FILE NAME..:D:\DOWNLOADS\BLUETOOTH CODING.docx
FILE NAME..:D:\DOWNLOADS\Chrysanthemum.jpg
FILE NAME..:D:\DOWNLOADS\client_server_krm_01may2002.ppt
FILE NAME..:D:\DOWNLOADS\data.pdf
FILE NAME..:D:\DOWNLOADS\DataBase.docx
FILE NAME..:D:\DOWNLOADS\Dclient_server_krm_01may2002.ppt
FILE NAME..:D:\DOWNLOADS\des.docx
FILE NAME..:D:\DOWNLOADS\Desert.jpg
FILE NAME..:D:\DOWNLOADS\Granizo.pdf
FILE NAME..:D:\DOWNLOADS\style.css
FILE NAME..:D:\DOWNLOADS\Thumbs.db
FILE NAME..:D:\DOWNLOADS\~$taBase.docx


Thursday, January 7, 2016

SIMPLE TABLE CREATION WITH FORMATTING FIELDS IN JAVA USING ITEXT PDF

SIMPLE TABLE CREATION IN JAVA USING ITEXT PDF

public void PdfGen() throws DocumentException, FileNotFoundException, ClassNotFoundException, SQLException {

        Document document = new Document();
        PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream("D:\\HelloWorld1.pdf"));
        document.open();
        Paragraph paragraph = new Paragraph();
        Chunk tab = new Chunk(new VerticalPositionMark(), 50f, false);
        // paragraph.setTabSettings(new TabSettings(tabList));
        Chunk CONNECT = new Chunk(
                new LineSeparator(0.5f, 95, BaseColor.BLUE, Element.ALIGN_CENTER, 3.5f));
        LineSeparator UNDERLINE
                = new LineSeparator(1, 100, null, Element.ALIGN_CENTER, -2);
        Chunk tab1 = new Chunk(new VerticalPositionMark(), 200, true);
        Chunk tab2 = new Chunk(new VerticalPositionMark(), 350, true);
        Chunk tab6 = new Chunk(new VerticalPositionMark(), 50f, false);
        Chunk tab3 = new Chunk(new DottedLineSeparator(), 450, true);
        Date d=new Date();
        document.add(new Paragraph("STATUS REPORT GENERATION.."+d.toString()));
         document.add(new Paragraph(new Chunk(tab1)));
        PdfPTable table = new PdfPTable(8); // 6 columns.
        table.setWidthPercentage(100);
        table.setWidths(new int[]{ 1, 2, 2, 2, 2,2,2,2});
       // List<String> cols=new ArrayList<String>();
       
        List<String> cols = new ArrayList<>(Arrays.asList("ID","TITHI","PHASE","STAR","DATE","DAY","TIME","STATUS"));
        for(int i=0;i<cols.size();i++)
        {
            
        PdfPCell colum = new PdfPCell(new Paragraph(cols.get(i)));
        colum.setHorizontalAlignment(Element.ALIGN_CENTER);
        table.addCell(colum);
       
       
        }
       Statement stm=new DataBase_Connection().ConnectionGet().createStatement();
        ResultSet rs=stm.executeQuery("select * from  status");
           //for(int i=0;i<cols.size()-1;i++)
          
        while(rs.next())
        {
              for(int i=1;i<=8;i++)
              {
              table.addCell(rs.getString(i));
              table.setSpacingBefore(10f);
              }
           
           
        }
       
        document.add(table);
       
        document.close();
        writer.close();
        JOptionPane.showMessageDialog(rootPane, "DATA IS PRINTED..");
       
       
       


    }
--------------------------------------------------------------------------------------------------------------------------

PDF TABLE WITH FORMATING FIELDS


import java.io.FileOutputStream;
import java.text.DecimalFormat;

import com.itextpdf.text.BaseColor;
import com.itextpdf.text.Document;
import com.itextpdf.text.DocumentException;
import com.itextpdf.text.Element;
import com.itextpdf.text.Font;
import com.itextpdf.text.Font.FontFamily;
import com.itextpdf.text.PageSize;
import com.itextpdf.text.Paragraph;
import com.itextpdf.text.Phrase;
import com.itextpdf.text.pdf.PdfPCell;
import com.itextpdf.text.pdf.PdfPTable;
import com.itextpdf.text.pdf.PdfWriter;

public class PrintReport {

 public static void main(String[] args) {

  String pdfFilename = "";
  PrintReport printReport = new PrintReport();
  if (args.length < 1)
  {
   System.err.println("Usage: java "+ printReport.getClass().getName()+
   " PDF_Filename");
   System.exit(1);
  }

  pdfFilename = args[0].trim();
  printReport.createPDF(pdfFilename);

 }

 private void createPDF (String pdfFilename){

  Document doc = new Document();
  PdfWriter docWriter = null;

  DecimalFormat df = new DecimalFormat("0.00");

  try {
  
   //special font sizes
   Font bfBold12 = new Font(FontFamily.TIMES_ROMAN, 12, Font.BOLD, new BaseColor(0, 0, 0));
   Font bf12 = new Font(FontFamily.TIMES_ROMAN, 12);

   //file path
   String path = "docs/" + pdfFilename;
   docWriter = PdfWriter.getInstance(doc , new FileOutputStream(path));
  
   //document header attributes
   doc.addAuthor("betterThanZero");
   doc.addCreationDate();
   doc.addProducer();
   doc.addCreator("MySampleCode.com");
   doc.addTitle("Report with Column Headings");
   doc.setPageSize(PageSize.LETTER);
 
   //open document
   doc.open();

   //create a paragraph
   Paragraph paragraph = new Paragraph("itext ");
  
  
   //specify column widths
   float[] columnWidths = {1.5f, 2f, 5f, 2f};
   //create PDF table with the given widths
   PdfPTable table = new PdfPTable(columnWidths);
   // set table width a percentage of the page width
   table.setWidthPercentage(90f);

   //insert column headings
   insertCell(table, "Order No", Element.ALIGN_RIGHT, 1, bfBold12);
   insertCell(table, "Account No", Element.ALIGN_LEFT, 1, bfBold12);
   insertCell(table, "Account Name", Element.ALIGN_LEFT, 1, bfBold12);
   insertCell(table, "Order Total", Element.ALIGN_RIGHT, 1, bfBold12);
   table.setHeaderRows(1);

   //insert an empty row
   insertCell(table, "", Element.ALIGN_LEFT, 4, bfBold12);
   //create section heading by cell merging
   insertCell(table, "New York Orders ...", Element.ALIGN_LEFT, 4, bfBold12);
   double orderTotal, total = 0;
  
   //just some random data to fill
   for(int x=1; x<5; x++){
   
    insertCell(table, "10010" + x, Element.ALIGN_RIGHT, 1, bf12);
    insertCell(table, "ABC00" + x, Element.ALIGN_LEFT, 1, bf12);
    insertCell(table, "This is Customer Number ABC00" + x, Element.ALIGN_LEFT, 1, bf12);
   
    orderTotal = Double.valueOf(df.format(Math.random() * 1000));
    total = total + orderTotal;
    insertCell(table, df.format(orderTotal), Element.ALIGN_RIGHT, 1, bf12);
   
   }
   //merge the cells to create a footer for that section
   insertCell(table, "New York Total...", Element.ALIGN_RIGHT, 3, bfBold12);
   insertCell(table, df.format(total), Element.ALIGN_RIGHT, 1, bfBold12);
  
   //repeat the same as above to display another location
   insertCell(table, "", Element.ALIGN_LEFT, 4, bfBold12);
   insertCell(table, "California Orders ...", Element.ALIGN_LEFT, 4, bfBold12);
   orderTotal = 0;
  
   for(int x=1; x<7; x++){
   
    insertCell(table, "20020" + x, Element.ALIGN_RIGHT, 1, bf12);
    insertCell(table, "XYZ00" + x, Element.ALIGN_LEFT, 1, bf12);
    insertCell(table, "This is Customer Number XYZ00" + x, Element.ALIGN_LEFT, 1, bf12);
   
    orderTotal = Double.valueOf(df.format(Math.random() * 1000));
    total = total + orderTotal;
    insertCell(table, df.format(orderTotal), Element.ALIGN_RIGHT, 1, bf12);
   
   }
   insertCell(table, "California Total...", Element.ALIGN_RIGHT, 3, bfBold12);
   insertCell(table, df.format(total), Element.ALIGN_RIGHT, 1, bfBold12);
  
   //add the PDF table to the paragraph
   paragraph.add(table);
   // add the paragraph to the document
   doc.add(paragraph);

  }
  catch (DocumentException dex)
  {
   dex.printStackTrace();
  }
  catch (Exception ex)
  {
   ex.printStackTrace();
  }
  finally
  {
   if (doc != null){
    //close the document
    doc.close();
   }
   if (docWriter != null){
    //close the writer
    docWriter.close();
   }
  }
 }

 private void insertCell(PdfPTable table, String text, int align, int colspan, Font font){
 
  //create a new cell with the specified Text and Font
  PdfPCell cell = new PdfPCell(new Phrase(text.trim(), font));
  //set the cell alignment
  cell.setHorizontalAlignment(align);
  //set the cell column span in case you want to merge two or more cells
  cell.setColspan(colspan);
  //in case there is no text and you wan to create an empty row
  if(text.trim().equalsIgnoreCase("")){
   cell.setMinimumHeight(10f);
  }
  //add the call to the table
  table.addCell(cell);
  
 
 }

}

Tuesday, January 5, 2016

ANONYMOUS INNER CLASS


ANONYMOUS INNER CLASS AND INTERFACE


Anonymous classes in java are defined in a different way than that of a normal java classes. In java anonymous classes can be created in either of the two ways.

1) Using a class reference variable.
2) Using an interface.

Sample code:
public class Anonmyoussec
{
public  void Anonmy1()
{
System.out.println("ANONMYOUS CLASS MAIN");
}

}
class Anonmyoussec1
{
static Anonmyoussec anon=new Anonmyoussec()
{
public void Anonmy1()
{
System.out.println("ANONMYOUS CLASS SUB MAIN");
}
};
public static void main(String args[])
{
anon.Anonmy1();
}
}


ANONMYOUS CLASS INTERFACE:


interface Anonmy1
{
public void sum();
}
public class InnerClass
{
static Anonmy1 a1=new Anonmy1() {

@Override
public void sum() {
System.out.println("DATA SUM");
}
};
public static void main(String[] args)
{
a1.sum();
}


}

SYNCHRONIZATION IN THREAD (java)

SYNCHRONIZATION IN JAVA THREAD

Java programming language provides a very handy way of creating threads and synchronizing their task by using synchronized blocks. You keep shared resources within this block. Following is the general form of the synchronized statement:

synchronized(objectidentifier) 
{
// Access shared variables and other shared resources
}

SAMPLE CODE:

public class Sync
{
static Runnable br,br1;
public static void main(String[] args)
{
br=()->{
data();
};
br1=()->{
data();
};
Thread t1=new Thread(br);
t1.start();
Thread t2=new Thread(br1);
t2.start();

}
public synchronized static void data()
{
for(int i=0;i<10;i++)
{
try {
Thread.sleep(100);
} catch (InterruptedException ex) {
Logger.getLogger(Sync.class.getName()).log(Level.SEVERE, null, ex);
}
System.out.println(i);
}
}

}

INNER CLASS ABSTRACTION IN JAVA

INNER CLASS ABSTRACTION  IN JAVA

INNER CLASS METHOD CREATION:


public class InnerClas
{
static private int i=1;
static class Innner
{
public void getval()
{
System.out.println("value of i.."+i);
}
}
public static void main(String args[])
{
Innner i1=new Innner();
i1.getval();
}
}

Sample code: From Outer class calling Inner class method


public class Outerclass
{
private int i=8;
public void createInner()
{
Innerclass i1=new Innerclass();
i1.getvalue();
}
class Innerclass
{
public void getvalue()
{
System.out.println("value of i.."+i);
}
}

}
class Invoke
{
public static void main(String args[])
{
Outerclass outerobj=new Outerclass();
Outerclass.Innerclass innerobj= outerobj.new Innerclass();
innerobj.getvalue();
}

}

Monday, January 4, 2016

WAYS OF CREATING THREAD IN JAVA


THREAD CREATION IN JAVA


Java is a multi threaded programming language which means we can develop multi threaded program using Java. A multi threaded program contains two or more parts that can run concurrently and each part can handle different task at the same time making optimal use of the available resources specially when your computer has multiple CPUs.By definition multitasking is when multiple processes share common processing resources such as a CPU. Multi threading extends the idea of multitasking into applications where you can subdivide specific operations within a single application into individual threads. Each of the threads can run in parallel. The OS divides processing time not only among different applications, but also among each thread within an application.Multi threading enables you to write in a way where multiple activities can proceed concurrently in the same program.

TYPES OF CREATING THREAD:-


1.      IMPLEMENTING RUNNABLE INTERFACE
2.      EXTENDING THREAD CLASS
3.      ANONMYOUS THREAD CLASS
4.      ANONMYOUS RUNNABLE INTERFACE THREAD
5.      LAMBDA ANONMYOUS RUNNABLE THREAD


TYPE 1-CREATING THREAD USING IMPLEMENTING RUNNABLE INTERFACE


public  class Runnablethre implements Runnable
{
static Thread ti;

Runnablethre()
{
System.out.println("Strating thread..");
}

@Override
public void run()
{
System.out.println("running thread..");
try {
Thread.sleep(100);
System.out.println("NAME OF THE THREAD.."+ti.getName());
System.out.println("PRIORITY OF THE THREAD.."+ti.getPriority());
} catch (InterruptedException ex) {
Logger.getLogger(Runnablethre.class.getName()).log(Level.SEVERE, null, ex);
}
System.out.println("thread Excited..");
}

public static void main(String args[])
{
Runnablethre re=new Runnablethre();
System.out.println("Creating thread..");
ti=new Thread(re);
ti.start();

} }

TYPE 2-  CREATING THREAD BY EXTENDING THREAD CLASS

public class ExtendThread extends Thread
{
public void run()
{
System.out.println("running thread");
}

public static void main(String args[])
{
Thread t1=new Thread(new ExtendThread());
t1.start();
}

}

TYPE 3-ANONMYOUS THREAD

public class AnonmyThread
{
public static void main(String args[])
{
Thread t1=new Thread()
{
public void run()
{
System.out.println("THREAD CREATED..");
}
};
t1.start();
}

}

TYPE 4- ANONMYOUS RUNNABLE INTERFACE THREAD

public class AnonmyRunn
{
public static void main(String args[])
{
Runnable r1=new Runnable()
{
@Override
public void run() {
System.out.println("THREAD CREATED..");
}

};
Thread t1=new Thread(r1);
t1.start()
}
}

TYPE 5- LAMBDA ANONMYOUS RUNNABLE THREAD

public class lAMBDAthread
{
public static void main(String args[])
{
Runnable task2 = () -> {
System.out.println("Task #2 is running");
};
new Thread(task2).start();
}

}

USER DEFINED EXCEPTION IN JAVA

USER DEFINED EXCEPTION:


import java.io.IOException;
import java.util.Scanner;
public class UserDefExcep
{
public static void main(String args[])
{
try
{
System.out.println("ENTER VALUE..");
Scanner in= new Scanner(System.in);
int a=in.nextInt();
if(a>5)
throw new Exception("value should be greather than 5");
}
catch(Exception ex)
{
System.out.println(ex.getMessage());
}
}


}