In the previous article, we learned what Java is, how Java programs execute, and the role of JVM, JRE, and JDK. We also ended with an interesting question:
Is Java a 100% Object-Oriented Programming Language?
Before moving on to classes and objects, let's answer this question and explore some fundamental Java concepts such as comments, identifiers, keywords, and data types.
Java is widely known as an Object-Oriented Programming (OOP) language because it supports important OOP concepts such as:
However, Java is not considered a purely Object-Oriented Programming language.
There are a few reasons why Java is not considered completely object-oriented.
The biggest reason is that Java provides primitive data types.
int age = 20;
char grade = 'A';
boolean isPassed = true;
Here, int, char, and boolean are primitive data types. They store values directly and are not objects.
In a purely object-oriented language, everything should be represented as an object.
Since Java includes primitive data types, it breaks this rule.
Java allows the use of static variables and methods.
class Student {
static String collegeName = "ABC College";
}
A static variable belongs to the class itself rather than to an object.
In pure object-oriented programming, most interactions are expected to happen through objects. Static members introduce behavior that exists independently of any object.
Java allows arithmetic operations directly on primitive values.
int a = 10;
int b = 20;
int sum = a + b;
Here, the addition operation works directly on primitive values rather than through objects.
In a purely object-oriented language, even numbers are typically represented as objects and operations are performed through methods.
Java was designed to balance:
Primitive data types make programs faster and more memory efficient. Static members provide utility and convenience when data needs to be shared across all objects.
Because of these practical design decisions, Java is not considered a pure OOP language.
Java strongly follows Object-Oriented Programming principles and is one of the most popular OOP languages in the world.
However, because it includes primitive data types, static members, and some features that operate outside the object model, Java is object-oriented but not 100% object-oriented.
Comments are notes written inside code to make it easier for humans to understand.
Comments are ignored by the compiler and do not affect program execution.
A single-line comment starts with //.
// This is a single-line comment
System.out.println("Hello World");
A multi-line comment starts with /* and ends with */.
/*
This is a
multi-line comment
*/
System.out.println("Hello World");
Comments help developers:
Identifiers are names given by programmers to variables, methods, classes, and objects.
Examples:
int age = 20;
String studentName = "Ravi";
double totalMarks = 95.5;
Here:
agestudentNametotalMarksare identifiers.
❌ Invalid
int 2marks = 50;
✅ Valid
int marks2 = 50;
❌ Invalid
String student name = "Ravi";
✅ Valid
String studentName = "Ravi";
_, and $ Are Allowed✅ Valid
student_name
student$name
age
Age
AGE
All three are considered different identifiers.
Keywords are reserved words that already have a predefined meaning in Java.
These words are used by the compiler and cannot be used as identifiers.
Some common Java keywords are:
class
public
static
void
int
double
if
else
while
for
return
❌ Invalid
int class = 10;
Since class is a keyword, Java will generate a compilation error.
A variable is a named container used to store data.
Think of a variable as a labeled box that stores information.
For example:
String name = "Ravi";
int age = 20;
Here:
name stores textage stores a numberDifferent types of information require different data types.
Java provides several primitive data types to store different kinds of values efficiently.
The table below summarizes the commonly used primitive data types.
| Datatype | Size | Range | Default Value | Wrapper Class |
|---|---|---|---|---|
| byte | 1 byte | -128 to 127 | 0 | Byte |
| short | 2 bytes | -32768 to 32767 | 0 | Short |
| int | 4 bytes | -2147483648 to 2147483647 | 0 | Integer |
| long | 8 bytes | -9223372036854775808 to 9223372036854775807 | 0 | Long |
| float | 4 bytes | -3.4e38 to 3.4e38 | 0.0 | Float |
| double | 8 bytes | -1.7e308 to 1.7e308 | 0.0 | Double |
| boolean | NA | true / false | false | Boolean |
| char | 2 bytes | 0 to 65535 | '\u0000' | Character |
Used to store whole numbers.
int age = 20;
Used to store decimal numbers.
double price = 499.99;
Used to store a single character.
char grade = 'A';
Used to store true or false values.
boolean isPassed = true;
Used to store text.
String name = "Ravi";
Note:
Stringis not a primitive data type. It is a class in Java.
int, double, and boolean, and every value had to be stored as an object. What advantages and disadvantages do you think this would have on performance and memory usage?int age = 20;
double age = 25.5;
Will this code compile successfully? If not, identify the issue and explain how Java uses identifiers and data types in this case.
studentName
2ndYear
total_marks
class
student$name
Choose the most appropriate Java data type for each and explain your choice.