Institute of Computer Science
  1. Courses
  2. 2019/20 spring
  3. Object-Oriented Programming (Narva College) (LTAT.NR.003)
ET
Log in

Object-Oriented Programming (Narva College) 2019/20 spring

  • Home
  • Materials
  • Grading
  • Java Glossary
  • Cheat sheet (S1-S6)
  • Source Example
  • Links
Chapter 1

First program

Once the environment is set up, let's write our first source code in Java. Source code is a text file that contains instructions written in a high level language Java. The source code cannot be executed (made to run) by a processor without some additional steps (translation into bytecode).

Step 1. Watch the video:

Step 2. Launch IntelliJ and start a new project. The wizard will ask you for a few names:

* Project Name - the name of a new project. This will be the name of the folder where all your current project files will be kept. We recommend to create a new project for each session, e.g. Session_1.
* Class Name - the name of the class in the code stored in the src (source) folder within your IntelliJ project. NB! Class names must be unique, without spaces, and the first letter of each word must be capitalised. We recommend to create a new class for each task, e.g. HelloWorld.
* Java File Name - the name of the file with extension of .java. IntelliJ sets the file name to be exactly as the class name. The source file holds the code.

Step 3. Type the following source code that defines a class called HelloWorld:

// This application program prints Hello, World!
public class HelloWorld {
  public static void main(String[] args) {
    System.out.println("Hello, World!");
  }
}
DO NOT COPY the code because your mind and hands need time to get used to a new programming language!
PS! Pay attention:
* Java is case-sensitive;
* the file name must be the same as the class name;
* punctuation: commas (,), dots (.), quotes ("), parentheses (), braces {} and brackets []
* each Java statement ends with a semicolon ; (do not use semicolons after method and class declarations that are followed by curly braces);
* the highlighted "keywords" - IntelliJ does it to make it easier for you to read your code.

Step 4. Compile/build the project and run the program (use the top menu):

PS! Pay attention to:
* Java source file must have the extension .java;
* compiled source code is Java bytecode with extension .class.

Question:

Check the out folders of the project. Has a new file with extension of .class been added?

Chapter 1
  • Institute of Computer Science
  • Faculty of Science and Technology
  • University of Tartu
In case of technical problems or questions write to:

Contact the course organizers with the organizational and course content questions.
The proprietary copyrights of educational materials belong to the University of Tartu. The use of educational materials is permitted for the purposes and under the conditions provided for in the copyright law for the free use of a work. When using educational materials, the user is obligated to give credit to the author of the educational materials.
The use of educational materials for other purposes is allowed only with the prior written consent of the University of Tartu.
Terms of use for the Courses environment