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 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.
7. 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.
8.
9.
10.
11.
12. 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.
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 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.
20. 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
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 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.
25. 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.