translate in your language

Saturday, April 16, 2011

*) An overview of Java

                                                CHAPTER-2


*)  Two Paradigms:-  All computer programs consists of 2 elements
                                   !) Code   2) Data


>) A program can  coneceptually organized around its code or around its data.


>) Programs  written around "what is happening" is called process-oriented 
     model.
    *) The process-oriented model can be thought of as code acting on data.
    *) This approach characterizes a program as a series of linear steps
         (that is,code).
    *) Procedural languages such as "C" employ  this model to considerable 
        success.
    
    Disadvantage:- Problems with this approach appear as programs grow  
                              larger and more complex.




>) Object Oriented Programming:- To manage increasing complexity this 
                               approach organizes a program around its data(that is,objects
                               and a set of  well-defined interfaces to that data.


    *) OOP program can be characterized as data controlling access to code,by
        switching the controlling entity to data,you can achieve several 
        organizational  benefits.


   




>) Abstraction :- This is an important element of  OOP,complexity is
                                        managed   through abstraction.


    Example:- We think Car is a well-defined object with its own unique behavior.
                    not as a thousands of individual parts.Instead ,they are free to utilize
                    the object as a whole.


   *) Hierarchical classifications is a powerful way to manage abstraction.It layer
       the semantics(the study of language meaning) of complex systems,breaking
       them into more manageable pieces.




   *) Data from a process-oriented program can be transformed into its component
       objects by abstraction.


   *) Each of these objects describes its own unique behavior.A sequence of 
        process  steps can become a collection of messages between these objects.



> The Three OOP Principles:- All OOP languages provide a
                 mechanisms that help us implement the object-oriented model.
            
        1) Encapsulation   2) Inheritance    3) Polymorphism

1) Encapsulation:- It binds together Code & Data it manipulates(handles),
                 and keep both safe from outside interference and misuse.

   @) It acts like a protective wrapper that prevents the code and data from being
        arbitrarily(Based on random choice or codes)accessed by other code defined 
        outside the wrapper.Access to the code and data inside the wrapper is 
        tightly controlled through a well-defined
        interface(A point where two systems interact).

*) Example :-In the automatic transmission on an automobile.It encapsulate
                            hundreds of bits of information about your engine,such as how
                            much you are accelerating,the pitch of the surface you are on
                            and the position of the shift lever.

                       *) We as the user have only one method of affecting this complex
                           encapsulation;by moving the gear-shift lever.We can't affect 
                           the transmission by using the turn signal or windshield wipers.
                           Thus,the gear-shift lever is a well-defined interface to the
                            transmission.

                       *) What occurs inside the transmission does not affect objects 
                           outside the transmission.
                           Example:- Shifting gears does not turn on the horn,because
                                             an automatic transmission is encapsulated.

@) The power of encapsulated code is that everyone knows how to access it and
      thus can use it regardless of the implementation details and without fear of
      unexpected side effects.This same idea can be applied to programming.

@) In java,basis of encapsulation is the CLASS
      
      Class:- A class defines the structure and behavior(data and code) that will
                   shared by the set of Objects.
             
               >>Each object of a given class contains the structure and behavior
                   defined by the class.Objects sometimes referred to as
                   instances(a particular case) of the class

              >> A Class is a logical construct(Form or an idea);an object has
                   physical reality.


@) The code and data that constitute the class.Collectively,these elements
      are called members of the class

     >>Member variables or instance variables:- The data defined by the class.

     >>Member Methods or Methods :- The code that operates on that data.

         (*) Note:- Method in Java is similar to that of function in C/C++.


@) The methods define the behavior and interface of a class that operate on 
      its instance data and how  the member variables can be used.

@) Each method or variable in a class may be market private or public.

@) The public interface of a class represents everything that external users
      of the class need to know.

@) The private methods and data can only be accessed by code that is a
      member of the class.

@) Code which is not a member of a class cannot access a private method
      or variable.



> Inheritance :- This is the process by which one object acquires
                                          the properties of another object.
    
    @) This is important because it supports the concept and most knowledge
          is made manageable by hierarchical(that is,top-down) classifications.

    @) Without hierarchies,each object would need to define all of its charac-
          teristics explicitly.

    @) However,by use of inheritance,an object need only define those 
          qualities that make it unique within its class.It can inherit it's general
          attributes from its parent.

    @) Thus,it is the inheritance mechanism that makes it possible for one
          object to be a specific instance of a more general case.

