Vous êtes sur la page 1sur 11

JDK (Java Development Kit) Java Developer Kit contains tools needed to develop the Java programs, and

JRE to run the programs. The tools include compiler (javac.exe), Java application launcher (java.exe), Appletviewer, etc Compiler converts java code into byte code. Java application launcher opens a JRE, loads the class, and invokes its main method. You need JDK, if at all you want to write your own programs, and to compile the m. For running java programs, JRE is sufficient. JRE is targeted for execution of Java files i.e. JRE = JVM + Java Packages Classes(like util, math, lang, awt,swing etc)+runtime libraries. JDK is mainly targeted for java development. I.e. You can create a Java file (with the help of Java packages), compile a Java file and run a java file JRE (Java Runtime Environment) Java Runtime Environment contains JVM, class libraries, and other supporting files. It does not contain any development tools such as compiler, debugger, etc. Actually JVM runs the program, and it uses the class libraries, and other supporting files provided in JRE. If you want to run any java program, you need to have JRE installed in the system The Java Virtual Machine provides a platformindependent way of executing code; programmers can

concentrate on writing software, without having to be concerned with how or where it will run. If u just want to run applets (ex: Online Yahoo games or puzzles), JRE needs to be installed on the machine. JVM (Java Virtual Machine) As we all aware when we compile a Java file, output is not an 'exe' but it's a '.class' file. '.class' file consists of Java byte codes which are understandable by JVM. Java Virtual Machine interprets the byte code into the machine code depending upon the underlying operating system and hardware combination. It is responsible for all the things like garbage collection, array bounds checking, etc JVM is platform dependent. The JVM is called "virtual" because it provides a machine interface that does not depend on the underlying operating system and machine hardware architecture. This independence from hardware and operating system is a cornerstone of the write-once run-anywhere value of Java programs. There are different JVM implementations are there. These may differ in things like performance, reliability, speed, etc. These implementations will differ in those areas where Java specification doesnt mention how to implement the features, like how the garbage collection process works is JVM dependent, Java spec doesnt define any specific way to do this. JIT Compiler In order to speed up the execution time of a Java program, a just-in-time (JIT) compiler exists that translates the byte codes into native machine code on-the-fly. Rather than compiling method-by-method the SAP JVM runs the program immediately

using an interpreter. It analyzes the code as it runs to detect the critical hot spots in the program. Then the SAP JVM focuses the attention of a global native-code compiler and optimizer on these hot spots. By avoiding compilation of infrequently executed code (most of the program), the compiler can devote much more attention to the performance-critical parts of the program, without necessarily increasing the overall compilation time. This hotspot monitoring is continued dynamically as the program runs, so that it literally adapts its performance on-thefly to the needs of the user. The JIT compiler does not only provide functionality to compile byte codes into native code blobs, it also contains techniques for switching back from compiled code to the interpreter. This deoptimization allows the compiler to perform aggressive optimizations that speed up the normal execution, but may lead to situations where the optimization was too optimistic and must therefore be undone. It is also a prerequisite for providing the debugging-on-demand functionality. Suns HotSpot VM comes with two flavors of JIT compilers. The client compiler is tuned for the performance profile of typical client applications, whereas the server compiler focuses on the performance profile of typical server applications. The SAP JVM is built and optimized for server environments and therefore does not support the client compiler. Garbage Collection A major attraction of the Java programming is that it provides a built-in automatic memory management, or garbage collection. In traditional languages, dynamic memory allocation is done using an explicit allocate/free model. By contract, a garbage collector automatically handles freeing of unused object memory behind the scenes by only reclaiming an object when it can prove that the object is no longer accessible to the running program. The Sun HotSpot VM comes with several garbage collector algorithms suitable for distinct use cases. For example, there are algorithms optimized for high-throughput or

low-pause times. The SAP JVM supports a subset of these algorithms, which are suitable for application server scenarios.

Introduction to classes Class can be defined in 2 ways 1.analytical manner 2.programming manner 1.analytical manner : A group of members of diff kind can be called as class Or A set or category of things having some property or attribute in common and differentiated from others by kind, type, or quality. Class A class is the definition of a type. It is the blueprint used to construct objects of that type. 2.programming manner Java classes contain fields and methods. A field is like a C++ data member, and a method is like a C++ member function. Each field and method has an access level:

private: accessible only in this class (package): accessible only in this package protected: accessible only in this package and in all subclasses of this class

public: accessible everywhere this class is available Private members Private members are members of a class that cannot be accessed by any class other than the class in which it is declared. public members When a method or variable member is declared public, it means all other classes, regardless of the package that they belong to, can access the member (assuming the class itself is visible).

Similarly, each class has one of two possible access levels:

(package): class objects can only be declared and manipulated by code in this package public: class objects can be declared and manipulated by code in any package

Note: for both fields and classes, package access is the default, and is used when no access is specified. Types of classes

