Module 1   Getting Started
Objectives •  Describe key features of Java technology.  •  Describe the Java virtual machine’s (JVM) function. •  Describe how garbage collection works.  •  Write, compile, and run a simple Java application.  •  List the task performed by Java platform that handle  code security
Definition •  A high-level programming language  •  O riginally called  OAK . •  In 1995 name  changed  to Java and  also  modified to take advantage of World Wide Web.
How Java works •  A program is both compiled and interpreted.  •  With the compiler, first you translate a program  into an intermediate language called  Java  bytecodes   •  This  platform-independent code is interpreted by the  interpreter   •   The interpreter parses and runs each Java bytecode  •   Compilation happens just once •   Interpretation occurs each time the program is executed.
 
Key Features of Java Programming Language   1. Platform Independence   Java compilers do not produce native object code  for a particular platform but rather ‘byte code’ instructions  for the Java Virtual Machine (JVM). 2. Object Orientation   Java is a pure object-oriented language. This means  that everything in a Java program is an object and  everything is descended from a root object class.
3. Rich Standard Library   The Java environment includes hundreds of classes  and methods in six major functional areas.  1. Language Support    2.  Utility 3. Input/output  4.  Networking 5. Abstract Window Toolkit  6.  Applet 4. Familiar C++ like Syntax 5 .  Garbage Collection  - Java does not require programmers to  explicitly free dynamically allocated memory. This makes  Java programs easier to write and less prone to memory  errors.
6. Multithreaded   Java Support multithreaded programming,which allow you to write programs that do many things simultaneously.
 
 
 
Java Virtual Machine Functionality •  Provides hardware platform specifications •  Reads compiled byte codes that are platform  independent  •  The Java interpreter installed on your computer  implements the Java VM.
Java Platform
Java Development Kit   •  A Java software development environment from Sun.  •  It includes the compiler, JVM, debugger and other  tools for developing Java applets and applications.  •  Each new version of the JDK adds features and  enhancements to the language.  •  When Java programs are developed under the  new version,the Java interpreter (Java Virtual Machine)  that executes them must also be updated to that same  version.
J ava  R untime  E nvironment A subset of the Java Development Kit (JDK),  provides the minimum requirements for executing a Java application .   The JRE includes the Java Virtual Machine (JVM), core classes, and supporting files .
Classpath A way to  tell the JVM, where to find your  source code, as well as any other classes or objects that are required by your application.  The CLASSPATH contains directories (or JAR files),  from where your java compiler/runtime will  look for .class files  Path The PATH variable contains directories where  binary files (e.g. EXE files in Windows) will be  looked for.
 
Consider MyClass myRef = new MyClass(); this creates an object somewhere in the heap, it also creates a  reference variable called 'myRef' that effectively points to the spot  in the heap where the object is. Consider the right side indicates the heap and left side is list of  references,  draw an arrow to show where each ref is pointing to. MyClass ref2 = myRef; We have two things on the left, each with an arrow pointing to  the single object on the right.
Go through the code line by line, drawing and erasing arrows as  Needed, you can then see when an object has no arrows pointing to it,  thus making it eligible for garbage collection.  Ways to call garbage collector algorithms In reality, it is possible only to suggest to the JVM that it perform  garbage collection. However, there are no guarantees the JVM will  actually remove all of the unused objects from memory. The garbage collection routines that Java provides are members of the  Runtime class.  The Runtime class is a special class that has a single object (a Singleton) for each main program.
The Runtime object provides a mechanism for communicating directly with the virtual machine.  To get the Runtime instance, you can use the method Runtime.getRuntime(), which returns the Singleton.  Once you have the Singleton you can invoke the garbage collector  using the gc() method. Alternatively, you can call the same method on the System class,  which has static methods that can do the work of obtaining the  Singleton for you. System.gc(); Example  CheckGC.java
 
 
Class Loader     Loads all classes necessary for the execution of a program.  Bytecode Verifier   Java compilers perform extensive compile-time checking on the source code they compile. However, the  Java Virtual Machine  (JVM) cannot rely on compile-time checking because it has no way of determining whether the class files it interprets were produced by a trustworthy Java compiler or by a malicious user.   
Verifier serves to make sure that class files loaded into the JVM  respect certain security-related properties like •   the class file’s syntax,  •   the behavior of its code and  •   the potential interdependencies that it has with other class files.
Suppose If a buggy compiler generated a class file that contained a  method whose bytecodes included an instruction to jump beyond the  end of the method, that method could, if it were invoked, cause the  virtual machine to crash.  Thus, for the sake of robustness, it is important that the virtual machine  verify the integrity of the bytecodes it imports.

