Slideshare uses cookies to improve functionality and performance, and to provide you with relevant advertising. If you continue browsing the site, you agree to the use of cookies on this website. See our User Agreement and Privacy Policy.

Slideshare uses cookies to improve functionality and performance, and to provide you with relevant advertising. If you continue browsing the site, you agree to the use of cookies on this website. See our Privacy Policy and User Agreement for details.

3.
Java architecture When you write and run a Java program, you are tapping the power of these four technologies. You express the program in source files written in the Java programming language, compile the source to Java class files, and run the class files on a Java virtual machine. Java API is actually a huge collection of library routines that performs basic programming tasks. The combination of the Java virtual machine and Java API is called the Java Platform See the figure below...

6.
Java architecture Java Virtual Machine(JVM) The Method area The method area is where the bytecodes reside. The program counter always points to (contains the address of) some byte in the method area. The program counter is used to keep track of the thread of execution. After a bytecode instruction has been executed, the program counter will contain the address of the next instruction to execute. After execution of an instruction, the JVM sets the program counter to the address of the instruction that immediately follows the previous one, unless the previous one specifically demanded a jump.

7.
Java architecture Java Virtual Machine(JVM) The Java stack The Java stack is used to store the results of the bytecode instructions, to pass parameters to and return values from methods as well as to keep the state of each method invocation. The state of each method is called its Stack frame. For example, if we have method that calls other m If our program is calling the A method, the A method will automatically call B, C and D, because of its state. Stack frame of A

8.
- The JVM's heap stores all objects instantiated by an executing Java program. Objects are created by Java's &quot;new&quot; operator, and memory for new objects is allocated on the heap at run time. Garbage collection What is the Java heap memory? - Garbage collection is the process of automatically freeing objects that are no longer referenced by the program. This frees the programmer from having to keep track of when to free allocated memory, thereby preventing many potential bugs and headaches. Java architecture Java Virtual Machine(JVM)

9.
Java references and parameters passing Java, unlike C++, stores all objects on the heap, and requires the new operator to create the object. Variables are still stored on the stack, but they hold a pointer to the object, not the object itself (and of course, to confuse C++ programmers more, these pointers are called &quot;references&quot;).

10.
Java references and parameters passing In C++, objects may be created on the stack using &quot;automatic&quot; allocation. The following is legal C++: Integer foo = Integer(1); it creates a new Integer object on the stack. A Java compiler, however, will reject it as a syntax error, because we haven’t allocated heap memory by ‘new’ operator.

15.
Some Java Basics ‘ final’ keyword A final class cannot be extended. This is done for reasons of security and efficiency and all methods in a final class are implicitly final. Many of the Java standard library classes are final , for example java.lang.System and java.lang.String . A final method cannot be overridden by subclasses. This is used to prevent unexpected behavior from a subclass altering a method that may be crucial to the function or consistency of the class. A final variable can only be initialized once, either via an initializer or an assignment statement. It need not be initialized at the point of definition: this is called a 'blank final' variable.

16.
Some Java Basics The three forms of Polymorphism Instance methods and overriding An instance method in a subclass with the same signature (name, plus the number and the type of its parameters) and return type as an instance method in the superclass overrides the superclass's method. Overloading Overloaded methods are methods with the same name signature but either a different number of parameters or different types in the parameter list. Dynamic (or late) method binding Dynamic (or late) method binding is the ability of a program to resolve references to subclass methods at runtime .

18.
Some Java Basics Variables Instance Variables (Non-Static Fields) Non-static fields are also known as instance variables because their values are unique to each instance of a class (to each object, in other words). Class Variables (Static Fields) A class variable is any field declared with the static modifier; this tells the compiler that there is exactly one copy of this variable in existence, regardless of how many times the class has been instantiated. Local Variables Similar to how an object stores its state in fields, a method will often store its temporary state in local variables . These are only visible to the methods in which they are declared. Parameters are variables that are passed to the methods.

19.
Some Java Basics Constants The static modifier, in combination with the final modifier, is also used to define constants. The final modifier indicates that the value of this field cannot change. String Class The String class represents character strings. All string literals in Java programs, such as &quot;abc&quot;, are implemented as instances of this class. Since strings are instances of the String class, max size of a String class object could be the available heap memory.