Welcoming a new face — #anonim_fw0 just made a spark with 5 #NFTs in the #NFToa ecosystem ⚡🔥
— NFToa (@nftoa_) September 2, 2025
Fresh energy like this keeps the community alive and growing. Thank you for joining the journey #eCash $XEC #NFTCollectors #NFT_support #CryptoTrading #CryptoNews #CryptoHelp pic.twitter.com/G2j1a8JW3y
1. Data Type
There are 8 basic data types in Java, namely boolean (for logical form), char (for textual form), byte, short, int, long (integral), double and float (floating point). Table 8.1 below shows an explanation of these data types.

Data Types, Variables, Input-Output (I/O) Statements
Table 8.1. Data types in Java
| Operator | Fungsi | Contoh |
|----------|----------------------------------------------|--------------|
| + | Penjumlahan | 3 + 5 = 8 |
| - | Pengurangan | 7 – 2 = 5 |
| * | Perkalian | 5 * 2 = 10 |
| / | Pembagian | 6 / 3 = 2 |
| % | Sisa hasil bagi (modulus) | 5 / 2 = 1 |
| ++ | Menambahkan nilai 1 ke variabel (increment) | C++ = C + 1 |
| -- | Mengurangi nilai 1 ke variabel | C-- = C - 1 |In Java, String is not a primitive data type (but is a Class). String represents a data type consisting of several characters. Strings are written using double quotes ("").
The following examples show how to use the above data types. Type the code in the following examples then compile and run. Observe the output of the program.
Example 8.1. Use of integral data types
public class ContohPerhitungan { public static void main(String[] args) { byte a = 1; short b = 12; int c = 300, d, e; d = a + b + c; e = a * b * c;
System.out.println("Hasil penjumlahan = " + d);
System.out.println("Hasil perkalian = " + e);
} }Example 8.2. Using the float data type
public class LuasLingkaran { public static void main(String[] args) { double pi = 3.1416; double r = 2.12; double luas; luas = pi * r * r;
System.out.println("Luas Lingkaran = " + luas);
}
}Example 8.3. Use of the char data type
~public class tipeChar {
public static void main(String[] args) {
char ch = 'A';
System.out.println("ch = " + ch); ch++;
System.out.println("ch = " + ch);
}
}2. Variables and Constants
The rules for naming variables and constants as in Chapter 5 also apply to Java. In addition, writing identifiers in Java is case-sensitive. This means that uppercase and lowercase letters are considered different. Unlike VB, Java requires us to declare variables and constants first. Otherwise, the program code will not compile.
The way to declare variables is as follows:
<tipe data> <nama variabel> [=nilai awal];Initial values are optional or may or may not be included. Consider example 8.1 above. Variables a, b, and c have initial values assigned. While variables d and e do not have values assigned. Also consider examples 8.2 and 8.3 for variable declarations.
3. Input / Output
In the examples of program code above, we have actually used one way to display output to the screen, namely the System.out.println command, but we have never used a statement to get input. Here we will learn how to use input and output statements in Java.
To be able to capture input from the keyboard, we must use the BufferedReader class located in the java.io package. So at the beginning of the program we must include the class in the program code. Consider the following example.
Example 8.4. Input statements in Java
import java.io.BufferedReader; import java.io.InputStreamReader; import java.io.IOException;
public class InputKeyboard
{
public static void main( String[] args ){ BufferedReader dataIn = new BufferedReader(new
InputStreamReader( System.in) );
String name = "";
System.out.print("Ketikkan nama anda:");
try{
name = dataIn.readLine(); }catch( IOException e ){
System.out.println("Error!");
}
System.out.println("Hai " + name +"!");
}
}The three lines that start with the import command indicate that we will be using the BufferedReader, InputStreamReader and IOException classes that are in the java.io package. We will discuss the explanation of the package in another part of this chapter.
Pada statement,
BufferedReader dataIn = new BufferedReader(new
InputStreamReader( System.in) );We declare a variable named dataIn with the class type BufferedReader. Then, we declare a String variable with the identifier name. This statement is used to indicate where to store the input from the user. The name variable is initialized as an empty String "". The next line is to provide the string output as we have learned by using the System.out.print statement;
Now, the block below is a try-catch block (we will discuss about this in the exception sub-chapter)
try{
name = dataIn.readLine(); }catch( IOException e ){
System.out.println("Error!");
}This line explains that the possibility of an error in the statement name = dataIn.readLine(); will be captured. If there is an error then the text "Error" will be delivered. If there is no error then the name variable will be filled with what the user entered via the keyboard. And will be displayed in the last statement.
To display the output we want, we can use the following command:
System.out.println()
System.out.print()System.out.println() will create a new line while System.out.print() will not create a new line.
Getting to Know Java Programming Data Types
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package teoriPBO;
import java.util.Scanner;
/**
*@author Wawan Beneran
* www.gatewan.com
*/
public class tipedata {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// 2 kategori tipe data
// 1 tipe data primitif (biasanya ditulis dengan diawali huruf kecil smua)
// 2 tipe data referensi/objek Conversion Class Table
| Class | Konversi ke Tipe Data | Pemakaian |
|-----------|-----------------------|--------------------------|
| Boolean | Boolean | Boolean.parseBoolean(…); |
| Byte | Byte | Byte.parseByte(…); |
| Character | Char | String.charAt(); |
| Short | Short | Short.parseShort(…); |
| Integer | Int | Integer.parseInt(…); |
| Long | Long | Long.parseLong(…); |
| Float | Float | Float.parseFloat(…); |
| Double | Double | Double.parseDouble(…) |