A Very Short Intro to Java

Clément Aubert

October 3, 2020

Installation, Compilation and Execution

You can find at https://spots.augusta.edu/caubert/teaching/general/java/prog.zip a simple java program, made of two files, Demo.java and Rectangle.java. You can also download them in a printable format.

To compile and execute them,

  1. Install Java Development Kit (JDK). Hopefully the instructions at http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html should be clear enough.

  2. Open a terminal and naviguate to the folder where you stored Demo.java and Rectangle.java.

  3. To compile Rectangle.java using java compiler, type

    javac Rectangle.java

    in Linux/Unix-based systems, or (something like)

    "C:\Program Files (x86)\Java\jdk1.8.0_151\bin\javac" Rectangle.java

    in Windows. We will refer to those two commands as simply javac in the following: you can change the path and environment variables in Windows to make it more convenient to execute java compiler. A Rectangle.class file will be created, this program needs to be compiled before Demo.java, since this latter uses the class Rectangle. Once Rectangle is compiled, compile Demo.java, using

    javac Demo.java
  4. To execute Demo.class, type

    java Demo

    You’ll be asked for your name and age. Just enter a string and hit the “enter” key, and then enter an integer and hit the “enter” key.

If you have questions, feel free to reach me at .

Presentation of the Programs

Those are really straightforward programs in java, hopefully allowing you to get familiar with this programming language. Start by reading Demo.java, the main purpose of those two files is to get some sense of the syntax, the overall construction will be very close to what you would do in any object-oriented programming-language.

Note that every java program

and that java is case sensitive, every statement ends with ;.

One “feature” of java that often confuses programmers is that you need to “flush” the buffer after using a nextInt (or next"AnythingThatIsn'tLine" actually) to be able to read again from it. You can find it explained e.g. at https://stackoverflow.com/a/13102066.

Pushing Further

You can start by installing an IDE for Java. Eclipse is popular, open-source, cross-platform and free, but quite heavy, choice, you may also want to consult e.g. this list on wikipedia to ease the comparison. Note that Visual Studio Code supports Java, and is probably already installed on your computer.

Playing with the code won’t hurt, and here are some suggestions of exercises:

In CSCI 4711 - Software Engineering, Dr. Paul Attie uses Program Development in Java: Abstraction, Specification, and Object-Oriented Design, by Barbara Liskov and John Guttag. Addison-Wesley.