Data types are divided into two groups:
- Primitive data types - includes byte , short , int , long , float , double , boolean and char.
- Non-primitive data types - such as String , Arrays and Classes
example :-
public class Main {
public static void main(String[] args) {
int myNum = 5; // integer (whole number)
float myFloatNum = 5.99f; // floating point number
char myLetter = 'D'; // character
boolean myBool = true; // boolean
String myText = "Hello"; // String
System.out.println(myNum);
System.out.println(myFloatNum);
System.out.println(myLetter);
System.out.println(myBool);
System.out.println(myText);
}
}
output:-
5
5.99
D
true
Hello
example of non primitive data types:-
example 1:-
public class Main {
public static void main(String[] args) {
String txt = "Hello World";
System.out.println(txt.toUpperCase());
System.out.println(txt.toLowerCase());
}
}
output:-
HELLO WORLD
hello world
example 2:-
public class Main {
public static void main(String[] args) {
String[] cars = {"Volvo", "BMW", "Ford", "Mazda"};
System.out.println(cars[0]);
}
}
output:-
Volvo
Sign up here with your email
ConversionConversion EmoticonEmoticon