0% found this document useful (0 votes)
21 views

Java is a high-level, class-based, object-oriented programming language that was first developed by Sun Microsystems in 1991

Java badics
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
21 views

Java is a high-level, class-based, object-oriented programming language that was first developed by Sun Microsystems in 1991

Java badics
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 9

Java is a high-level, class-based, object-oriented programming language that was first

developed by Sun Microsystems in 1991. The language was initially called "Oak" after an oak
tree that stood outside the office of James Gosling, the creator of Java. It was later renamed
"Java" in 1995, inspired by Java coffee.

### Key Milestones in Java's History:

1. **1991**: Java's development begins. A team led by James Gosling, along with Mike
Sheridan and Patrick Naughton, started working on a project known as "The Green Project."
They aimed to create a language that could be used for electronic devices like set-top boxes
and televisions.

2. **1995**: Java is officially released by Sun Microsystems. The language was designed with a
philosophy of "Write Once, Run Anywhere," meaning compiled Java code could run on any
platform without needing recompilation. This release included the HotJava web browser, which
was the first browser to support Java applets.

3. **1996**: Java Development Kit (JDK) 1.0 is released. It becomes the first stable release of
Java, and developers start adopting it widely for various software projects.

4. **1997**: Java becomes popular for server-side applications. Java Platform, Enterprise
Edition (Java EE), which extends Java Standard Edition (Java SE) with specifications for
enterprise features such as distributed computing and web services, is developed.

5. **1999**: Sun Microsystems releases Java 2, which was a major overhaul. This version
introduced the Swing graphical API, Collections framework, and the concept of Java Community
Process (JCP), which allowed community members to participate in the development of Java
specifications.

6. **2004**: Java 5 (also known as J2SE 5.0) introduces major updates like generics, metadata,
enumerated types, and the enhanced for loop.

7. **2006**: Sun Microsystems releases Java as open-source software under the GNU General
Public License (GPL). This leads to the creation of OpenJDK, which is the official reference
implementation of the Java platform.

8. **2009**: Oracle Corporation acquires Sun Microsystems, becoming the owner of Java. This
acquisition causes concerns within the community about the future of Java's open-source
status.

9. **2011**: Java 7 is released, adding features like the try-with-resources statement, improved
type inference for generic instance creation, and more.
10. **2014**: Java 8 is released with significant updates, including lambda expressions, the
Stream API, and the new Date and Time API, which made functional programming concepts
more accessible in Java.

11. **2017**: Oracle introduces a new release cadence for Java, promising new feature
releases every six months. Java 9 is released with the module system (Project Jigsaw), which
aimed to make Java more modular and scalable.

12. **2018-Present**: Java continues to evolve with regular updates. Recent versions have
introduced new features like switch expressions, text blocks, records, pattern matching, and
more. Java 17, released in 2021, is a Long-Term Support (LTS) version, which means it will
receive extended support and updates from Oracle.

Java remains one of the most popular programming languages due to its portability, security
features, and vast ecosystem of libraries and frameworks. It is widely used in various domains,
including web development, mobile development (especially Android), enterprise applications,
and large-scale systems.

Java is a high-level, object-oriented programming language developed by Sun Microsystems in


the early 1990s, with its official release in 1995. It was designed by James Gosling and his team
with the primary objective of being a "Write Once, Run Anywhere" language. This means that
Java code, once written and compiled, can run on any device or operating system that has a
Java Virtual Machine (JVM), without requiring any modification to the code.

### Key Features of Java:

1. **Platform Independence**: Java achieves platform independence through the use of the
JVM, which allows Java programs to run on any platform that has a JVM installed. This makes
Java an excellent choice for cross-platform applications.

2. **Object-Oriented**: Java is a pure object-oriented language, meaning it models real-world


entities using classes and objects. Key principles of object-oriented programming, such as
inheritance, encapsulation, polymorphism, and abstraction, are integral to Java.

3. **Simple and Familiar**: Java was designed to be easy to use and accessible to
programmers. It avoids complex features found in other languages, like explicit pointer
management and operator overloading, which simplifies the development process.

4. **Secure**: Java provides a robust security framework. The language was designed with
security in mind, including features like runtime checking, garbage collection, and a secure
execution environment for running code from untrusted sources (e.g., Java applets).
5. **Robust and Reliable**: Java emphasizes early checking for possible errors, with features
like exception handling and a strong memory management model. The automatic garbage
collection helps prevent memory leaks, which can lead to program crashes and instability.

