A Very Short Intro to Java

Clément Aubert

May 17, 2018

Installation, Compilation and Execution

You can find at http://spots.augusta.edu/caubert/teaching/general/java/prog.zip a simple java program, made of two files, Demo.java and Rectangle.java.

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, 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
  1. To execute Demo.class, type
java Demo

You’ll be asked for an integer value. Just enter and 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 ;.

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.

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