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 Java. The name "Java" was inspired by Java coffee, which comes from the Indonesian island of Java. According to popular accounts, James Gosling chose the name while having a cup of coffee near his office.
JDK 1.0 was released on January 23, 1996. Since its first release, many new features have been added to Java. Today, Java is widely used for developing desktop applications, web applications, enterprise applications, mobile applications, smart cards, embedded systems, and cloud-based applications.
Basic Structure Of Java Program
// 1. Package Declaration (optional)
package mypackage;
// 2. Import Statements (optional)
import java.util.Scanner;
// 3. Class Declaration
public class MyProgram {
// 4. Main Method – Entry point of the program
public static void main(String[] args) {
// 5. Statements – Code to be executed
System.out.println("Hello, World!");
}
}
1. Package Declaration (Optional)
A Java program may begin with a package declaration that defines the folder or package name in which the class is stored.
For example: package mypackage;
This helps organize code into different logical groups.
2. Import Statements (Optional)
After the package declaration, import statements can be added to include built-in or user-defined Java classes and packages.
For example: import java.util.Scanner;
This allows the program to use various functionalities provided by external classes.
3. Class Declaration
Every Java program must have at least one class, which is the main building block of Java code.
For example: public class MyProgram { }
The class name should match the filename, and it contains all the methods and variables of the program.
4. Main Method Declaration
Inside the class, the main method is defined using the line:public static void main(String[] args)
This is the entry point of every Java application, and the JVM starts executing the program from this method.
5. Statements (Code Body)
Inside the main method, we write statements that define the program's behavior, such as printing output, taking input, or performing calculations.
For example: System.out.println("Hello, World!");
These statements are executed in the order they appear.
Comments
Post a Comment