Static A class can be declared static, indicating that it contains only static members. It is not possible to create instances of a static class using the new keyword. Static classes are loaded automatically by the .NET Framework common language runtime (CLR) when the program or namespace containing the class is loaded.

Use a static class to contain methods that are not associated with a particular object. For example, it is a common requirement to create a set of methods that do not act on instance data and are not associated to a specific object in your code. You could use a static class to hold those methods. The main features of a static class are:

They only contain static members. They cannot be instantiated. They are sealed. They cannot contain Instance Constructors (C# Programming Guide).

Creating a static class is therefore much the same as creating a class that contains only static members and a private constructor. A private constructor prevents the class from being instantiated. The advantage of using a static class is that the compiler can check to make sure that no instance members are accidentally added. The compiler will guarantee that instances of this class cannot be created. An anonymous class An anonymous class is a local class without a name. An anonymous class is defined and instantiated in a single succinct expression using the newoperator. While a local class definition is a statement in a block of Java code, an anonymous class definition is an expression, which means that it can be included as part of a larger expression, such as a method call. When a local class is used only once, consider using anonymous class syntax, which places the definition and use of the class in exactly the same place.

A final class A final class cannot be extended. This is done for reasons of security and efficiency. Accordingly, many of the Java standard library classes are final, for example java.lang.System andjava.lang.String. All methods in a final class are implicitly final. Example: public final class MyFinalClass {...} Restricted subclasses are often referred to as "soft final" classes.[1]

Abstract class is a class that can not be instantiated, it exists extensively for inheritance and it must be inherited. There are scenarios in which it is useful to define classes that is not intended to instantiate; because such classes normally are used as baseclasses in inheritance hierarchies, we call such classes abstract classes. Abstract classes cannot be used to instantiate objects; because abstract classes are incomplete, it may contain only definition of the properties or methods and derived classes that inherit this implements it's properties or methods. Static, Value Types & interface doesn't support abstract modifiers. Static members cannot be abstract. Classes

with abstract member must also be abstract.

Wrapper Classes Wrapper class is a wrapper around a primitive data type. It represents primitive data types in their corresponding class instances e.g. a boolean data type can be represented as a Boolean class instance. All of the primitive wrapper classes in Java are immutable i.e. once assigned a value to a wrapper class instance cannot be changed further. Wrapper Classes are used broadly with Collection classes in the java.util package and with the classes in the java.lang.reflect reflection package. Following table lists the primitive types and the corresponding wrapper classes: Primitive boolean byte char double float int long short void Wrapper java.lang.Boolean java.lang.Byte java.lang.Character java.lang.Double java.lang.Float java.lang.Integer java.lang.Long java.lang.Short java.lang.Void

In Java 5.0 version, additional wrapper classes were introduced in the java.util.concurrent.atomicpackage. They

provide atomic operations for assignment, addition and increment. These classes act like variables and cannot be used as a substitute for the regular wrapper classes. Few of these new wrapper classes like AtomicInteger and AtomicLong are the subclasses of the Number Classes. Primitive Wrapper boolean int long V AtomicBoolean AtomicInteger AtomicLong AtomicReference<V>

Features Of the Wrapper Classes Some of the sound features maintained by the Wrapper Classes are as under :

All the methods of the wrapper classes are static. The Wrapper class does not contain constructors. Once a value is assigned to a wrapper class instance it can not be changed, anymore.

Wrapper Classes : Methods with examples There are some of the methods of the Wrapper class which are used to manipulate the data. Few of them are given below: 1. add(int, Object): Learn to insert an element at the specified position. 2. add(Object): Learn to insert an object at the end of a list.

3. addAll(ArrayList): Learn to insert an array list of objects to another list. 4. get(): Learn to retrieve the elements contained with in an ArrayList object. 5. Integer.toBinaryString(): Learn to convert the Integer type object to a String object. 6. size(): Learn to get the dynamic capacity of a list. 7. remove(): Learn to remove an element from a particular position specified by a index value. 8. set(int, Object): Learn to replace an element at the position specified by a index value. Overloaded methods Methods are overloaded when there are multiple methods in the same class with the same names but with different parameter lists. Overridden methods Methods in the parent and subclasses with the samename, parameter list, and return type are overridden. Constructor A method-like block of code that is called when the object is created (instantiated) Typically, constructors initialize data members and acquire whatever resources the object may require. It is the code that runs before the object can be referenced Interface An interface defines a group of methods, or a public interface, that must be implemented by any class that implements the interface. An interface

allows an object to be treated as a type declared by the interface implemented. Method A section of source code that performs a specific function, has a name, may be passed parameters, and may return a result. Methods are found only within classes. static methods The static keyword declares a method that belongs to an entire class (as opposed to belonging to an instance). A class method may be accessed directly from a class, without instantiating the class first. final method The final keyword applied to a method prevents the method from being overridden by a subclass.