6. **Multithreaded**: Java has built-in support for multithreading, allowing developers to write
programs that can perform multiple tasks simultaneously. This is useful for applications that
require background processing, such as games, media players, or web servers.

7. **Distributed Computing**: Java supports distributed computing through its extensive


networking capabilities, allowing programs to access files, applications, and data across the
network. Technologies like Remote Method Invocation (RMI) and Enterprise JavaBeans (EJB)
facilitate distributed application development.

8. **High Performance**: While traditionally, interpreted languages are slower than compiled
languages, Java's use of Just-In-Time (JIT) compilers allows for optimized performance, making
Java applications perform at speeds comparable to native applications.

9. **Dynamic and Extensible**: Java is designed to adapt to an evolving environment. New


classes can be added seamlessly to a running Java program, and it supports dynamic loading
of classes.

10. **Vast Ecosystem and Community Support**: Java boasts a rich ecosystem of libraries,
frameworks, and tools that enhance development efficiency. It also has a vast, active community
that contributes to its continuous improvement, making it one of the most supported and
versatile programming languages.

### Applications of Java:

Java is used in various domains, including:

- **Web Applications**: Java is widely used for building robust and scalable web applications
using frameworks like Spring, Hibernate, and Apache Struts.
- **Enterprise Applications**: Java Enterprise Edition (Java EE) provides a set of specifications
and standards for building large-scale, secure, and high-performance applications.
- **Mobile Applications**: Java is the foundation for Android development, the most popular
mobile operating system worldwide.
- **Scientific and Research Applications**: Due to its reliability and speed, Java is used in
scientific applications, including natural language processing and artificial intelligence.
- **Games and Embedded Systems**: Java is also used in the development of games and
applications for embedded systems and smart devices.

Overall, Java remains one of the most popular programming languages due to its versatility,
robustness, and ease of use, making it a preferred choice for developers worldwide in various
application domains.
Java program syntax refers to the set of rules that defines how a Java program is written and
understood by the Java compiler. Here’s an overview of the key components and structure of a
Java program:

### Basic Structure of a Java Program

```java
// Package declaration (optional)
package com.example;

// Import statements (optional)


import java.util.Scanner;

// Class declaration
public class ClassName {

// Main method: entry point of any Java program


public static void main(String[] args) {
// Statements (code to be executed)
System.out.println("Hello, World!"); // Print a message to the console
}

// Other methods (optional)


public void exampleMethod() {
// Method code here
}
}
```

### Key Components of Java Syntax

1. **Comments**:
- **Single-line comments** start with `//` and extend to the end of the line.
- **Multi-line comments** are enclosed in `/*` and `*/`.
- **Documentation comments** are enclosed in `/**` and `*/` and are used to generate API
documentation.

```java
// This is a single-line comment

/* This is a
multi-line comment */
/**
* This is a documentation comment
* Used to describe the functionality of the code
*/
```

2. **Package Declaration** (optional):


- Specifies the package to which the class belongs. It should be the first line in the file.
```java
package com.example;
```

3. **Import Statements** (optional):


- Used to import other Java classes, packages, or libraries. Must be declared after the
package declaration and before the class definition.
```java
import java.util.Scanner;
```

4. **Class Declaration**:
- Every Java program must have at least one class definition. A class is a blueprint for objects,
encapsulating data and methods that manipulate that data.
```java
public class ClassName {
// class body
}
```
- **Access Modifiers**: `public`, `private`, `protected`, and default (no keyword) define the
visibility of the class.
- **Naming Conventions**: Class names should start with an uppercase letter and follow
camel case.

5. **Main Method**:
- The `main` method is the entry point for any Java standalone application.
```java
public static void main(String[] args) {
// code to execute
}
```

6. **Methods**:
- A method is a block of code that performs a specific task. It can have zero or more
parameters and may or may not return a value.
```java
public int add(int a, int b) {
return a + b;
}
```
- **Modifiers**: `public`, `private`, `protected`, `static`, `final`, etc., define method behavior.
- **Return Type**: Specifies the data type of the value the method returns. If it doesn’t return a
value, use `void`.
- **Method Name**: Should start with a lowercase letter and use camel case.

7. **Statements and Expressions**:


- **Statements**: A single line of code that performs a task, such as a variable declaration,
assignment, or method call.
- **Expressions**: Combinations of variables, operators, and method calls that evaluate to a
single value.
```java
int sum = a + b; // Statement with an expression
```

