0% found this document useful (0 votes)
25 views7 pages

Java Self Notes

self notes from java

Uploaded by

prernadjschool
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
Download as docx, pdf, or txt
0% found this document useful (0 votes)
25 views7 pages

Java Self Notes

self notes from java

Uploaded by

prernadjschool
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1/ 7

ANDROID - August - 2024 BATCH (MGM)

Java Concepts - write once, and run anywhere (WORA)

 JAVA was developed by James Gosling at Sun Microsystems Inc in the


May 1995 and later acquired by Oracle Corporation.

 It is a simple programming language. Java makes writing, compiling, and


debugging programming easy.

 It is a class-based, object-oriented programming language and is designed to have


as few implementation dependencies as possible.

 A general-purpose programming language made for developers to write once


run anywhere that is compiled Java code can run on all platforms that
support Java.

 It helps to create reusable code and modular programs.

 Java applications are compiled to byte code that can run on any Java Virtual
Machine. The syntax of Java is similar to c/c++.

 JAVA was developed by James Gosling at Sun Microsystems Inc in the


May 1995 and later acquired by Oracle Corporation.

 (WORA), meaning that compiled Java code can run on all platforms that support
Java without the need for recompilation.

 You willl get a clear review of Java in Historoy of Java


ANDROID - August - 2024 BATCH (MGM)

Java History -

 Java’s history is very interesting. It is a programming language


created in 1991. James Gosling, Mike Sheridan, and Patrick
Naughton, a team of Sun engineers known as the Green team initiated
the Java language in 1991

 Sun Microsystems released its first public implementation in 1996


as Java 1.0. It provides no-cost -run-times on popular platforms.

 Java is an Object-Oriented programming language developed


by James Gosling in the early 1990s.

 The team initiated this project to develop a language for digital


devices such as set-top boxes, television, etc.

 Originally C++ was considered to be used in the project but the idea
was rejected for several reasons (For instance C++ required more
memory).

 Gosling endeavoured to alter and expand C++ however before long


surrendered that for making another stage called Green.

 James Gosling and his team called their project “Greentalk” and its
file extension was .gt and later became to known as “OAK”.

 In 1997, Sun Microsystems approached the ISO standards body and


later formalized Java, but it soon withdrew from the process. At one
time, Sun made most of its Java implementations available without
charge, despite their proprietary software status. Sun generated
revenue from Java through the selling of licenses for specialized
products such as the Java Enterprise System.

 On November 13, 2006, Sun released much of its Java virtual


machine as free, open-source software.

 The principles for creating java programming language were simple,


robust, secured, high-performance, portable, multi-threaded,
interpreted, dynamic, etc. In 1995 Java was developed by James
Gosling, who is known as the Father of Java. Currently, Java is used
in mobile devices, internet programming, games, e-business, etc.
ANDROID - August - 2024 BATCH (MGM)

- Implementation of a Java application program involves a following


step.
They include:
1. Creating the program
2. Compiling the program
3. Running the program

Remember that, before we begin creating the program, the Java


Development Kit (JDK) must be properly installed on our system and
also path will be set.

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

Compiling the program


To compile the program, we must run the Java compiler (javac), with
the name of the source file on “command prompt” like as follows

If everything is OK, the “javac” compiler creates a file called


“Test.class” containing byte code of the program.

Running the program


We need to use the Java Interpreter to run a program.
ANDROID - August - 2024 BATCH (MGM)

1. Java Virtual Machine (JVM)

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.

Why it's important:


Different computers use different types of JVMs, but they all understand the same
bytecode. This means Java programs can run on any computer with the right JVM,
making Java a “write once, run anywhere” language.

2. Bytecode in the Development Process

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.

Why it's important:


Bytecode is like a middle step between your code and the final execution. The JVM
understands this bytecode and can run it on any computer.

3. Java Development Kit (JDK)

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.

4. Java Runtime Environment (JRE)

What is it?
The JRE is part of the JDK but focuses solely on running Java programs.

How it works:

 It includes the JVM, which executes bytecode.


 It also has other components like libraries and plugins needed to run Java applications.

Why it's important:


You need the JRE to run Java programs, but if you want to write and compile Java
programs, you need the full JDK.

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:

 You don’t have to manually delete objects from memory.


 The Garbage Collector identifies and cleans up objects that your program no longer needs.

Why it's important:


It helps prevent memory leaks and makes memory management easier, so you don’t
have to worry about freeing up memory yourself.

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:

 By default, Java has some libraries available.


 If you use external libraries, you need to tell Java where to find them by setting the ClassPath.
ANDROID - August - 2024 BATCH (MGM)
Why it's important:
Setting the ClassPath correctly ensures that your Java programs can find and use the
libraries they need to run.

Explanation of Code Patterns

 class : class keyword is used to declare classes in Java

 public : It is an access specifier. Public means this function is visible to all.

 static : static is again a keyword used to make a function static. To execute a


static function you do not have to create an Object of the class. The main()
method here is called by JVM, without creating any object for class.

 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.

 System.out.println : This is used to print anything on the console like “printf” in


C language.
ANDROID - August - 2024 BATCH (MGM)

Basic Java Concepts

Syntax and Basic Constructs

Data Types: int, float, double, boolean, char, String


Control Structures: if, else, switch, for, while, do-while
Operators: Arithmetic, relational, logical, bitwise

Object-Oriented Programming (OOP)

Classes and Objects: Creating classes, instantiating objects


Inheritance: Extending classes, super, this keyword
Polymorphism: Method overriding, dynamic method dispatch
Encapsulation: Access modifiers (private, protected, public), getters and setters
Abstraction: Abstract classes, interfaces

Exception Handling

Try-Catch-Finally: Handling exceptions using try, catch, finally


Throwing Exceptions: Using throw and throws

Collections Framework

Lists: ArrayList, LinkedList


Sets: HashSet, LinkedHashSet
Maps: HashMap, TreeMap
Iterators: Using Iterator to traverse collections

Concurrency

Threads: Creating and managing threads, Runnable interface


Synchronization: synchronized keyword, lock mechanisms

You might also like