1
About Java Programming
In this chapter...
Here are the topics we'll cover
Why Java
Java is currently one of the most influential programming language. Java is widely used for developing a variety of applications, including web applications, mobile apps (Android applications are widely built using Java), enterprise software, and many more. Java has a vast ecosystem of libraries, framework, and tools that furture ecnhance its capabilities and productivity for developers.
History of Java
Java was conceived by James Gosling, Patrick Naughton, Chris Warth, Ed Frank, and Mike Sheridan at Sun Microsystems, (now owned by Oracle Corporation) Introducing in 1991. This language was initially called "Oak", but was renamed "Java" in 1995 because of ™ trademark issue. Between the initial implementation of Oak in the fall of 1992 and the public announcement of Java in the spring of 1995, many more people contributed to the design and evolution of the language. Finally in 1996, Java 1.0 was released for Linux, Solaris, Macintosh, and Windows.
The primary motivation was the need for a platform-independent (i.e. architecture-neutral) language that could be used to create software to be embedded in various consumer electronic devices, such as microwave ovens and remote controls.
JVM (Java Virtual Machine)
The most critical component of the JRE is the JVM. The key that allows Java to solve both the security and the pertability problems just described is that the output of a Java compiler is not executable code. Rather, it is bytecode. Bytecode is a highly optimizes set of insteuctions designed to be executed by the Java run-time system, which is called the Java Virtual Machine (JVM). The original JVM was designed as an interpreter for bytecode.
JRE (Java Runtime Environment)
The Java Runtime Environment (JRE) is a set of software tools used for developing Java applications and applets. It encompasses a variety of components that are essential for running Java programs on a computer.
Java Environment
The term Java environment typically refers to the software ecosystem and infrastructure require to develop, compile, debug, and execute Java applications. It encompasses various components and tools that facilitate Java software development.
The Java environment includes everything required to develop, compile, debug, and run Java programs. It consists of:
-
Java Development Kit (JDK): JDK provides the tools necessary for Java development, including the Java compiler
javac
, Java Virtual Machine (JVM), and other utilities and libraries needed for Java development. -
Java Runtime Environment (JRE): JRE includes the JVM and libraries required for running Java applications. It doesn't include development tools like the compiler.
-
Integrated Development Environment (IDE): IDEs like Intellij IDEA, Eclipse, and NetBeans provide a comprehensive environment for Java development, including code editing, debugging, and project management features.
-
Text Editors: While not as feature-rich as IDEs, text editors like Visual Studio Code, Sublime Text, and Atom can also be used for Java development.
After installing JDK, several files and folders gt created on installed location in storage device. The adject location of these folders formation depends on the particular operating system. but by default, the JDK folder is formed under Program Files in windows system.
Folder | Description |
---|---|
bin | The compiler and other Java development tools. |
demo | Demo programs from which you can learn various java features. |
include | It contains files to integrate java with other languages. |
jre | Runtime Environment files are included. |
lib | Library files, including the Java API class library. |
src | The Source code for th java API classes. This folder is only created if you unpack the src.zip file. |
README | The Java readme file in HTML format & the text format. |
LICENSE | The Java license that you agreed to when you downloaded the JDK. |
COPYRIGHT | It is the copyright notice about all. |
Java Source File Structure
Java follows a specific file Structure for organizing source code files. Here's a typical Java Source file structure given below —
-
Package Declaration (Optional): If the Java files belogs to a package, start with the package declaration. Packages helps organizee related classes and avoid naming conflicts.
-
Imports Statements (Optional): Import statements are used to import classes from other packages that are used in the current Java file.
-
Class Declaration: The main body of the Java file contains one or more class declarations. Each class should be declared in its own file, and the file name should match the class name.
-
Main methods (Optional): If the Java file contains the main entry point of the program, it includes th
main
method. -
Other Methods and Fields: Apert from the main method, the file contain other methods, fileds, and inner classes as needed.
Compilation Process
The compilation process in Java involves translating human-readable Java source code into machine-readable bytecode that can be exectued by the Java Vertual Nachine (JVM).
Here's few stages of the compilation process:
-
Stage 1: Writing Java Code: Developers write Java source code files with a
.java
extension using a text editor or an Integrated Development Environment (IDE) like Intellij IDEA, Eclipse, or NetBeans. -
Stage 2: Compilation: Once the Java source code is written, it needs to be compiled. This is done using the Java compiler
javac
, which is included with Java Development Kit (JDK). The compiler translates the.java
files into bytecode files with a.class
extension. -
Stage 3: Compilation Error: During compilation, syntax errors are detected, and if present, compilation fails with error messages. Correct it and recompile.
-
Stage 4: Bytecode Generation: The output of the compilation process is platform-independent bytecode. Bytecode is a set of instructions targeted for the Java Virtual Machine (JVM), rather than for any specific hardware architecture. This bytecode is stored in
.class
files. -
Stage 5: Bytecode Verification: Before execution, the JVM verifies the generated bytecode to ensure that it adheres to Java's safety and security rules. This verification process helps prevent security vulnerabilities aqnd runtime errors.
-
Stage 6: Execution: Once the bytecode is successfully verified, it can be exectued by the Java Vertual Machine (JVM). The JVM loads the bytecode files and executes them line by line, converting them into machine code instructions that can be understood by the underlying operating system and hardware.
- Stage 7: Runtime Optization (Optional): Some JVM implementations perform runtime optimizations, such as just-in-time (JIT) compilation, which translates bytecode into native machine code at runtime for improved performance.
Next Up
2: Programming Structures in Java
Let's know basic structures of Java Programming? such as Classes, Constructors, Methods, Access Specifiers, and many more.
Start Chapter 2 ➔