> Example:- If order to describe animals in an abstract way,you would
                             say they have some attributes,such as *) size
                                                                                          *) intelligence,and
                                                                                          *) skeletal system
     
    @) Animals also have certain behavioral aspects;they *) eat
                                                                                           *) breathe,and
                                                                                           *) sleep

    @) This description of attributes and behavior is the class definitions for
          animals.

    @) If you wanted to describe a more specific class of animals,such as 
          mammals,they would have more specific attributes;such as type of
          *) teeth and *) mammary glands

    @) This is known as a subclass of animals,where animals are referred to
          as mammals superclass.

    @) Since mammals are simply more precisely specified animals,they inherit
          all of the attributed from animals.

     @) A deeply inherited subclass inherits all of the attributes from each of its 
           ancestors in the class hierarchy.

   *) Inheritance interacts with encapsulation as well.If a given class encapsulates
       some attributes,then any subclass will have the same attributes plus any that
       it adds as part of its specialization.

   *) This is a key concept that lets object-oriented programs grow in complexity
        linearly rather than geometrically.

   *) A new subclass inherits all of the attributes from all of its ancestors and does
       not have unpredictable interactions with the majority of the rest of the code
       in the system.


> Polymorphism:- A feature that allows one interface to be used for a
          a general class of actions is called polymorphism(Many forms)

   @) The specific action is determined by the exact nature of the situation.

   @) Consider three type of stacks(which is a last-in,first-out list) 

         *) integral values
         *) floating-point and
         *) one for characters.

         The algorithm that implements each stack is the same,even though data
         being stored differs.

  @) In a non-object-oriented language,you would be required to create three
        different sets of stack routines,with each set using different names.

  @) However,because of polymorphism,in Java you can specify a general set
        of stack routines that all share the same names

  @) Polymorphism is often expressed by the phrase " one interface,multiple
        methods."This means that it is possible to design a generic interface to
        a group of related activities.

  @) This helps reduce complexity by allowing the same interface to be used to
        specify a general class of action.

  @) It is the compiler's job to select the specific action(i.e,method) as it applies
        to each situation.We as a programmer do not need to make this selection
        manually.You need only remember and utilize the general interface.

*) Example:- A dog sense of smell is polymorphic.
                             >> If the dog smells a cat,it will bark and run after it.
                             >> If the dog smells its food,it will salivate and run to its bowl.

     The same sense of smell is at work in both situations.The difference is what
     being smelled,i.e, the type of data being operated upon by the dog's nose!This
     same general concept can be implemented in Java as it applies to methods
     within a Java program.


*) Polymorphism,Encapsulation,and Inheritance work 
    together:-
                 
     @) When this 3 mechanism properly combine to produce a programming 
           environment that supports the development of far more robust and 
           scalable programs than does the process-oriented  model.

     @) A well-designed hierarchy of classes is the basis for reusing the code in 
           which you have invested time and effort developing and testing.

     @) Encapsulation allows you to migrate your implementations over time 
           without breaking the code that depends on the public interface of your 
           classes.

     @) Polymorphism allows you to create clean,sensible ,readable,and resilient 
          code.

*) Inheritance Example :- All drivers rely on inheritance to drive 
         different types of vehicles,more or less find and operate the steering wheel,
         the brakes,and the accelerator.

     >>After a bit of gear grinding most people can even manage the difference 
          between a stick shift and an automatic,because they fundamentally 
         understand their common superclass,the transmission.

*) Encapsulated Example:- People interface with encapsulated
                                                                      features on cars all the time.

     >> The brake and gas pedals hide an incredible array of complexity with an
           interface so simple you can operate them with your feet.

    >> The implementation of the engine,the style of brakes,and the size of the
          tires have no effect on how you interface with the class definition of pedals.

*) Polymorphism Example:- It is clearly reflected in the ability of
               car manufacturers to offer a wide array of options on basically the same
               vehicle.

    *) For Example:- We can get an anti-lock breaking system or traditional brakes
                    power or rack-and-pinion steering,and 4-,6-,or 8-cylinder engines.
                       
              >> Either way,you will still press the break pedal to stop,turn the
                   steering wheel to change direction,and press the accelerator
                   when you want to move.The same interface can be used to control
                   a number of different implementations.


@) It is through this 3 mechanism that the individual parts are transformed into
      the object known as a car.

