What is Java?
- Java is a programming language and a platform. Java is a high-level, robust, object-oriented, and secure programming language.
- Java was developed by Sun Microsystems (which is now a subsidiary of Oracle) in the year 1995. James Gosling is known as the father of Java. Before Java, its name was Oak. Since Oak was already a registered company, so James Gosling and histeam changed the name from Oak to Java.
- Platform: Any hardware or software environment in which a program runs, is known as a platform. Since Java has a runtime environment (JRE) and API, it is called a platform.
History of Java
- The very first name of java is “Green”.
- Java is a general-purpose programming language that is class-based, object-oriented, and designed to have as few implementation dependencies as possible.
- Java was originally developed by James goslings at sun microsystems and released in 1995 as a core component of sun microsystems java platforms.
- James goslings, mike shridan, and Patrick nagnton initiated the java language project in June 1991.
- The language was initially called Oak after an oak tree that stood outside gosling’s office.
- Why had they chosen a java name for java language the team gathered to choose a new name. The suggested words were “dynamic”.
- James goslings is the father of java, “revolutionary”, “silk”, DNA, etc. They wanted something that reflected the essence of the technology: revolutionary, lively, cool, unique and easy to spell, and fun to say.
- Why oak? Oak is a symbol of strength and chosen as a national tree of many countries like the USA, France, Germany, Romania, etc.
- In 1995, oak was renamed as “Java” because it was already a trademark by oak technologies.
- Java is an island of Indonesia where the first coffee was produced (called java coffee). It is a kind of espresso bean. java’s name was chosen by James goslings while having coffee near his office.
- Later the project went by the name Green and was finally renamed Java from java coffee from Indonesia.
- Goslings designed java with c/c++ style syntax that system and application programmers would familiar.
- Sun Microsystems released the first public implementation as Java 1.0 in 1996.
- JDK 1.0 was released in 1996. after the first release of java, there have been many additional features added to the language. now java is being used in windows applications, web applications, mobile applications, etc.
- It promised, “Write once, run anywhere”.
- The principles for creating java programming were “simple, robust, portable, platform-independent, secured, high performance, multithreaded, architecture-neutral, object-oriented, interpreted and dynamic”.
- Java was developed by James goslings, who is known as the father of java in 1995. James goslings and his team members started the project in the early 90s.
Editions of Java
- There are three editions of Java. Each Java edition has different capabilities. The editions of Java are:
- Java Standard Editions(SE): We use this edition to create programs for a desktop computer.
- Java Enterprise Edition(EE): We use this edition to create large programs that run on the server and to manage heavy traffic and complex transactions.
- Java Micro Edition(ME): We use this edition to develop applications for small devices such as set-top boxes, phones, appliances, etc.
Features of Java
- Simple: Java is simple because its syntax is simple and easy to understand. Java eliminates many complex and ambiguous concepts of C++. For example, the use of explicit pointers and operator overloading is not in Java.
- Object-Oriented: Everything in Java is in the form of an object. In other words, it has some data and behavior. A Java program must have at least one class and object.
- Robust: Java always tries to check errors at runtime and compile time. Java uses a garbage collector to provide a strong memory management system. Features like Exception handling and garbage collection make Java robust or strong.
- Secure: Java is a secure language, as Java does not use explicit pointers. All Java programs run on the virtual machine. Moreover, Java contains a security manager that defines the access levels of Java classes.
- Platform-Independent: Java provides a guarantee to write code once and run it anywhere (on any platform). The compiled byte code is platform-independent, and we can run it on any machine irrespective of the Operating system.
- Portable: We can carry the bytecode of Java to any platform. There are no implementation-dependent features in Java. Java provides predefined information for everything related to storage, such as the size of primitive data types
- High Performance: Java provides high performance with the use of the Just-In-Time (JIT) compiler.
- Distributed: Java is a distributed language it provides networking facilities. Java works very well in the distributed environment of the Internet. This is because Java supports TCP/IP protocol. EJB (Enterprise Java Beans) and RMI (Remote Method Invocation) of Java are used to create a distributed system.
- Multi-threaded: Java is a multi-threaded language as it can handle more than one job at a time.
Java Environment- JVM, JRE, and JDK
1. JVM (Java VirtualMachine)
Java Virtual Machine provides a runtime environment in which we can execute the bytecode. JVM is platformdependent. It performs the following tasks:
A) Loading the code
B) Verifying the code
C) Executing the code
D) Providing a runtime environment.
2. JRE (Java Runtime Environment)
JRE is a collection of tools. These tools together allow the development of applications and provide a runtime environment. JVM is a part of JRE. JRE is also platform dependent like JVM.
3. JDK (Java Development Kit)
Java Development Kit provides an environment that helps to develop and execute the Java program.There are Development Tools in JDK to provide an environment to develop Java programs. JDK, along with the JRE, contains other resources like the interpreter, and loader. compiler, an archiver (jar), and a documentation generator (Javadoc). These components together help you to build Java programs.
Java Keywords
Keywords are special words that are basically reserved keywords in any programming language. We cannot use them in the rest of the programs. We can only use them as the name of variables in Java, class, or method
1) abstract |
11) for |
21) new |
31) enum |
41) super |
2) assert |
12) goto |
22) package |
32) extends |
42) switch |
3) boolean |
13) if |
23) private |
33) final |
43) synchronized |
4) break |
14) implements |
24) protected |
34) finally |
44) this |
5) byte |
15) import |
25) public |
35) float |
45) throw |
6) case |
16) instance of |
26) continue |
36) while |
46) throws |
7) catch |
17) int |
27) default |
37) return |
47) transient |
8) char |
18) interface |
28) do |
38) short |
48) try |
9) class |
19) long |
29) double |
39) static |
49) void |
10) const |
20) native |
30) else |
40) strictfp |
50) volatile |
Applications of Java Programming
- Mobile applications (especially Android apps)
- Desktop applications
- Web applications
- Web servers and application servers
- Games
- Database connection
Why Use Java Programming? or Where java is used?
- Java works on different platforms (Windows, Mac, Linux, Raspberry Pi, etc.)
- It is one of the most popular programming languages in the world
- It is easy to learn and simple to use
- It is open-source and free
- It is secure, fast, and powerful
- It has huge community support (tens of millions of developers)
- Java is an object-oriented language that gives a clear structure to programs and allows code to be reused, lowering development costs.
- As Java is close to C++ and C#, it makes it easy for programmers to switch to Java or vice versa.
Java First Program
In Java, every application begins with a class name, and that class must match the filename.
Let’s create our first Java program, called First.java, which can be done in any text editor (like Notepad, eclipse).
The file should contain a “Hello World” message, which is written with the following code:
First.Java |
The output of the program is:
Hello World
What is the meaning of System.out.println() in Java?
In Java, System.out.println() is a statement that prints the argument passed to it. The println()method display results on the monitor. Usually, a method is invoked by objectname.methodname().
Where System is the class name, it is declared as final. The out is an instance of the System class and is of type PrintStream. Its access specifiers are public and final. It is an instance of java.io.PrintStream. When we call the member, a PrintStream class object creates internally.
Difference between print () and println () methods.
Both methods are used to display the results on the monitor. The print () method displays the result on the console and retains the cursor in the same line. It works only with an argument. The println () method also displays the result on the console but moves the cursor to the next line. It can also work without arguments.
Define the term State, Behavior, and Identity in Java.
State: represents the data (value)of an object.
Behavior: represents the behavior (functionality) of an object such as deposit, withdrawal, etc.
Identity: An object identity is typically implemented via a unique ID. The value of the ID is not visible to the external user. However, it is used internally by the JVM to identify each object uniquely.
What is the Syntax in Java?
The syntax is a particular format for writing a program in Java and the commands to compile and executes it. Without proper knowledge of syntax, it will be difficult for a programmer or a learner to get the desired outputs from a program.
What is an interpreter in Java?
Java interpreter is a computer program (system software)that implements the JVM. It is responsible for reading and executing the program. It is designed in such a way that it can read the source program and translate the source code instruction by instruction. It converts the high-level program into assembly language (machine language).
How does the Java interpreter work?
To convert the byte code into machine code, we deploy the .class file on the Java Virtual Machine (JVM)
The JVM converts that code into machine code using the Java interpreter. The JVM uses the interpreter at runtime, after that it executes the code on the host machine.
Features of Interpreter
It converts the source code into machine language, line by line at run time, without changing the sequence.
An interpreter does not generate intermediate machine code Each error of every line is displayed one by one
When compared to a compiler, the program execution speed is slower Less amount of time is spent on analyzing and processing the program.