Introduction to Java Programming
A language named after coffee, built so one compiled program could run on any machine with a JVM.
Walk into any postgraduate school's records office and look at the student files. Every folder uses the same printed form: name, matric number, programme, level. But the ink inside is different in every folder. One says Aisha, PGD Computer Science, another says Tunde, PGD Computer Science.
The printed form is one thing and the filled-in folders are many things made from it. That small difference is the most important idea in this whole course. By the end of this chapter you'll be able to write the "form" in Java, fill in as many folders as you like, and explain exactly what happens in memory when you do.
First, a quick refresher from Programming I. Programming means writing instructions, in a logical order, that make a computer solve a problem for you. We write those instructions in a high-level language, and something has to turn them into machine code. There are two ways to do that. An interpreter translates and runs the program one line at a time. A compiler translates the whole program in one go, before it runs.
Java does both, and that is its cleverest trick. The compiler (javac) turns your .java file into bytecode, a .class file written for an imaginary computer. Then the Java Virtual Machine (JVM) on each real computer runs that bytecode. Windows, Linux and macOS each have their own JVM, but they all understand the same bytecode.
javac, then run anywhere there is a JVM. This two-step design is why Java is called platform-independent.Textbooks list Java's main characteristics, and they're worth knowing as a set. Java is simple (it keeps only the features it needs), object-oriented, platform-independent (portable bytecode), robust (strong type checking, automatic garbage collection, no raw pointers to corrupt memory), multithreaded (it can do several things at once), and it comes with a rich library of ready-made classes. Each one of these was a fix for something that went wrong with C and C++ on those early TV boxes.
Spotted a mistake?