java programing language

 


Java is a high-level, general-purpose, and object-oriented programming language that was originally developed by Sun Microsystems in 1995. It has since become one of the most popular programming languages due to its platform independence, versatility, and widespread use in various domains.

Here are some key characteristics and features of Java:

Platform Independence:

Java follows the "Write Once, Run Anywhere" (WORA) principle. Code written in Java can run on any device or platform with a Java Virtual Machine (JVM), making it platform-independent.
Object-Oriented Programming (OOP):

Java is designed around the principles of object-oriented programming, including concepts like classes, objects, encapsulation, inheritance, and polymorphism.
Syntax:

Java syntax is similar to C and C++, making it familiar to many programmers. It also incorporates some features from other languages, which contribute to its readability and ease of use.
Automatic Memory Management:

Java uses automatic garbage collection to manage memory. This helps developers avoid memory leaks and makes memory management more straightforward.
Rich Standard Library:

Java comes with a vast standard library that provides a wide range of pre-built functionality, from data structures to networking, I/O, and graphical user interface development.
Multi-Threading:

Java supports multithreading, allowing developers to write programs that can perform multiple tasks simultaneously. This is useful for building scalable and responsive applications.
Security:

Java places a strong emphasis on security. It runs in a sandboxed environment, which helps protect against various security threats. Java applets, once a common feature for web-based applications, have been deprecated due to security concerns.
Community and Ecosystem:

Java has a large and active community of developers worldwide. The ecosystem includes a variety of tools, frameworks (e.g., Spring, Hibernate), and libraries that enhance Java's capabilities for different application domains.
Enterprise Adoption:

Java is widely used in enterprise environments for building large-scale, mission-critical applications. Its reliability, scalability, and maintainability have contributed to its popularity in business and industry.
Continued Evolution:

Java is regularly updated with new features and improvements. The introduction of the Java Platform, Standard Edition (Java SE) and Java Platform, Enterprise Edition (Java EE) has evolved into the more modular and streamlined Java Platform, Standard Edition (Java SE) and Jakarta EE.



Spring boot

public class printSong 
{
public static void main (String[] args) 
for (int i = 1; i <= 3; i++) 
System.out.println("Row, row, row your boat, gently down the stream,"); 
System.out.println ("Merrily, merrily, merrily, merrily; life is but a dream"); 
System.out.println(); 
}
}
}


do while

public class testing_do_while_loop {

    public static void main(String[] args){


        int x=0;

        do{

            System.out.println("Value of x is " + x + ".");

            x++;

        }while (x<=6);

    }

}


for loop

public class testing_for_loop {


    public static void main(String[] args) {


        for( int i = 1; i < 5; i++ ) {

        // i++ means increase the value of i by 1 each time untill 1<5

        

            System.out.println("Value of i is " + i + " now.");

        }


    }

    

}


if else 

public class testing_if_else {


    //This part is for string conditions

    public static void main(String[] args){

        String str="dengue";


        if("covid".equals(str)){

            System.out.println("You cannot go out");

        }

        else{

            System.out.println("You can go out");

        }


    //This part is for int conditions    


        int i = 0;

        

        if (i == 10){

            System.out.println("i is 10");

        }

        else{

            System.out.println("i is not 10");

        }

    }

}


if else if

public class testing_if_else_if {

    public static void main(String[] args){


        String str = "Covid";

        if ("Covid".equals(str)){

            System.out.println("You Have Covid");

        }

        else if ("Dengue".equals(str)){

            System.out.println("You Have Dengue");

        }

        else{

            System.out.println("You Are Healthy");

        }

        

    }

}

oop concepts

Encapsulation:


Encapsulation is the bundling of data (attributes) and methods that operate on the data into a single unit known as a class. It helps in hiding the internal implementation details of the class


public class BankAccount {

    private double balance;


    public void deposit(double amount) {

        balance += amount;

    }


    public double getBalance() {

        return balance;

    }

}


Inheritance:


Inheritance allows a class to inherit properties and behaviors from another class. The class that is being inherited from is called the superclass or parent class, and the class that inherits is called the subclass or child class.

java



public class Animal {

    void eat() {

        System.out.println("This animal eats.");

    }

}


public class Dog extends Animal {

    void bark() {

        System.out.println("The dog barks.");

    }

}



Polymorphism:


Polymorphism allows objects to be treated as instances of their parent class rather than their actual class. This can be achieved through method overriding and interfaces.

java



public interface Shape {

    void draw();

}


public class Circle implements Shape {

    @Override

    public void draw() {

        System.out.println("Drawing a circle.");

    }

}


public class Square implements Shape {

    @Override

    public void draw() {

        System.out.println("Drawing a square.");

    }

}



Abstraction:


Abstraction involves simplifying complex systems by modeling classes based on the essential properties and behaviors they share. Abstract classes and interfaces in Java are used to achieve abstraction.

java




abstract class Shape {

    abstract void draw();

}


class Circle extends Shape {

    @Override

    void draw() {

        System.out.println("Drawing a circle.");

    }

}

No comments: