You are on page 1of 1

Features in Java: Java is a Platform, Simple,Object Oriented, Platform Independent, Safe,High peformance, Multi-Threaded, Dynamic/ Java is a platform for

application development. Java solves the problem of platform independence by using byte code. The java compiler does not produce native executable code for a particular machine like a C compiler would. Instead it produces a special formate called byte code. Java byte code written in hexadecimal. This looks a lot like machine language, but unlike machine language Java programs that have been compiled into byte code still need an interpreter to execute then on any given platform. The interpreter reads the byte code and translates it into the native language of the host machine on the fly.Simple: Java was designed to make it much easier to write bug free code. According to Suns Bill Joy, Shipping C code has, on average, one bug per 55 lines of code. Java code is bug free code. Code is keeping the language simple. Java has the bare bones functionality needed to implement its rich feature set. It does not add lots of syntactic sugar or necessary features. Despite its simplicity Java has considerably more functionality than C, primarly because of the large class library. About half of the bugs in C and C++ programs are related memory allocation and deallocation. Therefore the second important addition that java makes to provide bug free code is memory allocation and deallocation. Object Oriented: Object oriented programming is the catch phrase of computer programing Object oriented programs, objects represent data. Object have two sections fields and methods Fields tell what and object is Methods tell what an object does. OOP is alleged to have a number of advantages Simpler, More efficient reuse of code. Faster time to market. More robust, error free code, Platform Independent: Java was designed not only to be cross platform in source from like C, but also in compiled binary form. Since this is frankly imposible across processor architechtures. Java is compiled to an intermediate form called byte code. A java program never really executes natively on the host machine. Rather a special native program called java interpreter reads the byte code and executes the corresponding native machine instructions. The second important part of making java cross platform is the eliminatio of undefined or architecture dependent constructs. Iteger are always four bytes long and floating point variables follow the IEEE 754 standard for computer arithematic exactly. Safe:java was designed from the ground up to allow for secure execution of code across a network, even when the source of that code was untrusted and possibly malicious. Java programs cannot access arbitary addresses in memory. Java implements a robust exception handling mechanism to deal with both expected and unexpected errors. The worst that an applet can do to host system is bring down the runtime environment. However the biggest security problem is not hackers. Its not viruses. Its not even insiders erasing their hard drives and quitting the company to go to and work for the competitor. The biggest security issue in computing today is bugs. Regular, ordinary, nonmalicious unintended bugs are responsible for more data loss and lost productivity.High Peformance: java byte codes can be compiled on the fly to code that rivals C++ in speed using a Just in time compiler Several companies are also working on native machine architecture compilers for java. These will produce executable code that does not require a seperate interpreter, and that is indistinguishable in speed from C++. Multi Threaded: Java is inherently multithreaded. A single java program can have many different threads executing independently and continuously. Three java applets on the same page can run togethe with each getting equal time from the CPU with very little extra effort on the part of the programmer.Dynamic: Java does not have an explicit link phase. Java source code is divided into .java files, roughly one per each class in the program. The compiler compiles these into .class files containing byte code. Each .java file generally produces exactly one .class file. The compiler searches the current directory specified in the classpath environment variable to find other classes explicitly referenced by name in each source code file. If the file that is complied depends on other, non-compiled files the compiler will try to find them and compile them as well. The compiler is quite smart and can handle circular dependencies as well as methods that are used before theyre declared. It also can determine whether a source code file has changed since the last time it was compiled Garbage Collected: There is no need to explicitly allocate or deallocate memory in Java. Memory is allocated as needed, both on the stack and the heap, and reclaimed by the garbage collector when it is no longer needed. Theres no malloc(), free( ), or destructor methods.Most java vitrual machines use an inefficient, mark and sweep garbage collector.Data Types in Java: There are eight primitive data types in java. However there are only seven literals 1.Boolean,2.Byte,3. Short 4. Int,5. Long 6. Float, 7. Double 8. Char. 1. True or False 2) 89,-945,37868 3) 89L,845L,5123567876L, 4)89.5f,-32.5f, 5)89.5,-32.5,87.6E45, 6) c,9,t 7) This is a string literal There are no short or byte literals.1. Boolean: 1 bit may take the value, true or false it is defined as 1s and 0s. 2. Byte: 1 signed byte (twos complement) ranges values 128to 127. 3. Short: 2 bytes signed 2 complement ranges from 32,768 to 32767, 3. Int: 4 bytes signed 2s 2,147,483,648 to 2,147,486,647 like all numeric types. 5. Long: 8 bytes signed 2s complement 9,223,372,036,854,775,808 to +9,223,372,036,854,775,807 6) Float: 4 bytes IEEE 754, covers a range from 1.40129846432481707e-45 to 3.40282346638528860e+38 7)Double: 8 bytes IEEE 754 covers a range from 4.94065645841246544-324d to 1.79769313486231570e+308d 8) Char: 2 bytes, unsigned , Unicode, 0to 65,35 Chars are not the same as bytes,ints,shorts or strings.Unicode: Java uses the unicode character set. Unicode is a two byte character code set that has characters representing almost all characters in almost all human alphabets and writing systems around the world including English, Arabic, Chinese and more. \u00AE it represents copy rights symbol. But frackly this is way more trouble than its worth. Switch Case: switch9x){ case0: dosomthing0(); break; case1 dosomthing1); break; case2 dosomthing2); break; case3 dosomthing3(); break; case4: dosomthing4(); break; default: do something Else();}Life Cycle of an Object: An object is a software module that has state and behavior. An objects state is contained in its member variables and its behavior is implemented through its method. Java programs that we write will create many objects from prototypes known as classes. These objects interact wit one another by sending each other messages. The result of message is a method invocation which performs some action or modifies the state of the receiving object. These object interactions, the java program can implement a GUI, run an animation, or send and receive information over the network. Once an object has completed the work for which is was created, its is garbage collected and its resourses recycled for the use of other objects. Creating Object: In java we create an object by creating and instance of a class. Date today = new Date( ); This statement creates a new date object. This single statement actually performs three actions; declaration, instantiation and initialisation. Date today is a variable declaration which simply declares to the compiler that the name today will be used to refer to an object whose type is date. The new operator instantiates the date class and date initializes the object. Declaring an Object:While the declaration of an object is not a necessary part of object creation, object declarations often appear on the same line as the creation of an object. Either way, declaring a variable to hold an object is just like declaring a variable to hold a value of primitive data.Instantiating Object:The new operator instantiates a class by allocating memory for a new object of that type new requires a single argument. The new operator creates the object, the constructor initializes it. Initializing Object: As mentioned previously, classes provided constructor methods to initialize a new object of that type. A class may provide multiple constructors to perform different kinds of initialization on new objects. When looking at the implementation for a class you can recognize the constructors because they have the same name as the class and have no return type. The compiler can differentiate the constructors through the type and number of the arguments Using Object:Once we have created an object, we will probably want to use it for something. Suppose for example, that after creating a new rectangle object you would like to move it to a different location. Say the rectangle is an object in a drawing program and the user just clicked the mouse over the rectangle and dragged it to a new location.Referencing an objects Variable: First lets focus on how to inspect and modify the rectangles position by modifying its x and y variables directly. Now we will see to move the rectangle by calling its move method. To access and objects variable, simply append the variable name to an object reference with an intervening. Calling an Object Method: This method is similar to objects variable. To call objects method, simply append the method name to an object reference with an interveing -, and provide any arguments to the method with in enclosing parentheses. If the method does not require any arguments, just use empty parentheses. Cleaning Up Unused Object: Many other OO Languages require that you keep track of all the objects you create and that you destroy them when are no longer needed. Writing code to manage memory in this way is tedious and often error pone. Java saves you from this by allowing you to create as many objects as you want but never having to destroy them. The Java runtime environment deletes objects when it determnes that they are no longer being used. This process known as garbage collection. Garbage Collector: The GC runs in a low priority thread and runs both synchronously and asynchronously depending on the situation and the system on which is java is running. A comacting, mark-sweep collector with some conservative scanning. Finalization: Before an object gets garbage collected, the GC gives the object an opportunity to cleanup after itself though a call to the objects finalize method. This process is known as finalization. During finalization an object may wish to free system resourses such as files and sockets or drop references to other objects so that they in turn become eligible for garbage collection.

You might also like