Java Basic PART I Soumen Santra MCA, M.Tech, SCJP, MCP
Java Write Once, Run Anywhere IN ANY PLATFORMONE SOURCE CODE
Java : Components Editor: Write the source code. Linker: Link the Source code with the library files. Java Compiler – Keyword javac use as convert Java source code to bytecode. Bytecode - An intermediate form, known as native code, closer to machine code. JVM-Java Virtual Machine , a concept of target platform which interprets the bytecode. Interpreter-The interpreter demonstrates the platform independent .class file to equivalent machine dependent code to run. Keyword java. Javadoc-API Documentation generator. JRE- Java Runtime Environment.
Java : Features JVM uses bytecodes as .class file. Light-weight Small binary class files for fast execution. Just-in-time (JIT) Compilers for compiling only changes code. Multithreading for high process and memory management. Native Methods Interfaces as JNDI. Native Methods Libraries.
Java : Features (Cont..) Class Loader. Dynamic. Good communication constructs. Secure. Portable and Compatible. Understandable and easy-to-write. Fully Object Oriented. Support Console based, Windows based and Web based application. Case-sensitive. JRE. Jdk (Java Development toolkit).
General Language Features C/C++ like syntax, ends with ; No pointers concept. Objects taken all controls. Objects communicates with objects through messages. Messages result in invocation of class methods.
Java : Security Language designed as safe. Strict compiler javac & JIT. Dynamic Runtime Loading (Verifier). Runtime Security Manager. Jar- Create & manage all the java archive files. Method area. Heap. JVM language stacks. Pc registers. Native method stacks. Java kernel.
Security Manager Prevents unauthorized disk read/writes. Restricts network access without creating dynamic link library files. Restricts Other access (native methods). Implementation is browser or processor dependent.
Object Oriented Languages Comparison with java C++ Objective C Ada Java Encapsulation Yes Yes Yes Yes Inheritance Yes Yes No Yes Multiple Inheritance Yes Yes No No Polymorphism Yes Yes Yes Yes Binding (Early/Late) Both Both Early Both Concurrency Poor Poor Difficult Yes Garbage Collection No Yes No Yes Genericity Yes No Yes No Class Libraries Yes Yes Limited Yes FEATURES
Features Removed From C++ Operator overloading. Pointers of Array/pointers. Multiple-inheritance of implementation through class inherit concept. Enum, typedef, #define. Copy constructors, destructors. Templates. And many more....
Added or Improved over C++ Interfaces over class. Garbage collection. Exceptions (More featureful than C++). Strings and many implementation. Instanceof. Package. Multi-threads.
Java better than C++ No Typedefs, Defines, or Preprocessor. No Global Variables. No goto statement. No Pointers. No Unsafe Structures. No Multiple Inheritance. No Operator Overloading. No Automatic Coercions. No Fragile Data Types. No copy constructor.
Basic Data Types Data Types boolean either true of false char 16 bit Unicode 1.1 byte 8-bit integer (signed) short 16-bit integer (signed) int 32-bit integer (signed) long 64-bit integer (signed) float 32-bit floating point double 64-bit floating point String (class for manipulating strings) String, StringBuilder, StringBuffer, StringTokenizer  Java uses Unicode to represent characters internally.
Java Integrates Power of Compiled Languages and Flexibility of Interpreted Languages  Applet.  Swing & Layout Manager.  Hibernate.  Struts.  Spring  Servlet  Java Server Pages (JSP)  Java Bean.  Enterprise Java Bean (EJB).  J2ME.  Junit.  & Many More.
Power of Java and the Web Deliver .exe, not just .class. Remove porting. Remove end-user installation. Remove software distribution costs. Access by millions of customers through web.
Applications : Types Different possibilities to write/run a Java codes are: Application- A stand-alone program that can be invoked from command line through console which has a “main” method. Applet- A program embedded in a web page , to be run when the page is browsed . A program that contains no “main” method. Application -Java interpreter Applets- Java enabled web browser (Linked to HTML via <APPLET> tag. in html file or run through Appletviewer).
Java Bytecodes move locally or through network Java Source code (.java) Java Compiler Java Bytecode (.class ) Java Interpreter Just in Time Compiler Runtime System Class Loader Bytecode Verifier Java Class Libraries Operating System Hardware Java Virtual machine Runtime Environment Compile-time Environment Life Cycle of Java Code
Lifecycle of Java Code
Java Development Kit javac – Name of the Java Compiler. java - Name of the Java Interpreter. jdb- Name of the Java Debugger. appletviewer - Name of the Tool to run the applets code and give Applet window. javap – Use to print the Java bytecodes. javaprof - Name of the Java profiler. javadoc - Name of the documentation generator. javah - Name of the creates C header files. Javak= Name of the Kernel of the java.
Bytecode Verifier It Called when the class is first loaded in runtime environment by JRE. It Verifies the bytecodes meet certain set of properties. Verified code runs faster through JRE. After verification, interpreter defines memory layout. Release all memories through Garbage collector.
Java Example : Hello World // HelloWorld.java: Hello World program class HelloWorld { public static void main(String args[]) { System.out.println(“Hello World of Java”); } }
Program Processing for Output Compilation # javac HelloWorld.java outputs in HelloWorld.class Execution # java HelloWorld Hello World of Java #
Simple Java Applet Example // HelloApplet.java: A sample applet import java.applet.*; public class HelloApplet extends Applet { public void paint(Graphics g) { g.drawString(“Hello Applet !”,250,250); } } Prints Hello Applet ! In Applet window At (250,250) (x,y) coordinate
Execution of an Applet by HTML <HTML> <TITLE> Hello Applet </TITLE> <APPLET code=“HelloApplet.class” width=500 height=500 align=“right ”> </APPLET> </HTML>
Mechanism of Applets Hello Applet HelloApplet Java <app= “HelloApplet ”> 4 APPLET Development “HelloApplet.java” At terminal The Web HelloApplet .class AT WEB SERVER 2 31 5 Create Applet tag in HTML document Accessing from Client The browser creates a new window and a new thread and then runs the code
Sequence Diagram : Classic Web Perspective
Sequence Diagram : Java Web Interaction
Significance of downloading Applets Interaction with World wide web w3 consortium. Dynamic animated web page instead of static web pages. Applets react to users interactive application. Could not connect network activity. Do not create dynamic link library files in cookies.
Used Java Main Packages java.lang (by default added) java.util java.io java.awt java.awt.image java.applet java.net java.sql
Thank You Give Feedback

