Java as an object-oriented programming language has several interesting features. They are listed below.
- Unlike many other programming languages including C and C++ when Java is compiled, it is not compiled into platform specific machine, rather into platform independent byte code.
- This byte code is distributed over the web and interpreted by JVM on whichever platform it is being run.
- Object oriented throughout – no coding outside of class definitions, including main().
- An extensive class library available in the core language packages.
- Code is compiled to bytecodes that are interpreted by Java virtual machines (JVM).
- This provides portability to any machine for which a virtual machine has been written.
- The two steps of compilation and interpretation allow for extensive code checking and improved security.
Exception handling built-in, strong type checking (that is, all data must be declared an explicit type), local variables must be initialized.
Several dangerous features of C and C++ eliminated
- No memory pointers
- No preprocessor
- Array index limit checking
Automatic Memory Management
Automatic garbage collection – memory management handled by JVM.
♦ No memory pointers
♦ Programs run inside the virtual machine sandbox.
♦ Array index limit checking
♦ Code managed by
- bytecode verifier – checks classes after loading
- class loader – confines objects to unique namespaces. Prevents loading a hacked “java.lang.SecurityManager” class, for example.
- security manager – determines what resources a class can access such as reading and writing to the local disk.
- The linking of data and methods to where they are located is done at run-time.
- New classes can be loaded while a program is running. Linking is done on the fly.
- Even if libraries are recompiled, there is no need to recompile code that uses classes in those libraries.
This differs from C++, which uses static binding. This can result in fragile classes for cases where linked code is changed and memory pointers then point to the wrong addresses.
Interpretation of bytecodes slowed performance in early versions, but advanced virtual machines with adaptive and just-in-time compilation and other techniques now typically provide performance up to 50% to 100% the speed of C++ programs.
- Lightweight processes, called threads, can easily be spun off to perform multiprocessing.
- Can take advantage of multiprocessors where available
- Great for multimedia displays.
Java was designed with networking in mind and comes with many classes to develop sophisticated Internet communications.