Brief History of Java

Document Sample
Brief History of Java Powered By Docstoc
					                           Brief History of Java
In 1990, Sun Microsystems began an internal project known as the Green
   Project to work on a new technology.
In 1992, the Green Project was spun off and its interest directed toward
   building highly interactive devices for the cable TV industry. This failed
   to materialize.
In 1994, the focus of the original team was re-targeted, this time to the
   use of Internet technology. A small web browser called HotJava was
   written. Oak was renamed to Java after learning that Oak had already
   been trademarked.
In 1995, Java was first publicly released.
In 1996, Java Development Kit (JDK) 1.0 was released.
In 2002, JDK 1.4 (codename Merlin) was released, the most widely used
In 2004, JDK 5.0 (codename Tiger) was released, the latest version.
                          James Gosling

   James Gosling is generally credited as
    the inventor of the Java programming
   He was the first designer of Java and
    implemented its original compiler and
    virtual machine
   He is also known as the Father of
   He is currently the Chief Technical
    Officer of Sun Microsystems
                       What is Java?

A multi-platform, network-centric, object-oriented
  programming language
    Multi-platform

        It can run on almost any computer platform

    Network-centric

        Designed with network in mind – “the network is the
        Designed for building applications for the Internet

    Object-oriented

        It incorporates object-oriented programming model
                           Java Platform Editions

A Java Platform is the set of APIs, class libraries, and other programs used
   in developing Java programs for specific applications

There are 3 Java Platform Editions

1. Java 2 Platform, Standard Edition (J2SE)
     • Core Java Platform targeting applications running on workstations

2. Java 2 Platform, Enterprise Edition (J2EE)
     • Component-based approach to developing distributed, multi-tier
        enterprise applications

3. Java 2 Platform, Micro Edition (J2ME)
     • Targeted at small, stand-alone or connectable consumer and
        embedded devices
    Java Development Kit (JDK)
Java Development Kit (JDK)
     • Is a set of Java tools for developing Java programs
     • Consists of Java API, Java Compiler, and JVM
Java Application Programming Interface (API)
     • Is prewritten code, organized into packages of similar topics
        Java Virtual
Machine (JVM)                JDK
•       Is an
execution engine that           JRE
runs compiled Java
byte code
                                       Java API
                                     Java Virtual Machine
                                   Hardware - Based Platform
                         Key Points

   A Java source file can include package, import and class
    declarations in that order
   The main() method is the start of execution of a Java
   Each Java statement is terminated by a semicolon “;”
   Identifiers are case-sensitive
   Java keywords cannot be used as identifiers
   Each variable must be declared with a data type
   There are 8 primitive data types: boolean, char,
    byte, short, int, long, float and double
   There are 3 reference data types: class, array and
                   Key Points (continued)

   Use unary, arithmetic operators for basic mathematical
   Use string operator to concatenate strings
   Use relational operators to compare objects
   Use conditional operator as alternative to if-else()
   Use logical operators to compare boolean values
   Use assignment operators to assign values to variables
   Get familiar with object, shift and bitwise operators
   Java evaluates operators in order of precedence
   Casting is converting one data type to another
               Key Points
   if() and switch() are used for
    branching statements

   while(), do-while() and for() are
    used for iterating statements

   break, continue and label are used
    to branch inside loops
                         Key Points
   An array is a collection of values (either
    primitive or objects) all of which have the
    same data type

   There are 3 steps in creating an array:
       Declaration
       Creation
       Initialization

   Array elements are accessed using an index
    that starts at 0
                  Key Points
   A method refers to what an object or class can
   A method must have a return type, a name, and
    optional parameters
   The method signature refers to a method name
    and its parameters
   Return statement returns a value to its caller or
    returns control to its caller
   A method that does not return a value must
    specify void as a return type
   Calling a method should match its method
   When calling a method in the same class, use
        What is an Exception?
   An event during program execution
    that prevents the program from
    continuing normally

   An error condition that changes the
    normal flow of control in a program

   A signal that some unexpected
             Types of Exceptions
   All exceptions in Java are objects of Throwable
   Unchecked Exceptions
       are exceptions derived from Error and
        RuntimeException classes
       are usually irrecoverable and not handled
       are not checked by the compiler
   Checked Exceptions
       are exceptions derived from Exception class
        excluding the RuntimeException class
       must be handled explicitly
                  Key Points
   Exceptional conditions sometimes occur in
    properly written code and must be handled
   Exception handling in Java is build around the
    “throw-and-catch” paradigm
   If a method can‟t handle the exception, it can
    propagate the exception to the call stack
   All exceptions are objects of Throwable
   Only Checked exceptions must be handled
             Defining a Class
   A Class acts as the template from which an
    instance of an object is created. The class
    defines the properties of the object and the
    methods used to control the object's
   A Class specifies the structure of data as
    well as the methods which manipulate that
    data. Such data and methods are contained
    in each instance of the class.
   A Class is a model or template that can be
           Defining an Object