Java Basic PART I

  • 1.
    Java Basic PARTI Soumen Santra MCA, M.Tech, SCJP, MCP
  • 2.
    Java Write Once, RunAnywhere IN ANY PLATFORMONE SOURCE CODE
  • 3.
    Java : Components Editor:Write the source code. Linker: Link the Source code with the library files. Java Compiler – Keyword javac use as convert Java source code to bytecode. Bytecode - An intermediate form, known as native code, closer to machine code. JVM-Java Virtual Machine , a concept of target platform which interprets the bytecode. Interpreter-The interpreter demonstrates the platform independent .class file to equivalent machine dependent code to run. Keyword java. Javadoc-API Documentation generator. JRE- Java Runtime Environment.
  • 4.
    Java : Features JVMuses bytecodes as .class file. Light-weight Small binary class files for fast execution. Just-in-time (JIT) Compilers for compiling only changes code. Multithreading for high process and memory management. Native Methods Interfaces as JNDI. Native Methods Libraries.
  • 5.
    Java : Features(Cont..) Class Loader. Dynamic. Good communication constructs. Secure. Portable and Compatible. Understandable and easy-to-write. Fully Object Oriented. Support Console based, Windows based and Web based application. Case-sensitive. JRE. Jdk (Java Development toolkit).
  • 6.
    General Language Features C/C++like syntax, ends with ; No pointers concept. Objects taken all controls. Objects communicates with objects through messages. Messages result in invocation of class methods.
  • 7.
    Java : Security Languagedesigned as safe. Strict compiler javac & JIT. Dynamic Runtime Loading (Verifier). Runtime Security Manager. Jar- Create & manage all the java archive files. Method area. Heap. JVM language stacks. Pc registers. Native method stacks. Java kernel.
  • 8.
    Security Manager Prevents unauthorizeddisk read/writes. Restricts network access without creating dynamic link library files. Restricts Other access (native methods). Implementation is browser or processor dependent.
  • 9.
    Object Oriented LanguagesComparison with java C++ Objective C Ada Java Encapsulation Yes Yes Yes Yes Inheritance Yes Yes No Yes Multiple Inheritance Yes Yes No No Polymorphism Yes Yes Yes Yes Binding (Early/Late) Both Both Early Both Concurrency Poor Poor Difficult Yes Garbage Collection No Yes No Yes Genericity Yes No Yes No Class Libraries Yes Yes Limited Yes FEATURES
  • 10.
    Features Removed FromC++ Operator overloading. Pointers of Array/pointers. Multiple-inheritance of implementation through class inherit concept. Enum, typedef, #define. Copy constructors, destructors. Templates. And many more....
  • 11.
    Added or Improvedover C++ Interfaces over class. Garbage collection. Exceptions (More featureful than C++). Strings and many implementation. Instanceof. Package. Multi-threads.
  • 12.
    Java better thanC++ No Typedefs, Defines, or Preprocessor. No Global Variables. No goto statement. No Pointers. No Unsafe Structures. No Multiple Inheritance. No Operator Overloading. No Automatic Coercions. No Fragile Data Types. No copy constructor.
  • 13.
    Basic Data Types DataTypes boolean either true of false char 16 bit Unicode 1.1 byte 8-bit integer (signed) short 16-bit integer (signed) int 32-bit integer (signed) long 64-bit integer (signed) float 32-bit floating point double 64-bit floating point String (class for manipulating strings) String, StringBuilder, StringBuffer, StringTokenizer  Java uses Unicode to represent characters internally.
  • 14.
    Java Integrates Power ofCompiled Languages and Flexibility of Interpreted Languages  Applet.  Swing & Layout Manager.  Hibernate.  Struts.  Spring  Servlet  Java Server Pages (JSP)  Java Bean.  Enterprise Java Bean (EJB).  J2ME.  Junit.  & Many More.
  • 15.
    Power of Javaand the Web Deliver .exe, not just .class. Remove porting. Remove end-user installation. Remove software distribution costs. Access by millions of customers through web.
  • 16.
    Applications : Types Differentpossibilities to write/run a Java codes are: Application- A stand-alone program that can be invoked from command line through console which has a “main” method. Applet- A program embedded in a web page , to be run when the page is browsed . A program that contains no “main” method. Application -Java interpreter Applets- Java enabled web browser (Linked to HTML via <APPLET> tag. in html file or run through Appletviewer).
  • 17.
    Java Bytecodes move locally or through network Java Source code (.java) Java Compiler Java Bytecode (.class) Java Interpreter Just in Time Compiler Runtime System Class Loader Bytecode Verifier Java Class Libraries Operating System Hardware Java Virtual machine Runtime Environment Compile-time Environment Life Cycle of Java Code
  • 18.
  • 19.
    Java Development Kit javac– Name of the Java Compiler. java - Name of the Java Interpreter. jdb- Name of the Java Debugger. appletviewer - Name of the Tool to run the applets code and give Applet window. javap – Use to print the Java bytecodes. javaprof - Name of the Java profiler. javadoc - Name of the documentation generator. javah - Name of the creates C header files. Javak= Name of the Kernel of the java.
  • 20.
    Bytecode Verifier It Calledwhen the class is first loaded in runtime environment by JRE. It Verifies the bytecodes meet certain set of properties. Verified code runs faster through JRE. After verification, interpreter defines memory layout. Release all memories through Garbage collector.
  • 21.
    Java Example :Hello World // HelloWorld.java: Hello World program class HelloWorld { public static void main(String args[]) { System.out.println(“Hello World of Java”); } }
  • 22.
    Program Processing forOutput Compilation # javac HelloWorld.java outputs in HelloWorld.class Execution # java HelloWorld Hello World of Java #
  • 23.
    Simple Java AppletExample // HelloApplet.java: A sample applet import java.applet.*; public class HelloApplet extends Applet { public void paint(Graphics g) { g.drawString(“Hello Applet !”,250,250); } } Prints Hello Applet ! In Applet window At (250,250) (x,y) coordinate
  • 24.
    Execution of anApplet by HTML <HTML> <TITLE> Hello Applet </TITLE> <APPLET code=“HelloApplet.class” width=500 height=500 align=“right ”> </APPLET> </HTML>
  • 25.
    Mechanism of Applets HelloApplet HelloApplet Java <app= “HelloApplet ”> 4 APPLET Development “HelloApplet.java” At terminal The Web HelloApplet .class AT WEB SERVER 2 31 5 Create Applet tag in HTML document Accessing from Client The browser creates a new window and a new thread and then runs the code
  • 26.
    Sequence Diagram :Classic Web Perspective
  • 27.
    Sequence Diagram :Java Web Interaction
  • 28.
    Significance of downloadingApplets Interaction with World wide web w3 consortium. Dynamic animated web page instead of static web pages. Applets react to users interactive application. Could not connect network activity. Do not create dynamic link library files in cookies.
  • 29.
    Used Java MainPackages java.lang (by default added) java.util java.io java.awt java.awt.image java.applet java.net java.sql
  • 30.