A Brief Intro to Java for C/C++ Programmers ------------------------------------------- T.A. Gonsalves, IIT Mandi A list of features of Java, for programmers familiar with C. Compared to C++, Java is: * Strictly object-oriented -- all code must be in a Class * Supports only single inheritance, Class Object is the base of the class hierarchy. However, a Java class can also implement one or more interfaces to provide a form of multiple inheritance. An interface is similar to a pure virtual class in C++. Compared to C and C++: * Java source is compiled to machine-independent bytecodes (.class file). The .class files are platform independent. Bytecodes are interpreted by a Java Virtual Machine (JVM) that is platform-specific. * The Java standard includes a very rich set of classes: basic data structures (collections), networking, GUI, database access, multi-threading, thread-safe concurrent data structures, atomic variables, etc. These are guaranteed to be available on all conformant implementations. * Multi-threading is supported by user-level threads in the JVM on platforms that do not provide kernel threads. * Thus, Java is "write once, run anywhere", unlike C/C++ which have to be compiled for each target platform. The standard libraries in C/C++ are relatively small, rich sets of optional libraries are available but these may not be installed on all platforms of interest. * Java is inherently slower than a C/C++ program that is compiled to machine code by an optimising compiler. However, the Hotspot JVM does on-the-fly compilation of frequently used bytecode segments to machine code to achieve nearly C-like performance. * Java provides dynamic memory management via a "garbage collector". The programmer does not have to (indeed, cannot) free an object that is no longer needed. The garbage collector does this automatically. * Java supports dynamic loading of classes into a running program. The loaded classes could be sourced from any machine in the Internet. There are 3 commonly-used Java standards: * Java Standard Edition (Java SE) -- used on most computers * Java Enterprise Edition (Java EE) -- used for building large enterprise-class applications * Java Micro Edition (Java ME) -- used for small mobile platforms [Version 1, 1/4/2015]