An object is a self-contained entity
    with attributes and behaviors
information an object must know:   behavior an object must do:
 identity – uniqueness             methods – what it can do
 attributes – structure            events – what it responds to
 state – current condition
           Defining Abstraction
   Abstraction is the process of extracting
    common features from specific examples
   Abstraction is a process of defining the
    essential concepts while ignoring the
    inessential details
                Different Types of Abstraction

   Data Abstraction
    Programming languages define constructs to simplify the
    way information is presented to the programmer.
   Functional Abstraction
    Programming languages have constructs that „gift wrap‟
    very complex and low level instructions into instructions
    that are much more readable.
   Object Abstraction
    OOP languages take the concept even further and
    abstract programming constructs as objects.
Defining a Java Class

    A Java Class denotes a category of objects, and acts as a
     blueprint for creating such objects.
    It defines its members referred to as fields and methods.
    The fields (also known as variables or attributes) refer to
     the properties of the class.
    The methods (also known as operations) refer to behaviors
     that the class exhibits.
    Class Members
     A class member refers to one of the fields or methods of a class.
     Static members are variables and methods belonging to a class where
      only a single copy of variables and methods are shared by each object.
     Instance members are variables and methods belonging to objects
      where a copy of each variable and method is created for each object
                        Class Modifiers
   Class modifiers change the way a class can be used.
   Access modifiers describe how a class can be accessed.
   Non-access modifiers describe how a class can be
