JPR_S-19

Cards (37)

  • Features of Java
    • Data Abstraction and Encapsulation
    • Inheritance
    • Polymorphism
    • Platform independence
    • Portability
    • Robust
    • Supports multithreading
    • Supports distributed applications
    • Secure
    • Architectural neutral
    • Dynamic
  • finalize() method

    Used to perform specific actions that are to be done when an object is garbage collected
  • finalize() method syntax

    protected void finalize() {}
  • Integer.parseInt()

    Converts string objects to primitive int
  • Integer.toString()
    Converts primitive int to string objects
  • Types of inheritances in Java
    • Single level inheritance
    • Multilevel inheritance
    • Hierarchical inheritance
    • Multiple inheritance
    • Hybrid inheritance
  • try-catch-finally blocks syntax
    1. try{
    2. //Statements to be monitored for any exception
    3. } catch(ThrowableInstance1 obj) {
    4. //Statements to execute if this type of exception occurs
    5. } catch(ThrowableInstance2 obj2) {
    6. //Statements
    7. }finally{
    8. //Statements which should be executed even if any exception happens
    9. }
  • <param> tag syntax
    <param name="name" value="value">
  • Stream class
    An I/O Stream represents an input source or an output destination
  • Types of stream classes

    • Byte stream classes
    • Character stream classes
  • Platform independence and portability in Java
    • Java programs are compiled into bytecode which is platform independent and can be executed on any platform with a Java Virtual Machine (JVM)
    • JVM is a virtual machine which exists inside the computer memory and is a simulated computer within a computer which does all the functions of a computer
  • Constructors in Java

    Used to initialize an object as soon as it is created
  • Types of constructors
    • Default constructor
    • Constructor with no arguments
    • Parameterized constructor
    • Copy constructor
  • Creating threads in Java

    1. By extending the Thread class
    2. By implementing the Runnable interface
  • Stream
    A sequence of data
  • Java stream

    Composed of bytes
  • Input stream class
    • Java application uses an input stream to read data from a source
  • Output stream class
    • Java application uses an output stream to write data to a destination
  • Input stream
    • May read from a file, an array, peripheral device or socket
  • Output stream
    • May be a write to file, an array, peripheral device or socket
  • Input stream classes
    • Reads data as bytes
  • Output stream classes
    • Writes data as bytes
  • Super class of input stream
    Abstract inputStream class
  • Super class of output stream
    Abstract OutputStream class
  • Methods of input stream
    • public int read() throws IOException
    • public int available() throws IOException
    • public void close() throws IOException
  • Methods of output stream
    • public void write(int b) throws IOException
    • public void write(byte[] b) throws IOException
    • public void flush() throws IOException
    • public void close() throws IOException
  • Subclasses of input stream
    • File Input stream
    • Byte Array Input Stream
    • Filter Input Stream
    • Piped Input Stream
    • Object Input Stream
    • DataInputStream
  • Subclasses of output stream
    • File Output Stream
    • Byte Array Output Stream
    • Filter output Stream
    • Piped Output Stream
    • Object Output Stream
    • DataOutputStream
  • Applets
    Event driven
  • Applications
    Control driven
  • Program to copy content of one file to another file
    1. FileInputStream in= new FileInputStream("input.txt")
    2. FileOutputStream out= new FileOutputStream("output.txt")
    3. int c=0
    4. while(c!=-1)
    5. c=in.read()
    6. out.write(c)
    7. System.out.println("File copied to output.txt....")
    8. if(in!=null) in.close()
    9. if(out!=null) out.close()
  • Methods of vector class
    • boolean add(Object obj)
    • Boolean add(int index,Object obj)
    • void addElement(Object obj)
    • int capacity()
    • void clear()
    • Object clone()
    • boolean contains(Object elem)
    • void copyInto(Object[] anArray)
    • Object firstElement()
    • Object elementAt(int index)
    • int indexOf(Object elem)
    • Object lastElement()
    • Object insertElementAt(Object obj,int index)
    • Object remove(int index)
    • void removeAllElements()
  • Dynamic method dispatch
    Mechanism by which a call to an overridden method is resolved at run time, rather than compile time
  • Program to create two threads
    1. Ascending Thread: for(int i=1; i<=15;i++) System.out.println("Ascending Thread : " + i)
    2. Descending Thread: for(int i=15; i>0;i--) System.out.println("Descending Thread : " + i)
    3. main: Ascending a=new Ascending(); a.start(); Descending d=new Descending(); d.start()
  • Command Line Arguments

    Arguments passed at the time of running the java program
  • Program to input name and salary of employee and throw user defined exception if entered salary is negative
    1. NegativeSalaryException extends Exception with constructor
    2. main: BufferedReader br, accept name and salary
    3. if(salary<0) throw new NegativeSalaryException("Enter Salary amount isnegative")
    4. catch (NegativeSalaryException a) System.out.println(a)
  • Applet life cycle
    • init(): Variable declaration and initialization
    • start(): Actual code of the applet
    • stop(): Stops the execution of the applet
    • destroy(): Removes the applet object from memory
    • paint(): Redraws the output on the applet display area