Java Tutorial for Beginners

Institute of Computing - Unicamp

Author:Marcos Mota

Cell execution

Using the IJava Kernel you can write any Java expression to be evaluated.
(You can run the cell using CTRL+Enter)


In [2]:
String hi = "Hello!";
hi


Out[2]:
Hello!

In [2]:
String[] args = null;

First Program in Java

You can change the cell to see different outputs


In [3]:
public class HelloWorld {
    
    public static void main(String[] args){
        
        System.out.println("Hello World!");
    }
}

In [4]:
HelloWorld.main(args)


Hello World!

Variables and Operators

Variables are names given to data thar we need to store and manipulate in our programs.

For example:

int userAge;

Primitive Data Types in Java

Data Type Descriptrion
byte The byte data type is used for storing integers from -128 to 127. It uses 1 byte of storage space.
short The short data type uses 2 bytes of storage space and has a range of -32768 to 32767.
int The int data type uses 4 bytes of storage space and has a range of -2^31 (-2147483648) to 2^31 -1(2147483647).
long The long data type uses 8 bytes of storage space and has a range of -2^63 to 2^63 - 1.
float The float data type uses 4 bytes of storage and has a range of approximately negative 3.40282347 x 10^38 to positive 3.40282347 x 10^38.
double The double data type uses 8 bytes of storage and has a range of approximately negative 1.79769313486231570 x 10^308 to positive 1.79769313486231570 x 10^308
char char stands for character and is used to store single Unicode.
boolean boolean is a special data type that can only hold two values: true and false.

Strings and Arrays


In [5]:
"Hello World".length()


Out[5]:
11