Modifier         Description
(no modifier)    class is accessible within its package only
public           class is accessible by any class in any
abstract         class cannot be instantiated (a class
                 cannot be abstract and final at the same
final            class cannot be extended
strictfp         class implements strict floating-point
                                  Access Modifiers
            private                                                                                            default
  Private features of the                                                                            Only classes that are in the
 Sample class can only be                    Class                                                     package may access
 accessed from within the                                                                            default features of classes
        class itself.                                                                                 that are in the package



                                                  Class              Class

           protected                                                                                           public
   Classes that are in the                                                                             All classes may access
     package and all its                          Class                             Class               public features of the
  subclasses may access                                                                                      Sample class.
  protected features of the
       Sample class.
* Default is not a modifier; it is just the name of the access level if no access modifier is specified.
                         Accessibility Scope
   Accessibility scope defines the boundary of access to a
    class and its members

    Scope       Access
    static     static code can access static members but not
               instance members
    non-static non-static code can access both static
               members and instance members
    package    a class and its members can be accessed
               within the package they are declared
    class      class members can be accessed within the
    block       local variables can be accessed only within a
•Encapsulation is the process of hiding an object‟s
implementation from another object, while presenting
only the interfaces that should be visible.

•Encapsulating a Class

Members of a class must always be declared with the
minimum level of visibility.
Provide setters and getters (also known as
accessors/mutators) to allow controlled access to private
Provide other public methods (known as interfaces ) that
other objects must adhere to in order to interact with the
                           Key Points
   Abstraction is the process of formulating general concepts
    by extracting common properties of instances.
   A class is an abstraction of its instances.
   A Java Class denotes a category of objects.
   Class members refer to its fields and methods.
   Static members are variables and methods belonging to a
   Instance members are variables and methods belonging to
   Instantiating a class means creating objects of its own
   Class modifiers include: (no modifier), public, abstract,
    final and strictfp.
   Member modifiers include: (no modifier), public,
    protected, private, static, final, abstract,
    strictfp, synchronized, native, transient and
                   Key Points (Continued)

   Encapsulation hides implementation details of a class.
   Encapsulating a class means declaring members with
    minimum level of visibility.
   Setters are methods whose only function is to alter the
    state of an object in a controlled manner.
   Getters are methods which only function is to return
    information about the state of an object.
   Constructors are methods which set the initial state of
    an object upon creation of the object.
                      Defining Inheritance

   Inheritance is the ability to derive new classes from
    existing ones. A derived class ("subclass") inherits the
    instance variables and methods of the base class
    ("superclass"), and may add new instance variables and
   Inheritance defines a hierarchical relationship among
    classes wherein one class shares the attributes and
    methods defined in one or more classes.
   Inheritance is a relationship among classes in which one
    class shares the structure and behavior of another. A
    subclass inherits from a superclass.
                   Relationships of Inheritance
   “is-a” relationship
      a subclass can be used wherever a superclass can be
      implemented in Java by extending a class
   “has-a” relationship
      a whole-class relationship between a class and its
      also known as composition or aggregation
      implemented in Java by instantiating an object inside a
                                      “has-a” relationship
     “is-a” relationship

          Vehicle                            Car

    Car             Bus
                        this and super

   this is a reference to the object of the current class
      It can be used to distinguish instance variables from
       local variables
      It can be assigned to other references, or passed as a
       parameter, or cast to other types
      It cannot be used in a static context

   super is a reference to the object of a superclass
       Used to access hidden members of the superclass
       It cannot be assigned to other references, nor passed
        as a parameter, nor cast to other types
       It cannot be used in a static context
   Casting is converting from one data type to another
      Implicit casting is an implied casting operation

      Explicit casting is a required casting operation

      Primitive casting is converting a primitive data type to
        another data type
            Widening conversion is casting a narrower data type to
             a broader data type
            Narrowing conversion is casting a broader data type to
            a narrower data type
       Reference casting is converting a reference data type to
          Upcasting is conversion up the inheritance hierarchy

          Downcasting is conversion down the inheritance
       Casting between primitive and reference type is not
       In Java, casting is implemented using () operator
                              Key Points

   Inheritance is deriving a new class (subclass) from an existing
    class (superclass)
   Inheritance can exhibit an “is-a” or “has-a” relationship
   In Java, a class can only inherit from a single class
   All classes inherit from Object class – the highest in the
    inheritance hierarchy
   In Java, inheritance is implemented by the extends keyword
   this is a reference to the object of the current class
   super is a reference to the object of a superclass
   this() is used to call constructors within the same class
   super() is used to invoke constructors in the immediate
   Casting is converting from one data type to another
        Defining Polymorphism
   Polymorphism is the ability of different objects to
    respond to the same message in different ways. This
    means that different objects can have very different
    method implementations for the same message.
   Polymorphism is the ability of a new object to implement
    the base functionality of a parent object in a new way.
   Polymorphism is an object's ability to behave differently
    depending on its type.
   Polymorphism is the ability of objects belonging to
    different types to respond to methods of the same
    name, each one according to the appropriate type-
    specific behavior.
           Method Overloading
   Method Overloading is the process of declaring
    methods with the same name but different parameter

   A method can be overloaded in the same class or in a

   Which overloaded method to call is based on reference
    type and decided at compile time.

   Which overridden method to call is based on object
    type and decided during runtime.
     Rules of Method Overloading
1.   Overloaded methods must change the argument list.

2.   Overloaded methods can change the return type.

3.   Overloaded methods can change the access modifier.

4.   Overloaded methods can declare new or broader
     checked exceptions.
              Method Overriding
   Method Overriding allows a subclass to redefine
    methods of the same name from the superclass.

   The key benefit of overriding is the ability to define/defer
    behavior specific to subclasses.

   Which overridden method to call is based on object type
    and decided at runtime.
         Rules of Method Overriding
1.   An overridden method must have
     •   the same name
      • the same number of parameters and types

      • the same return type

      as the overridden method.
2.   Overriding a method cannot narrow the method access
     level defined in the overridden method.
3.   Overriding a method cannot widen checked exceptions
     defined in the overridden method.
4.   Methods declared as private, static, or final
     cannot be overridden.
5.   A static method cannot override an instance method.
      Overloading vs Overriding
Criteria   Overloaded Method
Argument Different                   Same
Return     Can change                Same
Exceptions Can change                Cannot be wider
Access     Can change                Cannot be narrower
Invocation Based on reference type   Based on object
           and decided at compile    type and decided at
           time                      runtime
         Defining Abstract Class
   An Abstract Class is a class that provides common
    behavior across a set of subclasses, but is not itself
    designed to have instances of its own
   A class that dictates certain behavior but allows its
    subclasses to provide implementation
   A class designed only as a parent from which sub-classes
    may be derived, but which is not itself suitable for
   A class often used to "abstract out" incomplete sets of
    features which may then be shared by a group of sibling
    sub-classes which add different variations of the missing
                   Rules on Abstract Class

   An Abstract Class cannot be instantiated
   An abstract class can SHOULD be extended
   An abstract class can have any number of abstract
    methods or none at all
   A class with at least one abstract method must be
    declared an abstract class
   A subclass can provide partial or full implementations of
    the inherited abstract methods
   A class that has at least one abstract method, whether
    declared or inherited from an abstract class, must be
    declared abstract.
               Defining Interface
   An Interface defines a contract by specifying a set of
    method prototypes for which each class that implements
    it must adhere

   An interface is 100% abstract class

   An interface provides only a form for a class but no
   An interface defines what a class can do but not how the
    class will do it
         Implementing Interface
   Implementing an interface means providing
    implementations for its methods
   Interfaces are implemented using the implements
   Rules on implementing the interface methods
     1. Must have the same method signature and return
     2. Cannot narrow the method accessibility

     3. Cannot specify broader checked exceptions

   Interface variables are implicitly public final
   Interface methods are implicitly public abstract
             Defining Final Class
   A Final Class is considered complete, it cannot be
    improved or specialized

   A final class ensures that its state and behavior cannot
    be changed for safety and security

   To re-use a final class, you must utilize composition
    instead of inheritance
            Rules on Final Class
   A final class cannot be extended or subclassed

   All methods of a final class have implementations

   All methods of a final class are implicitly final

   Members of the final class cannot be inherited or hidden

   Methods of the final class cannot be overridden
What is a Collection?
A Collection (also known as container) is an object that contains a
group of objects treated as a single unit.
Any type of objects can be stored, retrieved and manipulated as
elements of collections.

Collections Framework is a unified architecture for managing

Main Parts of Collections Framework
      Core interfaces defining common functionality exhibited by
      Concrete classes of the core interfaces providing data
      Methods that perform various operations on collections
                    Collections Hierarchy
                              Set and List


             Set                                                 List

implements         extends                                     implements


LinkedHashSet                  TreeSet            LinkedList     Vector     ArrayList

value   “Paul”   “Mark”       “John”   “Paul”       “Luke”

index       0      1             2       3            4

A List cares about the index.

ArrayList                 Vector                LinkedList

                          “John”         “Luke”
                               “Mark”       “Fred”

A Set cares about uniqueness,
  it doesn’t allow duplicates.

 HashSet                 LinkedHashSet               TreeSet

  key      “Pl”        “Ma”      “Jn”     “ul”     “Le”

 value    “Paul”       “Mark”   “John”   “Paul”   “Luke”

   A Map cares about unique
HashMap           Hashtable                       TreeMap

Shared By: