Learn Java Basics
About Lesson

A data type is a classification of data based on the type of value it holds. In Java, data types specify the size and type of values that can be stored in a variable.

Here are some examples of data types in Java:

  1. Integer (Int)

int – This data type is used to store integer values. For example:

int myAge = 30;
  1. Floating-point Numbers (double)

double – This data type is used to store decimal values. For example:

double myWeight = 70.5;
  1. Boolean (boolean)

boolean – This data type is used to store true or false values. For example:


boolean isStudent = true;
  1. Text (char)

Text (Char)char – This data type is used to store a single character. For example:

char myGrade = 'A';
  1. Text (String)

String – This data type is used to store a sequence of characters. For example:

String myName = "John";
  1. Floating-point Numbers (float)

float – This data type is used to store decimal values with single precision. For example:

float myHeight = 1.75f;
  1. Integer (long)

long – This data type is used to store integer values with a larger range than int. For example:

long mySalary = 10000000000L;

These are just a few examples of data types in Java. Different data types have different size limitations and are used to store different types of values.

Print Numbers and Texts

To print numbers and text in Java, you can use the System.out.print() or System.out.println() method. This method is used to display text on the console output.

Here’s an example of how to print a number and text using this method:


int num = 10;
String text = "Hello, World!";
System.out.print("The number is: " + num);
System.out.println("The text is: " + text);


Differnce between print() and println()

Featureprint()println()
Outputs textYesYes
Adds a newline characterNoYes
Continues printing on the same lineYesNo
Syntaxprint("text")println("text")
Exampleprint("Hello"); print("World")println("Hello"); println("World")
OutputHelloWorld

Hello

World


Join the conversation