JPR_W-19

Cards (50)

  • Constructor
    A special member which initializes an object immediately upon creation. It has the same name as the class name in which it resides and is syntactically similar to any method.
  • Types of constructors
    • Default constructor
    • Parameterized constructor
    • Copy constructor
  • Class
    A user defined data type which groups data members and its associated functions together
  • Object
    A basic unit of Object Oriented Programming and represents the real life entities
  • Methods of FileInputStream Class
    • void close()
    • int read()
    • int read(byte[] b)
    • read(byte[] b, int off, int len)
    • int available()
  • Error
    Mistakes that can make a program go wrong. They may be logical or typing mistakes, and can produce incorrect output, terminate execution abruptly, or cause the system to crash.
  • Types of errors
    • Compile time errors
    • Runtime errors
  • Java API packages
    • java.lang
    • java.util
    • java.io
    • java.awt
    • java.net
    • java.applet
  • Array
    A homogeneous data type where it can hold only objects of one data type
  • Types of arrays
    • One-Dimensional
    • Two-Dimensional
  • Access specifiers in Java
    • public
    • private
    • friendly
    • protected
    • Private Protected
  • String
    A major class where length is fixed (immutable) and contents cannot be modified
  • StringBuffer
    A peer class of String where length is flexible (mutable) and contents can be modified
  • Defining a class Circle
    1. Initialize data members pi and radius
    2. Display values of data members
    3. Calculate and display area of circle
  • Exception
    A problem that arises during the execution of a program. Java exception handling is used to handle error conditions systematically.
  • Built-in exceptions
    • Arithmetic exception
    • ArrayIndexOutOfBounds Exception
    • ClassNotFoundException
    • FileNotFoundException
    • IO Exception
    • NullPointerException
    • NumberFormatException
    • StringIndexOutOfBoundsException
    • OutOfMemoryException
    • SecurityException
    • StackOverflowException
  • drawRect()
    Displays an outlined rectangle. Syntax: void drawRect(int top,int left, int width,int height)
  • drawOval()
    Draws an ellipse or circle. Syntax: void drawOval(int top, int left, int width, int height)
  • Byte stream class
    Designed for byte streams. InputStream and OutputStream are abstract classes that define Java's model of streaming byte input and output.
  • Character stream class
    Designed for character streams. Reader and Writer are abstract classes that define streaming character input and output.
  • Applet life cycle
    1. init()
    2. start()
    3. paint()
    4. stop()
    5. destroy()
  • Class
    Doesn't support multiple inheritance, uses "extend" keyword to inherit, contains method body
  • Interface
    Supports multiple inheritance, uses "implements" keyword to inherit, contains abstract methods (without body)
  • Vector
    A dynamic array that can grow or shrink in size as needed
  • Creating a vector with 5 elements
    1. Add element 5
    2. Add element 15
    3. Add element 25
    4. Add element 35
    5. Add element 45
  • Inserting a new element at the 2nd position
    Insert element 20 at index 1
  • Removing the 1st and 4th elements from the vector
    1. Remove element at index 0
    2. Remove element at index 3
  • Vector creation and manipulation
    • Vector v = new Vector();
    • v.add(5);
    • v.add(15);
    • v.add(25);
    • v.add(35);
    • v.add(45);
    • v.add(1, 20);
    • v.remove(0);
    • v.remove(3);
  • replace()
    Method to replace all occurrences of old Char in a string with new Char
  • String s1="Java is a programming language. Java is a platform."
    • String s2=s1.replace("Java","Kava");//replaces all occurrences of "Java" to "Kava"
  • Output: Kava is a programming language. Kava is a platform.
  • Creating a vector with five elements
    1. addElement(new Integer(5))
    2. addElement(new Integer(15))
    3. addElement(new Integer(25))
    4. addElement(new Integer(35))
    5. addElement(new Integer(45))
  • Inserting new element at 2nd position
    insertElementAt(new Integer(20),1)
  • Removing 1st and 4th element from vector
    1. removeElementAt(0)
    2. removeElementAt(3)
  • Package is both naming and visibility controlled mechanism in Java
  • Package
    Mechanism for partitioning the class namespace into more manageable parts
  • Packages are mirrored by directories
  • package package1; public class Box { ... }
    • import package1.Box; class volume { ... }
  • Creating two threads
    1. new Even().start()
    2. new Odd().start()
  • Even thread printing even numbers 2 to 50
    for(int i=2;i<=50;i=i+2){ System.out.println("\t Even thread :"+i); sleep(500); }