@) The same is also true of computer programs.By the application of object-
      oriented principles,the various parts of a complex program can be bought
      together to form a cohesive,robust,maintainable whole.

 @) Every Java program is object-oriented
      

Saturday, April 2, 2011

*) The History and Evolution of Java

                                                           CHAPTER-1


*)  To fully understand:- Java,one must understand the reasons behind its
                  creation,the forces that shaped it,and the legacy that it inherits.
                  Like the successful computer languages that came before,Java 
                  is a blend of the best elements of its rich heritage combined with
                 the innovative concepts required by its unique mission.
  
           >)  Computer language innovation and development occurs for two 
                 fundamental reasons:
                
                 *) To adapt to changing environments and uses
                 *) To implement refinements and improvements in the art of 
                     programming.










*) Java's Lineage :- Java is related to C++,which is a direct descendant of C. 
                    From 'C',java derives its syntax.Many of java's object-oriented
                    features were influenced  by C++.
            
              Each innovation in language design was driven by the need to solve a 
   fundamental problem that the preceding languages could not solve.
  Java is no exception(A deliberate act of omission).










*) The Creation of Java :- Java was conceived(have the idea for) by
                                         *) James Gosling
                                         *) Patrick Naughton
                                         *) Chris Warth
                                         *) Ed Frank  and
                                         *) Mike Sheridan  at Sun Microsystems,Inc.in 1991.
    This language was initially called "Oak",but was renamed "Java" in 1995.










*) Key contributors to the design and evolution of Java :-
    >) Bill Joy
    >) Arthur van Hoff
    >) Jonathan Payne
    >) Frank Yellin
    >) Tim Lindholm








*) Primary motivation :- The need for platform-independent 
                 (that is(i.e.,) architecture-neutral) language that could to create 
    software to be embedded in various electronic devices.
            
                     Gosling and others began work on portable,platform-independent
    language that could be used to produce code that would run on a variety of
    CPUs under differing environments.










*) Secondary force :- With the emergence of World Wide Web,Java was 
                  propelled(cause to move forward with force) to the forefront of
    computer language design,because the Web,too,demanded 
    portable(easily or conveniently transported) programs.










*) How Java changed the Internet:-Java innovated a new 
             type of networked program called the applet that changed the way
    the online world thought about content.It also addressed some of the 
    thorniest issues associated with the Internet : portability and security.










*) Java Applets :-Its a special kind of Java program that is designed to be
                  transmitted over the internet and automatically executed by a Java-
                  compatible web browser.
    
     >) Applets are intended to be small programs and is downloaded on demand
         without further interaction with the user.    
    
      >) Handles user input,or provide  simple functions,
          Example:- calculator ,that execute locally,rather than on the server.         


      >) It expanded the universe of objects,there are two very broad categories
          of objects that are transmitted between the server and the client:
          *) Passive
          *) dynamic and
          *) active programs. 
  
          Example :-When you read your e-mail,you are viewing passive data,Even
                       when you download a program,the program's code is still only
          passive data until you execute it.


      >) Applet is a dynamic,self-executing program.Such a program is an 
          active agent on the client computer,yet it is initiated by server.










*) Security:- Every time you download a "normal" program,The program 
          might contain "virus" like Trojan horse ,or other harmful code.Malicious
          code can cause damage or gained unauthorized access  to system
          resources.
   Example :- A virus code might gather private information,such as credit card
               numbers,   bank account balances,and passwords,by searching the 
               contents of your  computer's local file system.


    >) Java achieved this protection by confining(restricting the scope) an applet to
         the Java execution environment and not allowing it access to other parts of 
         the computer.












*) Portability :-  >) Portability is a major aspect of the Internet.
               >) If a Java program were to be run on virtually any computer connected
                    to the internet,there needed to be some way to enable that program
                    to execute on different systems.
    
     Example:- Same applet must be able to be downloaded and executed by the 
                      wide variety of CPUs,operating systems,and browsers connected to
                      the Internet.
    >) The same code must work on all computers.Java provides a portable 
         executing code and solved this problems.














*) Bytecode :-  It is a highly optimized(use best) set of instructions designed
                                 to be executed by the Java run-time system,which is called
                                 Java Virtual Machine(JVM)
                            
    >) The output of Java compiler is not a executable code.Rather, it is bytecode.


   >) Java program is executed  by the JVM ,which helps in solving major 
       web-based programs.


   >) Translating a Java program into bytecode makes it much easier to run a 
        program in a wide variety of environments because only the JVM needs 
        to be implemented for each platform.


   >) JVM will differ from platform to platform,all understand the same bytecode.


   >) Java program executed by the JVM helps to make it secure.and prevent it 
        from generating side effects outside of the system.


  >) Safety is also enhanced by certain restrictions.


  >) The use of bytecode enables the JVM to execute programs much faster than
       you might expect.










