Java is designed for the web
Compiled byte code is very compact. Complete graphical applications can be a few tens of kilobytes, not megabytes. This makes it possible to download whole programs ("applets") which were part of the original objective of Java but not used so much now.
Other key factors make Java important for the web:
- Built-in security
- Built-in networking capabilities
- Server-based capabilities (servlets, EJB, etc)
Java is descended from C and C++
- Statement syntax very similar, including such idioms as
x++
and a += b
- Java was designed to overcome difficulties in those languages
- Deliberately simpler than C++ to make testing and maintenance easier
- Platform-independent base data types
- Security => no direct memory addressing - no pointers!
- Strict type checking and validation of byte codes
- But adds powerful new features, such as multiprocessing (threads)
If you have previously used C or C++ prepare to be a little confused until you get used to the differences.
In particular:
- no direct memory addressing
- limited class inheritance
- no operator overloading
- no macros
- no header files
- you cannot delete objects when you have finished with them - automatic "garbage collection" is done by the JVM instead, which is good news because the potential for "memory leaks", the bane of C++, is very much less
Java is designed for bug avoidance
For example:
- Java is strongly typed - type conversions are checked during execution
- Array indexes are always checked against bounds
- Memory address calculations are impossible