8. **Variables**:
- Variables are containers for storing data values. They must be declared with a specific data
type.
```java
int number = 5; // Declaring an integer variable
```
- **Types of Variables**:
- **Local Variables**: Declared inside a method or block.
- **Instance Variables**: Declared inside a class but outside any method, constructor, or
block.
- **Class Variables (Static Fields)**: Declared as static; only one copy exists regardless of
the number of instances.

9. **Control Structures**:
- **Conditional Statements**: `if`, `else if`, `else`, `switch` to control the flow based on
conditions.
```java
if (a > b) {
System.out.println("a is greater");
} else {
System.out.println("b is greater or equal");
}
```
- **Looping Statements**: `for`, `while`, `do-while` loops to execute code repeatedly.
```java
for (int i = 0; i < 5; i++) {
System.out.println(i);
}
```

10. **Exception Handling**:


- Used to handle runtime errors, allowing the program to continue execution.
```java
try {
int result = 10 / 0;
} catch (ArithmeticException e) {
System.out.println("Division by zero is not allowed.");
} finally {
System.out.println("This block always executes.");
}
```

11. **Access Modifiers and Non-Access Modifiers**:


- **Access Modifiers**: `public`, `private`, `protected`, and default.
- **Non-Access Modifiers**: `static`, `final`, `abstract`, `synchronized`, etc.

12. **Data Types**:


- **Primitive Data Types**: `int`, `char`, `double`, `boolean`, `byte`, `short`, `long`, `float`.
- **Non-Primitive Data Types**: Objects, arrays, strings, etc.

### Example: Full Java Program

```java
package com.example;

import java.util.Scanner;

public class Greeting {

public static void main(String[] args) {


Scanner scanner = new Scanner(System.in); // Create a Scanner object for user input

System.out.print("Enter your name: ");


String name = scanner.nextLine(); // Read user input

System.out.println("Hello, " + name + "! Welcome to Java programming."); // Print a


greeting message
}
}
```

This program demonstrates basic Java syntax, including package declaration, import
statements, a class definition, the main method, a scanner for user input, and print statements.

Here's a simple Java program that demonstrates the basic structure of a Java application. This
program will print "Hello, World!" to the console.

### Example: HelloWorld Program in Java

```java
// This is a simple Java program that prints "Hello, World!" to the console.

public class HelloWorld { // The class name should match the filename HelloWorld.java

// The main method is the entry point of any Java program.


public static void main(String[] args) {
// The System.out.println method prints the specified message to the console.
System.out.println("Hello, World!");
}
}
```

### Explanation:

1. **Class Declaration**:
- Every Java program begins with a class declaration. In this example, the class is named
`HelloWorld`. The class name should match the filename (i.e., `HelloWorld.java`).

2. **Main Method**:
- The `main` method is the entry point for any standalone Java application. The Java Virtual
Machine (JVM) starts executing Java programs from the `main` method.
- The syntax `public static void main(String[] args)` is standard and must be used exactly as
shown.
- `public`: Access modifier that allows the JVM to access the `main` method.
- `static`: Means that the method can be called without creating an instance of the class.
- `void`: The method does not return any value.
- `main`: The name of the method, which is the entry point for any Java program.
- `String[] args`: The parameter `args` is an array of strings. It can be used to pass
command-line arguments to the program.

3. **Print Statement**:
- `System.out.println("Hello, World!");` is a statement that prints the text "Hello, World!" to the
console.
- `System` is a built-in class that provides access to the system.
- `out` is the output stream connected to the console.
- `println` is a method that prints the argument passed to it followed by a new line.

### How to Run the Program:

1. **Save the Program**: Save the above code in a file named `HelloWorld.java`.

2. **Compile the Program**: Open a command prompt or terminal and navigate to the directory
where the file is saved. Run the following command to compile the program:

```bash
javac HelloWorld.java
```

This command compiles the Java source file into a bytecode file (`HelloWorld.class`).

3. **Run the Program**: Run the compiled Java program with the following command:

```bash
java HelloWorld
```

You should see the output:

```
Hello, World!
```

This program is a basic example to demonstrate the syntax and structure of a Java application.
As you learn more about Java, you can create more complex programs involving user input,
loops, conditionals, and object-oriented concepts like inheritance and polymorphism.

You might also like