*) Just-In-Time(JIT):- >) HotSpot provides a JIT compiler for bytecode.
                   
    >) When a JIT compiler is part of the JVM,selected portions of bytecode are
         compiled into executable code in real time,on a piece-by-piece,demand
         basis.


   >) It is not practical to compile an entire Java program into executable code all
        at once,because Java  performs various run-time checks that can be done only 
        at run-time.


   >) Not all sequences of bytecode are compiled-only those that will benefit from
       compilation.The remaining code is simply interpreted.


   >) JIT yields a significant performance boost.


   >) The portability and safety features still remains, even if dynamic compilation
        is applied to bytecode ,because JVM is still in charge of the execution
        environment










*) Servlets :- A servlet is a small program that executes on the server.It 
                              extend the functionality of a web server


     >) With the advent of the servlets ,it spanned
         (extend over an area or time period) both sides of the client/server 
         connection.


     >) It is used to create dynamically generated content that is then served to the
          client.
       Example:- An online store might use a servlet to look up the price for an item
                         in a database.The price information is then used to dynamically 
                         generate a web page that is sent to the browser.


    >) Dynamically generated content is available through mechanisms such as
        CGI(Common Gateway Interface).


   >) Servlets are highly portable,Same servlet can be used in a variety of different
        server envionments,The server should support  the JVM and a servlet 
        container












*) The Java Buzzwords :- The fundamental forces that necessitated the
                  invention of Java are portability and security.The key considerations 
    were summed up by the Java team in the following list of buzzwords:
    >) Simple
    >) Secure
    >) Portable
    >) Object-oriented
    >) Robust
    >) Multithreaded
    >) Architecture-neutral
    >) Interpreted
    >) High performance
    >) DIstributed
    >) Dynamic













*) Simple :- It was designed to be easy for the professional programmer to
                          learn and use effectively.


    >) If you already understand the basic concepts of object-oriented
         programming,learning Java will be even easier.
  
   >) If you are an experienced C++ programmer moving to Java will require 
       very little effort


  >) Java inherits the C/C++ syntax and many of the object-oriented features
      of C++  ,programmers have little trouble learning Java.














*) Object-Oriented :-  Java was not designed to be source-code 
                       compatible    with any other language.This allowed the Java
                       programmer the flexibility to design with a blank slate.


    >) Outcome of this was a clean,usable,pragmatic approach to objects.


    >) Java manages to maintain balance between an object and a model.


    >) The Object model in Java is simple and easy to extend,while 
         primitive types,such as integers,are kept as high-performance
         non-objects.












*) Robust :- Web world  is a multiplatformed environment ,which demands
                          the programs that execute reliably in a variety of systems.


    >) Java gave high priority to robust programs which executes on every
         systems.


   >) Java restricts the user in a few key areas to help to find your mistakes 
        early in program. development.


  >) Java removes worry for the users about the most common causes of 
       programming errors.


  >) Java is a  strictly typed(identify as belonging to a certain type) language,
       It checks your code at compile time also at run time.


  >) Many effective bugs that often turn up in hard-to-reproduce run-time 
      situations are simply impossible to create in Java.


  >) To better understand how Java is robust,Java eliminates the problems by
       managing memory allocation and deallocation for you.Which is a tedious
       and difficult task to perform in traditional programming languages.


  >) Deallocation is automatic,Java provides  garbage collection for unused
       objects.


 >) Java help in exceptional conditions by providing object-oriented exception
      handling.In Java all run-time errors can-and should -be managed  by your
      program.










*) Multithreaded :- >) Java supports multithreaded programming,
     which allows you to write programs that do many things simultaneously.


>) The Java run-time system comes with an elegant yet sophisticated 
     solution for multiprocess synchronization that enables you to construct
     smoothly running interactive systems.


>) Java allows you to think about the specific behavior of your program,
     not the multitasking subsystem.










