What is Java? Why is it Used? How Was It Created? Datatypes and Variables in Java
Introduction
Java is one of the most popular programming languages in the world. It is widely used for developing web applications, desktop software, mobile applications, enterprise systems, and cloud-based solutions. Java follows the principle:
"Write Once, Run Anywhere (WORA)"
This means Java programs can run on different operating systems without modifying the code.
What is Java?
Java is a high-level, object-oriented, platform-independent programming language developed by James Gosling and his team at Sun Microsystems in 1995.
Java code is compiled into bytecode, which runs on the Java Virtual Machine (JVM). This allows Java applications to work on Windows, Linux, macOS, and many other platforms.
Simple Java Program
Java
public class Main {
public static void main(String[] args) {
System.out.println("Hello, Java!");
}
}
Output
Hello, Java!
Why is Java Used?
Java is popular because it offers:
- Platform Independence Java programs can run on any device with a JVM.
- Object-Oriented Programming Java uses classes and objects, making applications easier to develop and maintain.
- Security Java provides built-in security features and memory management.
- High Performance The JVM uses Just-In-Time (JIT) compilation to improve execution speed.
- Large Community Support Millions of developers use Java worldwide.
-
Enterprise Applications
Large companies use Java for banking, e-commerce, and business applications.
How Was Java Created?
In 1991, a team led by James Gosling at Sun Microsystems started a project called Green Project.
Evolution of Java
Year
Event
1991
Green Project Started
1994
Language renamed to Java
1995
Java officially released
2010
Sun Microsystems acquired by Oracle Corporation
Present
Java remains one of the most used languages
How Many Days Does It Take to Learn Java?
Learning time depends on your experience and dedication.
Beginner Roadmap
Level
Time Required
Java Basics
2–3 Weeks
OOP Concepts
2 Weeks
Collections & Exception Handling
2 Weeks
JDBC & Database
1–2 Weeks
Advanced Java
3–4 Weeks
Projects Practice
Ongoing
Recommended Timeline
1 Hour Daily → 3–4 Months
2–3 Hours Daily → 1–2 Months
4+ Hours Daily → 3–6 Weeks
Datatypes in Java
A datatype specifies the type of data a variable can store.
Java has 8 Primitive Datatypes.
Datatype
Size
Example
byte
1 byte
100
short
2 bytes
20000
int
4 bytes
50000
long
8 bytes
100000L
float
4 bytes
10.5f
double
8 bytes
20.55
char
2 bytes
'A'
boolean
1 bit
true
Example
Java
public class DataTypes {
public static void main(String[] args) {int age = 21; double salary = 50000.50; char grade = 'A'; boolean isStudent = true; System.out.println(age); System.out.println(salary); System.out.println(grade); System.out.println(isStudent);}
}
Output
21
50000.5
A
true
Non-Primitive Datatypes
These are created by programmers or provided by Java libraries.
String
Arrays
Classes
Interfaces
Objects
Example
Java
String name = "Ak";
Variables in Java
A variable is a container used to store data values.
Syntax
Java
datatype variableName = value;
Example
Java
int age = 21;
String name = "Ak";
Types of Variables in Java
- Local Variable Declared inside a method. Java public void display() { int num = 10; }
- Instance Variable Declared inside a class but outside methods. Java class Student { int id; } Each object gets its own copy.
-
Static Variable
Declared using the static keyword.
Java
class Student {
static String college = "ABC College";
}
Shared by all objects.
Method Overloading Example
Method Overloading allows multiple methods with the same name but different parameters.
Java
class Calculator {int add(int a, int b) {
return a + b;
}int add(int a, int b, int c) {
return a + b + c;
}double add(double a, double b) {
return a + b;
}
}
public class Main {
public static void main(String[] args) {
Calculator obj = new Calculator();
System.out.println(obj.add(10, 20));
System.out.println(obj.add(10, 20, 30));
System.out.println(obj.add(10.5, 20.5));
}
}
Output
30
60
31.0
Conclusion
Java is a powerful, secure, and platform-independent programming language used for building everything from mobile applications to enterprise software. By understanding Java's history, uses, datatypes, variables, and method overloading concepts, beginners can build a strong foundation for learning advanced Java topics such as OOP, Collections, JDBC, Spring Boot, and Full Stack Development.
Top comments (0)