Java Basics
Java Basics
In Java, a class is defined as a blueprint or template that is used to define the structure and behavior of objects. It is
used as a blueprint for crea�ng objects, which are instances of the class. Data members (variables) and methods
(func�ons) that define the characteris�cs and ac�ons of objects belonging to that class are contained within it. It is
considered as a fundamental building block of object-oriented programming in Java, allowing objects with similar
proper�es and func�onali�es to be created and organized.
What is an object?
In Java, objects are instances or individual en��es created from a class. They represent real-world things or concepts
and have both data (atributes) and behaviour (ac�ons) associated with them. Objects are used to interact with each
other and perform specific tasks in a program. They are the basic units of object-oriented programming, allowing
developers to model and manipulate data in a structured and organized manner.
What is JVM?
JVM stands for "Java Virtual Machine." It is a crucial part of the Java programming language and allows Java programs
to run on different computer systems without modifica�on.
Imagine having a magic translator for Java. This translator can understand Java code and convert it into a language that
your computer can understand and execute. That's what JVM does! It takes your Java program and translates it into
instruc�ons that your computer's processor can follow. This way, Java programs can run on any computer, whether it's
a Windows PC, a Mac, or a Linux machine, because the JVM handles the transla�on for you.
So, JVM acts as a bridge between your Java code and the computer's hardware, making Java a "write once, run
anywhere" language.
Explain history of Java.
Java was developed by a team of engineers at Sun Microsystems, led by James Gosling. The team, known as the "Green
Team," was formed in 1991 with the goal of crea�ng so�ware for interac�ve television and other consumer electronics.
The primary individuals involved in the development of Java were:
James Gosling: O�en referred to as the "father of Java," James Gosling was the chief architect of the Java programming
language. He played a crucial role in the design and development of Java from its incep�on.
Mike Sheridan: Mike Sheridan was one of the key members of the Green Team and contributed to the early
development of Java.
Patrick Naughton: Patrick Naughton was another important member of the Green Team and made significant
contribu�ons to the crea�on of Java.
The original name of the programming language was "Oak." It was named so because the team developed it for the
Green Project, which was aimed at crea�ng so�ware for interac�ve television and home appliances.
However, as the project shi�ed its focus from interac�ve television to the World Wide Web and other networked
devices, the name "Oak" no longer seemed appropriate. Addi�onally, there were trademark conflicts with the name
"Oak" as it was already in use by other companies.
To address these issues and find a more suitable name, the team held a brainstorming session. They eventually setled
on the name "Java," inspired by the Java coffee they o�en drank in their office cafeteria. The name "Java" was finalized
in 1994 and officially announced to the public in May 1995.
class MathOpera�ons
{
int calculateSum(int num1, int num2)
{
int sum = num1 + num2;
return sum;
}
}
Explana�on:
condi�on: The expression that evaluates to either true or false.
value_if_true: The value to be assigned to result if the condi�on is true.
value_if_false: The value to be assigned to result if the condi�on is false.
Example:
int num = 10;
String result = (num > 5) ? "Greater than 5”: "Less than or equal to 5";
System.out.println(result);
In this example, if the value of num is greater than 5, the ternary operator will return "Greater than 5," and if num is
less than or equal to 5, it will return "Less than or equal to 5." The result will be printed accordingly.