Java is a platform. It consists of:
- a virtual machine capable of running bytecodes
- a compiler which transforms Java code into bytecodes
- a programming language
- a standard library
The virtual machine, the compiler as well as the various components of the standard library have been released as open-source software by Sun (now owned by Oracle) and, consequently, the Java platform is well supported on all computer platforms. Forks of Sun’s original Java include OpenJDK.
Java was designed by James Gosling in 1995 to power embedded devices and, in 2012, Java powers Android smartphones and tablets and Blu-Ray drives for example. Java has also proved to be very successful in enterprises. Applications written in Java and conforming to the Java Enterprise Edition set of specifications are found in most of the large companies.
Setting up the development environment
- Make sure Java is installed
- Install the IntelliJ IDEA Community Edition IDE
- Write a Java program that displays the string of characters “Hello World” on standard output
Like Java, Eclipse is an open-source software (originally done by IBM) and, since then, has become a very important integrated development environment for Java and Android. Other IDEs used to do Java development are Netbeans and Eclipse.
Developing applications
Java is an imperative programming language, supports object-oriented programming and has a C-like syntax. The best way to learn how to program in Java is to develop progressively more complex applications. The work to do is:
- Write a Java program that displays a multiplication table for a specific number on the standard output.
- Write a Java program that calculates and displays the factorial of a specific number using both the recursive and iterative algorithms. When this is done, enhance the iterative version to work with big numbers.
- Write a Java program which uses the algorithm devised by Eratosthene to display all the prime numbers which are less or equal to a specific maximum number.
Input / Output
Computer applications generally read data from input devices (e.g. the keyboard), process the data in some way and display results on output devices (e.g. a screen)
- Write a Java program which reads integers from standard input and print out their sum on standard output. The program should read integers until the string “END” is encountered.
- Write a Java program that prompts the user for a number of seconds (an offset), displays the current date and time and also the date and time after that offset.
In order to write those programs, it is important to understand how Input / Output is done in Java as well as how the platform handles times and dates. The relevant information is found in the Java API Specification.
Leave a Reply