*) Architecture-Neutral:- The main issue for the programmers 
                                                         was that of code longevity and portability.


  >) The main problems is that no guarantee exists that if you write a program
       today,it will run tomorrow--even on the same machine.


  >) Operating system and processor upgrades,changes in core system 
       resources can make a program malfunction.


 >) JVM is an attempt to alter this situation.Their goal was "write once; run
      anywhere, any time,forever." To a great extent,this goal was accomplished.










*) Interpreted and High-Performance :- Java  enables the
             creation of cross-platform programs by compiling into an intermediate
             representation called Java bytecode.


    >) Any system that implements the JVM can easily execute the bytecode.


   >) Java bytecode was carefully designed so that it would be easy to translate
       directly into native machine code by using JIT(Just in Time) compiler.








*) Distributed :- Java is designed for the distributed environment of 
                                      the Internet because it handles TCP/IP protocols.


    >) Accessing  a resource using URL is not much different from 
        accessing a file.


   >) Java also supports Remote Method Invocation(RMI).This enables a 
        program to invoke methods across a network.










*) Dynamic :-  Java programs carry with them substantial amounts of
              run-time type information that is used to verify and resolve accesses
              to objects at run-time.


    >) This make it possible to dynamically link code in a safe and expedient 
         manner.


   >) This is crucial to the robustness of the Java environment ,in which small
        fragments of bytecode may be dynamically updated on a running system.










                                       *) The Evolution of Java


>) After the release of Java 1.0,the designers of Java had already created
    Java 1.1.


>) The features added by Java 1.1 were more significant and substantial and
     added many new library elements,redefined the way events are handled,
     and reconfigured many features of the 1.0 library.


>) The creation of Java 2,marking the beginning  of Java's "modern age."


>) It may seem odd that the first release of Java 2 used the 1.2 version
     number.It originally referred to the internal version number of the Java
     libraries,but then was generalized to refer to the entire release.


>) Java 2 added a new features,such as Swing and the Collections Framework,
    and it enhanced  the JVM and various programming tools.


>) Java 2 affected the Thread class in which the methods suspend(),resume(),
    and stop() were deprecated(strong disapproval)


>) J2SE 1.3 was the first major upgrade to the original Java 2 release.


>) Although version 1.3 contained a smaller set of changes.Program written
     for version 1.2 and those for version 1.3 are source-code compatible.


>) J2SE 1.4 further enhanched several important upgrades,enhancements,
    and additions in Java.


    Example:- It added the new keyword assert,chained exceptions and
                      a channel-based I/O subsystem.It also made changes  to
                      the Collections Framework and the networking classes.


>) Version 1.4 maintained  nearly 100 percent source-code compatibility
     with prior versions.


>) J2SE 5 fundamentally the scope,power,and range of the language.


>) J2SE 5 major new features :-
    @) Generics
    @) Annotations
    @) Autoboxing and auto-unboxing
    @) Enumerations
    @) Enhanced,for each type of loop
    @) Variable-length arguments(varags)
    @)  Static import
    @) Formatted I/O
    @) Concurrency utilies


>) Each item in the list represents a significant addition to the Java language.
    Some,such as generics,the enhanced for,and varargs,introduce new syntax
    elements.


>) Autoboxing and auto-unboxing alter the semantics of the language and 
    Annotations new dimension to programming.


>) Sun  elected to increase the version number to 5 as a way of emphasizing
     that a major event was taking place.Thus,it was named J2SE 5,and the
     developer kit was called JDK 5.


>) In order to maintain consistency,Sun decided to use 1.5 as it internal 
    version number.


>) 1.5 also referred to as the developer version number.5 in J2SE 5 is
     called the product version number.






*) Java SE 6:- With the release of SE 6,Sun once again decided to change
                           the name of the Java platform.


>) First,notice that the "2" has been dropped.Thus,the platform now has the
    name Java SE,and the official product name is 
   Java platform ,Standard Edition 6.


>) 6 in Java SE 6 is the product version number.The internal,developer version
     version number is 1.6.


>) Java SE 6 builds on the base of J2SE 5,adding incremental improvements,
     enhanced the API libraries,new packages and offer improvements to the
     run time.


>) Java SE 6 serves to further solidify the advances made by J2SE 5.








*) A Culture of Innovation :- Java release redefined programming for the 
                                                Internet.


>) The JVM and bytecode changed the way about security and portability.


>) Applet and Servlet made the Web come alive.


>) The Java Community Process(JCP) redefined the way that new ideas are
     assimilated into the language.


>) Java has never stood still for very long,Java SE 6 is the latest release in
    Java's ongoing,dynamic history.