A begineers guide of JAVA - Getting Started

  • 1.
    Module 1 Getting Started
  • 2.
    Objectives • Describe key features of Java technology. • Describe the Java virtual machine’s (JVM) function. • Describe how garbage collection works. • Write, compile, and run a simple Java application. • List the task performed by Java platform that handle code security
  • 3.
    Definition • A high-level programming language • O riginally called OAK . • In 1995 name changed to Java and also modified to take advantage of World Wide Web.
  • 4.
    How Java works• A program is both compiled and interpreted. • With the compiler, first you translate a program into an intermediate language called Java bytecodes • This platform-independent code is interpreted by the interpreter • The interpreter parses and runs each Java bytecode • Compilation happens just once • Interpretation occurs each time the program is executed.
  • 5.
  • 6.
    Key Features ofJava Programming Language 1. Platform Independence Java compilers do not produce native object code for a particular platform but rather ‘byte code’ instructions for the Java Virtual Machine (JVM). 2. Object Orientation Java is a pure object-oriented language. This means that everything in a Java program is an object and everything is descended from a root object class.
  • 7.
    3. Rich StandardLibrary The Java environment includes hundreds of classes and methods in six major functional areas. 1. Language Support 2. Utility 3. Input/output 4. Networking 5. Abstract Window Toolkit 6. Applet 4. Familiar C++ like Syntax 5 . Garbage Collection - Java does not require programmers to explicitly free dynamically allocated memory. This makes Java programs easier to write and less prone to memory errors.
  • 8.
    6. Multithreaded Java Support multithreaded programming,which allow you to write programs that do many things simultaneously.
  • 9.
  • 10.
  • 11.
  • 12.
    Java Virtual MachineFunctionality • Provides hardware platform specifications • Reads compiled byte codes that are platform independent • The Java interpreter installed on your computer implements the Java VM.
  • 13.
  • 14.
    Java Development Kit • A Java software development environment from Sun. • It includes the compiler, JVM, debugger and other tools for developing Java applets and applications. • Each new version of the JDK adds features and enhancements to the language. • When Java programs are developed under the new version,the Java interpreter (Java Virtual Machine) that executes them must also be updated to that same version.
  • 15.
    J ava R untime E nvironment A subset of the Java Development Kit (JDK), provides the minimum requirements for executing a Java application . The JRE includes the Java Virtual Machine (JVM), core classes, and supporting files .
  • 16.
    Classpath A wayto tell the JVM, where to find your source code, as well as any other classes or objects that are required by your application. The CLASSPATH contains directories (or JAR files), from where your java compiler/runtime will look for .class files Path The PATH variable contains directories where binary files (e.g. EXE files in Windows) will be looked for.
  • 17.
  • 18.
    Consider MyClass myRef= new MyClass(); this creates an object somewhere in the heap, it also creates a reference variable called 'myRef' that effectively points to the spot in the heap where the object is. Consider the right side indicates the heap and left side is list of references, draw an arrow to show where each ref is pointing to. MyClass ref2 = myRef; We have two things on the left, each with an arrow pointing to the single object on the right.
  • 19.
    Go through thecode line by line, drawing and erasing arrows as Needed, you can then see when an object has no arrows pointing to it, thus making it eligible for garbage collection. Ways to call garbage collector algorithms In reality, it is possible only to suggest to the JVM that it perform garbage collection. However, there are no guarantees the JVM will actually remove all of the unused objects from memory. The garbage collection routines that Java provides are members of the Runtime class. The Runtime class is a special class that has a single object (a Singleton) for each main program.
  • 20.
    The Runtime objectprovides a mechanism for communicating directly with the virtual machine. To get the Runtime instance, you can use the method Runtime.getRuntime(), which returns the Singleton. Once you have the Singleton you can invoke the garbage collector using the gc() method. Alternatively, you can call the same method on the System class, which has static methods that can do the work of obtaining the Singleton for you. System.gc(); Example CheckGC.java
  • 21.
  • 22.
  • 23.
    Class Loader Loads all classes necessary for the execution of a program. Bytecode Verifier Java compilers perform extensive compile-time checking on the source code they compile. However, the Java Virtual Machine (JVM) cannot rely on compile-time checking because it has no way of determining whether the class files it interprets were produced by a trustworthy Java compiler or by a malicious user.  
  • 24.
    Verifier serves tomake sure that class files loaded into the JVM respect certain security-related properties like • the class file’s syntax, • the behavior of its code and • the potential interdependencies that it has with other class files.
  • 25.
    Suppose If abuggy compiler generated a class file that contained a method whose bytecodes included an instruction to jump beyond the end of the method, that method could, if it were invoked, cause the virtual machine to crash. Thus, for the sake of robustness, it is important that the virtual machine verify the integrity of the bytecodes it imports.