Java

What is Java?

Java is a general-purpose, high-level programming language known for its portability, security features, and robustness. It is widely used for developing applications ranging from mobile and web to enterprise systems. Java’s platform independence is achieved through its bytecode compilation and the use of the Java Virtual Machine (JVM), allowing it to run on various operating systems.

Why do we use Java?

Java is a very popular programming language you can use to create various software applications. The language’s design prioritizes object-oriented principles, aiming for simplicity in readability, writing, and learning. Millions of developers use Java to build everything from desktop programs to advanced web applications.

Where do we use Java?

  • Web-based Applications
  • Desktop GUI Applications
  • Mobile App Development
  • Gaming Applications
  • Big Data Technologies­­
  • Distributed Applications
  • IoT Applications
  • Cloud-based Applications

Java Platforms(Java SE & Java EE)

There are 4 platforms or editions of Java:

1) Java SE (Java Standard Edition).

Java SE (Java Standard Edition) is a widely-used platform for developing and deploying portable applications for desktops, servers, and embedded environments. It provides the core functionality of the Java programming language, including libraries, frameworks, and tools necessary for building and running Java applications on a variety of devices and operating systems.

2) Java EE (Java Enterprise Edition).
Java EE (Java Enterprise Edition) is a platform designed for developing large-scale, enterprise-level applications. It provides an API and runtime environment for developing and running distributed, multi-tiered, scalable, and secure applications. Java EE includes a set of specifications, such as servlets, JavaServer Pages (JSP), Enterprise JavaBeans (EJB), and Java Persistence API (JPA), which facilitate the development of robust and reliable enterprise applications.

Java Platforms(Java ME & Java FX)

There are 4 platforms or editions of Java:
3) Java ME (Java Micro Edition).

It is a micro platform that is mainly used to develop mobile applications.

4) Java FX
It is used to develop rich Internet applications. It uses a lightweight user interface API.

Example:

public class MainPerson {
            public static void main(String[] args) {
                int age;// scaler variable declaration //scaler variable - can hold only one value
                age = 5;// initializing age variable with value 5
                System.out.println("age is " + age);
                age = 10;// assigning value 10 in variable age
                System.out.println("now age is " + age);
                Person karim; // object variable declaration
                // here we are declaring an object variable named Karim
                // karim's Data Type Person
                // here karim is an object variable
                karim = new Person(); // instantiating karim with default values
                // by using Person() method
                System.out.println("id = " + karim.id);
                karim.id = 1;
                System.out.println("now id = " + karim.id);
                System.out.println("name = " + karim.name);
                karim.name = "Karim Ali";
                System.out.println("now name = " + karim.name);
                // now create Maria
                Person maria;
                maria = new Person();
                maria.id = 2;
                System.out.println("Maria id is " + maria.id);
           }
}  
Explanation:
  • int age; :- Declares an integer variable named age.
  • age = 5; :- Assigns the value 5 to the age variable.
  • System.out.println(“age is ” + age); :- Prints the message “age is 5” to the console.
  • age = 10; :- Updates the value of the age variable to 10.
  • System.out.println(“now age is ” + age); :- Prints the message “now age is 10” to the console.
  • Person karim; :- Declares a reference variable named karim of type Person. It’s important to note that at this point, karim is just a reference and does not yet point to any actual Person object.
  • karim = new Person(); :- Creates a new Person object and assigns its reference to the karim variable. Now, karim points to a newly created Person object.
  • System.out.println(“id = ” + karim.id); :- Prints the message “id = 0” to the console. By default, when a new Person object is created, its id member variable will be set to the default value for integers, which is 0.
  • karim.id = 1; :- Sets the value of the id member variable of the karim object to 1.
  • System.out.println(“now id = ” + karim.id); :- Prints the message “now id = 1” to the console, reflecting the updated value of karim’s id.
  • System.out.println(“name = ” + karim.name); :- Prints the message “name = null” to the console. Similar to id, the name member variable of the karim object has not been initialized yet, so it has the default value for strings, which is null.
  • karim.name = “Karim Ali”; :- Sets the value of the name member variable of the karim object to “Karim Ali”.
  • System.out.println(“now name = ” + karim.name); :- Prints the message “now name = Karim Ali” to the console, reflecting the updated value of karim’s name.
  • Person maria; :- Declares another reference variable named maria of type Person.
  • maria = new Person(); :- Creates a new Person object and assigns its reference to the maria variable.
  • maria.id = 2; :- Sets the value of the id member variable of the maria object to 2.
  • System.out.println(“Maria id is ” + maria.id); :- Prints the message “Maria id is 2” to the console, showing the value of maria’s id.
  • The code demonstrates the use of variables, object creation, and accessing member variables of objects in Java. It creates two instances of the Person class named karim and maria and sets their respective id values to 1 and 2. Additionally, it sets the name of karim to “Karim Ali”.
Audience:

Our Java programming tutorial is designed to help beginners and professionals.





Visited 1 times, 1 visit(s) today

Comments are closed.

Close