Survey
* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
Introduction to JVM A Java virtual machine (JVM) is an abstract computing machine. It provides runtime environment to execute java byte code. There are three notions of the JVM: specification, implementation, and instance. An instance of the JVM can execute any executable computer program compiled into Java byte code. It is the code execution component of the Java platform Figure below shows a block diagram of the Java virtual machine that includes the major subsystems and memory areas described in the specification. As mentioned in previous chapters, each Java virtual machine has a class loader subsystem: a mechanism for loading types (classes and interfaces) given fully qualified names. Each Java virtual machine also has an execution engine: a mechanism responsible for executing the instructions contained in the methods of loaded classes. Figure-2.1. The internal architecture of the Java virtual machine. When a Java virtual machine runs a program, it needs memory to store many things, including byte codes and other information it extracts from loaded class files, objects the program instantiates, parameters to methods, return values, local variables, and intermediate results of computations. The Java virtual machine organizes the memory it needs to execute a program into several runtime data areas. Although the same runtime data areas exist in some form in every Java virtual machine implementation, their specification is quite Java Classes Java is an Object-Oriented Language. As a language that has the Object Oriented feature, Java supports the following fundamental concepts: Polymorphism Inheritance Encapsulation Abstraction Object - Objects have states and behaviors. Example: A dog has states - color, name, breed as well as behaviors -wagging, barking, eating. An object is an instance of a class. Class - A class can be defined as a template/blue print that describes the behaviors/states that object of its type support Signals in JAVA The types of signals are Exceptions, Errors, Interrupts, and Controls. Exceptions The operating system synchronously raises an appropriate exception signal whenever a fatal condition occurs. Errors The JVM raises a SIGABRT if it detects a condition from which it cannot recover. Interrupts Interrupt signals are raised asynchronously, from outside a JVM process, to request shutdown. Controls Other signals that are used by the JVM for control purposes. Java function A Java method is a collection of statements that are grouped together to perform an operation. When you call the System.out.println method, for example, the system actually executes several statements in order to display a message on the console. Creating Method Considering the following example to explain the syntax of a method: public static int funcName(int a, int b) { // body } Here, public static : modifier. int: return type funcName: function name a, b: formal parameters int a, int b: list of parameters Methods are also known as Procedures or Functions: Procedures: They don't return any value. Functions: They return value The Constructors: A constructor initializes an object when it is created. It has the same name as its class and is syntactically similar to a method. However, constructors have no explicit return type. Example: Here is a simple example that uses a constructor: // A simple constructor. class MyClass { int x; // Following is the constructor MyClass() { x = 10; } } You would call constructor to initialize objects as follows: public class ConsDemo { public static void main(String args[]) { MyClass t1 = new MyClass(); MyClass t2 = new MyClass(); System.out.println(t1.x + " " + t2.x); } } The finalize ( ) Method: It is possible to define a method that will be called just before an object's final destruction by the garbage collector. This method is called finalize( ), and it can be used to ensure that an object terminates cleanly. For example, you might use finalize ( ) to make sure that an open file owned by that object is closed. To add a finalize to a class, you simply define the finalize( ) method. The Java runtime calls that method whenever it is about to recycle an object of that class. Inside the finalize( ) method, you will specify those actions that must be performed before an object is destroyed. The finalize( ) method has this general form: protected void finalize( ) { // finalization code here } Here, the keyword protected is a specifier that prevents access to finalize( ) by code defined outside its class.