What is Java?
?
- Java is a class-based objected-oriented programming language.
- It was developed by James Gosling at Sun Microsystems_Inc in 1995, after taking it into possession by the Oracle Corporation in 2009.
- It is a general-purpose, high-level programming language that helps programmers and developers to write code once and run it anywhere.
- Java is considered both a compiled and interpreted language and also dynamically programming language.
Why use java? or List the features of Java programming language.
?
- Java is a relatively simple and easy-to-use language compared with C/C++ programming language syntax.
- Java is a high- level and dynamically programming language.
- Some features are java supported very well, like
- Cross Platform Independent
- Object-Oriented - (java is not fully supported OOPs Concept)
- Portable
- Simple
- Secure
- Robust
- Distributed
- Architecture neutral
- Multithreading etc.,
So, we can use for java programming language.
Applications of Java
?
- Mobile Applications (Android App Development based on java) Ex: Netfilx, Uber, etc
- Desktop Applications, Ex: Adobe Acrobat Reader
- Web Applications, Ex: Amazon
- Enterprise Applications, Ex: ERP (Enterprise Resource Planning) System, CRM (Customer Relationship Management) System
- Web Server & Application Server, Ex: Apache Tomcat (WS) and WebSphere, WebLogic (AS)
Why is Java not a pure object-oriented language?
?
- Java is not 100% objects-oriented because of the existence of primitive data type.
- In Java some OOps Concept doesn't fully support it, especially the Multiple Inheritance Concept.
What is Architecture neutral?
?
- Write Once, Run Anywhere: Java programs can run on any processor, regardless of vendor or architecture.
- Bytecode Independence: Java compiles into bytecode, which is platform-independent and allows cross-platform execution.
- Universal Compatibility: Ensures Java applications run on different systems without modification.
CORA OR WORA
?
- Compile Once Run Anywhere
- Write Once Run Anywhere
Why java is a dynamic programming language?
?
- If any programming language allows memory allocation is done at Run Time then that programming language is called a Dynamic Programming language. Example: Java, Python, etc.,
- Dynamic Language is designed to optimize programmer efficiency, so you can implement functionally with less code.
- If any programming language allows memory allocation is done at Compile Time then that programming language is called a Static Programming language. Example: C, C++, etc.,
How to run Java on your system?
- Download and install the JDK on your system.
- Check if Java is installed correctly by typing
java --version
orjavac --version
in the command prompt. - If Java isn't installed properly, set the system variable for Java.
- Use an IDE like IntelliJ, Eclipse, or VS Code.
- Save your file with a
.java
extension (e.g.,hello.java
). - Write your code using Java syntax.
- Compile the file by typing
javac filename.java
. - Run the compiled file using
java filename
.
How Java works
?

Java compilation and execution process:
- Compile the Java file with
javac filename.java
to create bytecode (.class
file). - Run the bytecode with
java filename
, which sends it to the JVM. - The JVM converts the bytecode into machine code and executes the program to produce the output.
Main Function
?
- The main function in Java is the entry point of any Java application. It's where the program starts running.
- public: Accessible by any part of the program.
- static: No need to create an object to call it.
- void: It doesn't return any value.
- String[] args: Accepts command-line arguments.
JDK
?
- The Java Development Kit (JDK) is used for developing java applications and applets
- It consists of JRE, compiler, debugger and other tools like archiver, document generator, etc.
- It is responsible for compiling, debugging, and executing.
- It is a platform-independent.
JRE
?
- Java Runtime Environment is provided by Java to run the java applications.
- The components of JRE includes JVM, Class Loader, Bytecode verifier, Interpreter and Other libraries, etc.
- JVM is the most important component of JRE.
- It is a platform-dependent.
JVM
?
- Java Virtual Machine is a part of the JRE.
- It is a specification that provides a run-time environment for Java applications.
- JVM is the responsible for executing bytecode.
- It is converting the byte code to machine code.
- It is a platform-dependent.
Compiler
?
- A compiler is a tool which is used to translates the entire source code into intermediate code, known as bytecode, that bytecode, which is stored in a
.class
file. - The compiled bytecode is platform-independent.
Compilation Time
?
The time taken to convert the entire source code into bytecode.
Execution (or Runtime)
?
The process of converting the .class
file (bytecode) into binary or machine code and running the program with the given input.
Interpreter
?
- Interpreter is used to execute the instructions line-by-line.
- It allows step-by-step execution of the program.
JIT
?
- JIT is an integral part of the JVM.
- It is used to translate the bytecode into native machine code.
- This can result in faster performance and better runtime.
Garbage Collector
?
- Garbage Collector is used to automatically manage the memory.
- It is used to allocate and deallocate memory.
- The developers don't involve these memory allocation process.
Features of garbage collector
?
The features of garbage collection in Java are:
- Automatic Memory Management: It automatically frees up memory by removing objects that are no longer in use.
- No Manual Deallocation: Developers don't need to manually release memory, reducing errors.
- Handles Circular References: It can detect and remove objects that reference each other but are no longer needed.
Allocate and Deallocate Memory
?
In Java, memory is managed automatically:
-
Allocate Memory: Use the
new
keyword to create objects, which allocates memory from the heap.- Example:
Person p = new Person();
- Example:
-
Deallocate Memory: Java uses Garbage Collection to automatically free memory for objects that are no longer used, so you don’t need to manually deallocate it.
Byte Code
?
- Bytecode in Java is the intermediate code generated after you compile your Java program.
- It's not machine-specific but can be understood by the Java Virtual Machine (JVM), which translates it into machine code for execution.
- Bytecode makes Java platform-independent.
Why java is a secured language?
?
- Yes, Java is a secure language because its bytecode is protected, and no one can read it. Only the JVM can read and execute the bytecode.
- The bytecode runs in the JRE (Java Runtime Environment), and it won't work outside the JRE.
- Java's security manager and bytecode verification further enhance its safety.
Java is robust nature, how?
?
- Java uses less hardware, making it better for memory management, performance, and efficiency.