Intro to Java
The Java Language
- Java is a programming language that evolved from C++
- Both are object-oriented
- They both have much of the same syntax
- Began in the early 90's, originally used for programming in
intelligent consumer-electronic devices (internal chips, etc).
- Was originally named Oak by its creator, but changed when it was
reliazed that there was already a language called Oak
- When the Web took off in the early 90s, Java gained popularity for use
in adding dynamic content to web pages
- While applets surely helped Java gain quick popularity, they are by
no means the most important use of the language
- Java is now used for a wide variety of purposes, and its large and
rich set of pre-built packages makes it a very popular choice of software
developers
- Latest version is Java SE 22 -- Java Standard Edition 22 (Released March 2024). Java SE 23 expected in September 2024.
- A long-running and still commonly-used version is Java SE 8
- Java SE 11 is another popular edition receiving consistent support
- Since Java 9 was released, Oracle has been on a 6-month update cycle
with each new version number. Many version updates are minor, in terms of what is needed for this course. However, there have been some new language features introduced since then, along with some other valuable library updates that may become relevant in this course.
Java vs. C++
Compiling and Running
- C++ code must be fully compiled into machine language
- resulting executable is machine-specific
- can be portable when using non-machine specific libraries, but
requires compiling on each platform
- faster run time for executables
- Java code is compiled partway, but not to machine language
- Java code compiled to an intermediate level -- bytecode
- bytecode runs on an interpreter -- the Java Virtual
Machine
- Each platform needs its own JVM, but the same bytecode (generally
speaking) runs on any JVM on any platform (i.e. the compiled version
is portable)
- Typically Slower runtime than C++, since running on an interpreter
(and due to other factors)
Some benefits of Java (over C++) -- IMHO
- Vast collection of packages available in the Standard Development Kit (SDK)
- Easy-to-use API descriptions in HTML format on the Sun web site
- Standard format for building API descriptions for classes
- Easier to build programs with graphic interfaces (GUI)
- latest packages for GUI (Swing classes) not platform specific
- compiled bytecode runs on multiple platforms
- In C++, one would commonly have to use the GUI libraries for each
different platform
- Some syntax made easier to use. For example...
- no pointer notation
- all objects and arrays created dynamically (with new)
- no need for delete (automatic garbage collection)
- Java Runtime Environment (JRE) does some things for you
- Automatic garbage collection (for dynamically allocated objects)
- more dynamic run-time checking
- automatic dynamic binding and polymorphic behavior
Some benefits of C++ (over Java) -- IMHO
- Programmer has more control and power in C++
- In C++, programmer responsible for the details
- Control over addresses with pointers
- More control over efficient execution time and resource
allocation/deallocation
- C++ programs will typically run faster, because
- compiled to machine's native instruction set
- dynamic allocation doesn't have to be used for all objects
- programmer has more power to optimize what they want
- C++ still has some extra versatile features (that Java doesn't), like
operator overloading and multiple inheritance
Some Important Java Tools
- javac - java compiler
- java - java interpreter
- jar - the java archive utility
- javadoc - utility for auto-generating Java documentation API
pages
- JSP - Java Server Pages
- JRE - Java Runtime Environment
- J2SDK - Java 2 Standard Development Kit (sometimes JDK, Java
Development Kit, for short) -- includes JRE