Data Types A data type defines the kind of data a variable can store, the operations that can be performed on it, and the amount of memory allocated. Java Primitive Data Types Data Type Size Range (Approx.) Example Byte 1 byte -128 to 127 byte a = 100; short 2 bytes -32,768 to 32,767 short s = 1000; Int 4 bytes -2,147,483,648 to 2,147,483,647 int num = 50000; Long 8 bytes -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807 long l = 100000L; float 4 bytes ~6–7 decimal digits float f = 5.75f; double 8 bytes ~15 decimal digits double d = 19.99; Char 2 bytes Single Unicode character char c = 'A'; boolean 1 bit* true or false boolean flag = true; *Boolean size is JVM-dependent (commonly 1 byte in memory, but logically 1 bit). Java Non-Primitive Data Types Type Description Example String Sequence of characters String name = "Dinesh"; Array Collection of elements int[] arr = {1, 2, 3}; Class Blueprint for objects class Car { } Object Instance of a class Car myCar = ...
1.1 Introduction to Java Java is a high-level, object-oriented, general-purpose programming language developed by Sun Microsystems. It is simple, efficient, and platform-independent. Java was originally designed for embedded network applications running on multiple platforms. It is a portable, object-oriented, and interpreted language. History of Java James Gosling (known as the Father of Java), Mike Sheridan, and Patrick Naughton initiated the Java language project in June 1991. This small team of Sun Microsystems engineers was called the Green Team . Initially, Java was designed for small embedded systems and electronic appliances such as set-top boxes. The language was first called Greentalk by James Gosling, and its file extension was .gt . Later, it was renamed Oak and was developed as part of the Green Project. The oak tree symbolizes strength and is the national tree of several countries, including the United States, France, Germany, and Romania. In 1995, Oak was renamed ...