2.2. Some Java Basics

For those users that have not yet worked with Java or other object oriented programming languages, here are some tipps and explanations that might be usefull when working through the tutorial.

2.2.1. Main class and main method

In order to run a Java program you need a main method. The main method alway looks like this:

public static void main(String[] args) {

}

The class the main method is located in is sometimes referred to as main class but can have an abritrary name. When you start a Java program you always do this by specifying the main class. In addition, some programs need input parameters. These are called program arguments and called through the String[] args parameter of the main method.

2.2.2 Packages

Software like MATSim, that contains a lot of classes, is usually organized in packages. These packages do not only give a certain structure to the code but also impact the way you can reference other classes. Moreover, there can be several classes with the same name in different packages.

Thus, If you want to reference another class in your program it is not only important that you get the class name right, but also the path to the class including the entire package structure.

2.2.3 Comments

Comments in a Java class contain text or code that is not executed when you run your program. On the one hand, they are used to add some explanation to your code. On the other hand, the can be used to temporarily exclude certain parts of the code from the execution.

There are two types of comments in Java: // an /* */ :

//  this line is not excuted
/* 
This block is not executed
*/