Java Self Notes
Java Self Notes
Java applications are compiled to byte code that can run on any Java Virtual
Machine. The syntax of Java is similar to c/c++.
(WORA), meaning that compiled Java code can run on all platforms that support
Java without the need for recompilation.
Java History -
Originally C++ was considered to be used in the project but the idea
was rejected for several reasons (For instance C++ required more
memory).
James Gosling and his team called their project “Greentalk” and its
file extension was .gt and later became to known as “OAK”.
Creating Program
We can create a program using Text Editor (Notepad) or IDE
(NetBeans)
class Test
{
public static void main(String []args)
{
System.out.println(“My First Java Program.”);
}
};
File -> Save -> d:\Test.java
What is it?
The Java Virtual Machine, or JVM, is like a translator for Java programs.
How it works:
Writing: First, you write your Java program (like writing a letter).
Compiling: Next, a special tool called the Java compiler (JAVAC) translates your letter into a
language called bytecode.
Running: The JVM then reads and executes this bytecode.
What is it?
Bytecode is the intermediate code generated by the Java compiler from your source
code.
How it works:
After you write your Java program, the compiler turns it into bytecode, which is stored in files
with a .class extension.
Bytecode isn’t readable by humans but can be viewed using tools like javap.
What is it?
The JDK is a complete package that includes everything you need to write, compile,
and run Java programs.
How it works:
It includes the Java compiler, which turns your code into bytecode.
It also has the Java Runtime Environment (JRE), which runs your bytecode.
Plus, it comes with tools for debugging and documentation.
ANDROID - August - 2024 BATCH (MGM)
Why it's important:
You need the JDK installed on your computer to develop Java programs.
What is it?
The JRE is part of the JDK but focuses solely on running Java programs.
How it works:
5. Garbage Collector
What is it?
The Garbage Collector is a tool in Java that automatically manages memory by
removing objects that are no longer in use.
How it works:
6. ClassPath
What is it?
The ClassPath is like a directory where the Java runtime and compiler look for Java
classes and libraries.
How it works:
void : It is the return type, meaning this function will not return anything.
main : main() method is the most important method in a Java program. This is
the method which is executed, hence all the logic must be inside the main()
method. If a java class is not having a main() method, it causes compilation error.
String[] args : This is used to signify that the user may opt to enter parameters to
the Java Program at command line. We can use both String[] args or String
args[]. Java compiler would accept both forms.
Exception Handling
Collections Framework
Concurrency