Apache Commons CLI Tutorial

Time needed: 30 minutes In this tutorial I'll show how to use an Apache Commons CLI library in order to create a console application that accepts various user-provided options, validates them, and prints a help message if something goes wrong. We'll create a simple tool, called cli-random, that will generate pseudo-random numbers based solely on...

Java Arithmetic Operators

Time needed: 10 minutes This tutorial will show how to perform simple arithmetic operations in Java. So far in the previous tutorials we never did any operations on our data, except the string concatenation, such as the one shown below. The concatenated variable will hold an "abcdef" value. Arithmetic operators in Java are almost the...

Variables and types

Time needed: 20 minutes In the previous tutorial we've already used a variable. It was the args visible in a construction below. A word that precedes the variable name is called a type. In that case, String[] was a type, and args was a variable name. In Java, there are primitive types and object types....

Java comments

The Java comments are lines or portions of code ignored by the compiler and interpreter. Their main purpose is to provide various notes and hints helping to understand the code. Comments are the most basic form of documentation. In perfect world the code is self-documenting. It means that by reading the code you understand what's...

What String[] args do?

Time needed: 5 minutes In the previous examples we've made applications that simply execute an operation. What if we wanted to read some user input? That's what the String[] is there for: it contains all the arguments passed to an application. Let's write a slightly modified program: Compile and run it with the javac command,...

Code in Java without an IDE

Time needed: 5 minutes It's rather unpractical to code in Java this way, but in this tutorial I'll show that for simple applications, the whole process is very straightforward. All we need is a Java Development Kit and the favorite text editor. Let's create a file called MyProject.java Now we have to open terminal (or...

First application in Java

Time needed: 15 minutes In this tutorial we'll write our first Java application. Before we do that, however, we need to download and install few tools. Java Development Kit To create applications in Java we need Java Development Kit, which is a collection of tools necessary for that task. You can grab a JDK here....