Java Overview

Java is an open-source object-oriented programming language. Java was originally developed by Sun Microsystems in 1995. Java is supported by various platforms, such as Windows, Mac, Linux, etc.

Java is an object-oriented language because everything depends on objects. But, Java is not 100% object-oriented because of primitive data types int, char, float, etc. as they are not object-oriented. The primitive data types are faster than objects, and to achieve faster execution of Java programs, they kept the primitive data types as it is!

Java helps us create robust, large, high-performance, and scalable applications.

James Gosling is the creator of Java. Java was initially called Oak. James Gosling and his team changed the name from Oak to Java.

Oracle Corporation acquired by Sun Microsystems in 2009 and took complete ownership of Java.

Java is platform independent because the Java compiler converts the source code to bytecode, which is an intermediate language called bytecode, which can be executed on any platform or operating system.

The Bytecode(machine language) gets generated in the form of .class file as soon as the Java program gets compiled. Bytecode is an instruction for the JVM to covert it into machine language. Bytecode allows Java to be written once and run anywhere (WORA).

At the current moment, 3 billion devices are running Java.

Usage of Java:

  1. Desktop Applications
  2. Web Applications
  3. Enterprise Applications
  4. Mobile Applications
  5. Robotics
  6. Big data
  7. Frameworks

Four editions of Java:

1) Java SE (Java Platform, Standard Edition)
It is the standard edition which contains all the core functionality that needs to be supported by any programming language. Class, interface, abstraction, inheritance, encapsulation, polymorphism, String, exception handling, multithreading, I/O Stream, AWT, Collection, and so on are all examples of concepts.

2) Enterprise Edition Java Platform (Java EE)
It is a platform edition that helps us create various web applications It is developed on top of the Standard Edition. e.g. servlet, JSP, Web Services, EJB, JPA, Struts, Spring, etc.

3) Java ME (Java Platform, Micro Edition)
It is a platform edition used to create mobile applications.

4) JavaFX
It is a platform edition to develop desktop applications and Rich Internet Applications(RIA). Applications can run on a variety of platforms, including desktop, mobile, and web.

HelloWorld Java Program:

Let’s start and create our first Hello World Java application.

Create a java file ‘HelloWorld.java’ with the name ‘HelloWorld’ and extension as ‘.java’ anywhere in local machine. Copy, paste and save below code inside HelloWorld.java file.

Java application file will always have .java as an extension in the file name. The name of the Java file must match the class Name.

Java is case sensitive because it used C-style syntax, this means HelloWorld and helloworld are totally two different things.

// HelloWorld is the class name.
class HelloWorld {

// Predefined function given by java to print output.
public static void main(String[] args) {

/*
* Below println() method helps us to
* print/output Hello World !!! on screen.
*/ System.out.println("Hello World !!!");
}
}

Run javac HelloWorld.java command as shown in below screen shot in the same directory where we created above HelloWrold.java file. This command will create Employee.class file in the same folder where HelloWorld.java exist.

Run java HelloWorld command to get output of java application.

Congratulations!!! we have created our first java application.

Note: don’t worry about main method. We will be discussing this later in another chapter. Just remember, main method will be executing at first place.

Note: For having latest output always run javac class_name.java before running java class_name command. After saving latest changes in java file and run java class_name command will not print or give latest output.

Java Output:

The Java output statement helps us print the output/result on screen.

print() and println() are methods help us to print values or output same on the screen.

The println() method prints everything on the next line of the screen as shown below in output.

The print() method prints everything on the same line of the screen as shown below in output.

print() and println() can perform mathematical calculations and string concatenation.

Imran Khan, Adobe Community Advisor, AEM certified developer and Java Geek, is an experienced AEM developer with over 11 years of expertise in designing and implementing robust web applications. He leverages Adobe Experience Manager, Analytics, and Target to create dynamic digital experiences. Imran possesses extensive expertise in J2EE, Sightly, Struts 2.0, Spring, Hibernate, JPA, React, HTML, jQuery, and JavaScript.

5