SlideShare a Scribd company logo
JAVA
PROGRAMMING
NOTE
Author: SOLOMON BOATENG DONKOR
What is Java?
•Developed by Sun Microsystems in 1995,
•Java is one of the most popular and widely used
programming languages and platforms.
•A platform is an environment that helps to develop and
run programs written in any programming language.
•It is owned by Oracle, and more than 3 billion devices
run Java.
It is used for:
•Mobile applications (Especially Android apps)
•Desktop applications
•Web applications
•Web servers and application servers
•Games
•Database connection
•And much, much more!
Features of Java
•Java is a simple language: Java is easy to
learn and its syntax is clear and concise. It is
based on C++ (so it is easier for programmers
who know C++). Java has removed many
confusing and rarely-used features e.g. explicit
pointers, operator overloading, etc. Java also
takes care of memory management and it also
provides an automatic garbage collector. This
collects the unused objects automatically.
•Java is a platform-independent
language: The programs written in Java
language, after compilation, are converted into
an intermediate level language called
the bytecode which is a part of the Java
platform irrespective of the machine on which
the programs run. This makes java highly
portable as its bytecodes can be run on any
machine by an interpreter called the Java Virtual
Machine(JVM) and thus java provides
'reusability of code'.
•Java is an object-oriented programming
language: OOP makes the complete program
simpler by dividing it into a number of objects.
The objects can be used as a bridge to have
data flow from one function to another. We can
easily modify data and function's as per the
requirements of the program.
•Java is a secure language: Java is recognized
for its security features; Java's security features
include
•No use of pointer directly:
•Its robust sandbox environment: A robust
sandbox environment refers to a secure and
isolated execution environment where software
programs can run safely without affecting the
rest of the system. In the context of Java, the
Java Virtual Machine (JVM) provides this
sandbox environment.
• JVM (java Virtual Machine)- Java code is compiled into
bytecode, which is executed by the JVM. The JVM
provides a controlled execution environment, enforcing
strict access controls and runtime security checks. This
isolation helps prevent unauthorized access to system
resources and protects against many common security
threats.
Operating System (OS) Execution: C++ programs are
typically compiled into machine code that directly
interacts with the operating system. While this offers
more direct control over system resources, it also
increases the risk of security vulnerabilities, such as
buffer overflows and memory corruption, if not
managed carefully.
So, while it's true that Java's use of the JVM provides additional
security through its controlled execution environment, it's not
solely because Java uses the JVM for execution. Other security
features inherent to the language and runtime environment
also contribute to Java's reputation for security.
•Java is a multithreaded language: Java can perform many
tasks at once by defining multiple threads. For example, a
program that manages a Graphical User Interface (GUI) while
waiting for input from a network connection uses another
thread to perform and wait's instead of using the default GUI
thread for both tasks. This keeps the GUI responsive.
•Java programs can create applets: Applets are programs that
run in web browsers. But applets support was deprecated
in Java 9 release and has been removed in Java 11 release due
to waning browser support for the Java plugin.
•Java does not require any preprocessor: It does not require
inclusion of header files for creating a Java application.
Features of Java
•Java works on different platforms
(Windows, Mac, Linux, Raspberry Pi, etc.)
•It is one of the most popular programming
languages in the world
•It has a large demand in the current job
market
•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 which 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
The process of Java programming can be simplified in three steps:
•Create the program by typing it into a text editor and saving it to a file -
HelloWorld.java.
•Compile it by typing "javac HelloWorld.java" in the terminal window.
•Execute (or run) it by typing "java HelloWorld" in the terminal window.
The below-given program is the most simple program of Java printing
"Hello World" to the screen. Let us try to understand every bit of code
step by step.
// This is a simple Java program.
// FileName : "HelloWorld.java".
class HelloWorld
{
// Your program begins with a call to main().
// Prints "Hello, World" to the terminal window.
public static void main(String args[])
{
System.out.println("Hello, World");
}
}
Output
Hello, World
Time Complexity: O(1)
Space Complexit: O(1)
The "Hello World!" program consists of three primary components: the HelloWorld
class definition, the main method, and source code comments. The following
explanation will provide you with a basic understanding of the code:
1. Class definition
This line uses the keyword class to declare that a new class is being defined.
class HelloWorld {
//
//Statements
}
2. HelloWorld
It is an identifier that is the name of the class. The entire class definition, including all of its members, will be between
the opening curly brace "{" and the closing curly brace "}".
3. main method:
In the Java programming language, every application must contain a main method. The main function(method) is
the entry point of your Java application, and it's mandatory in a Java program. whose signature in Java is:
public static void main(String[] args)
•public: So that JVM can execute the method from anywhere.
•static: The main method is to be called without an object. The modifiers public and static can be written in either
order.
•void: The main method doesn't return anything.
•main(): Name configured in the JVM. The main method must be inside the class definition. The compiler
executes the codes starting always from the main function.
•String[]: The main method accepts a single argument, i.e., an array of elements of type String.
Like in C/C++, the main method is the entry point for your application and will
subsequently invoke all the other methods required by your program.
The next line of code is shown here. Notice that it occurs inside the main() method.
System.out.println("Hello, World");
This line outputs the string "Hello, World" followed by a new line on the screen. Output is
accomplished by the built-in println( ) method. The System is a predefined class that
provides access to the system, and out is the variable of type output stream connected to
the console.
Comments
They can either be multiline or single-line comments.
// This is a simple Java program.
// Call this file "HelloWorld.java".
This is a single-line comment. This type of comment must begin with // as in C/C++. For
multiline comments, they must begin from /* and end with */.
Important Points
•The name of the class defined by the program is HelloWorld, which is the same as the
name of the file(HelloWorld.java). This is not a coincidence. In Java, all codes must reside
inside a class, and there is at most one public class which contains the main() method.
•By convention, the name of the main class(a class that contains the main method) should
match the name of the file that holds the program.
•Every Java program must have a class definition that matches the filename (class name
and file name should be same).
Compiling the program
•After successfully setting up the environment, we can open a terminal in both
Windows/Unix and go to the directory where the file - HelloWorld.java is present.
•Now, to compile the HelloWorld program, execute the compiler - javac, to specify the
name of the source file on the command line, as shown:
javac HelloWorld.java
•The compiler creates a HelloWorld.class (in the current working directory) that contains
the bytecode version of the program. Now, to execute our program, JVM(Java Virtual
Machine) needs to be called using java, specifying the name of the class file on the
command line, as shown:
java HelloWorld
•This will print "Hello World" to the terminal screen.
JAVA PROGRAMING NOTE FOR BEGINNERS 20242

More Related Content

PPT
Java introduction
PDF
Introduction to Java Programming.pdf
PDF
Java Programming
PDF
Java basics notes
PPTX
OOP with Java
PPTX
JAVA PROGRAMMING-Unit I - Final PPT.pptx
PPTX
2 22CA026_Advance Java Programming_Data types and Operators.pptx
PPTX
unit1.pptx
Java introduction
Introduction to Java Programming.pdf
Java Programming
Java basics notes
OOP with Java
JAVA PROGRAMMING-Unit I - Final PPT.pptx
2 22CA026_Advance Java Programming_Data types and Operators.pptx
unit1.pptx

Similar to JAVA PROGRAMING NOTE FOR BEGINNERS 20242 (20)

PDF
Java Programming Fundamentals: Complete Guide for Beginners
PPTX
1.Intro--Why Java.pptx
PPTX
1 java programming- introduction
PDF
OOPS JAVA.pdf
PPTX
Java fundamentals
PPTX
JAVA PROGRAM CONSTRUCTS OR LANGUAGE BASICS.pptx
PDF
Java basics notes
PDF
Java basics notes
PDF
Java basics notes
PDF
Java programming basics notes for beginners(java programming tutorials)
PPT
Introduction to Core Java feature and its characteristics
PPTX
basic core java up to operator
PDF
Java chapter 1
PPTX
Java ms harsha
PPT
Comp102 lec 3
PPTX
oop unit1.pptx
PPTX
PPTX
Unit1 JAVA.pptx
PPT
this_is_how_to_start_coding_in_java_lang.ppt
PPTX
Java Programming Fundamentals: Complete Guide for Beginners
1.Intro--Why Java.pptx
1 java programming- introduction
OOPS JAVA.pdf
Java fundamentals
JAVA PROGRAM CONSTRUCTS OR LANGUAGE BASICS.pptx
Java basics notes
Java basics notes
Java basics notes
Java programming basics notes for beginners(java programming tutorials)
Introduction to Core Java feature and its characteristics
basic core java up to operator
Java chapter 1
Java ms harsha
Comp102 lec 3
oop unit1.pptx
Unit1 JAVA.pptx
this_is_how_to_start_coding_in_java_lang.ppt
Ad

Recently uploaded (20)

PPTX
Odoo POS Development Services by CandidRoot Solutions
PDF
Design an Analysis of Algorithms I-SECS-1021-03
PDF
How to Choose the Right IT Partner for Your Business in Malaysia
PDF
EN-Survey-Report-SAP-LeanIX-EA-Insights-2025.pdf
PPTX
Agentic AI Use Case- Contract Lifecycle Management (CLM).pptx
PDF
Adobe Premiere Pro 2025 (v24.5.0.057) Crack free
PDF
T3DD25 TYPO3 Content Blocks - Deep Dive by André Kraus
PDF
Odoo Companies in India – Driving Business Transformation.pdf
PPTX
Lecture 3: Operating Systems Introduction to Computer Hardware Systems
PDF
Design an Analysis of Algorithms II-SECS-1021-03
PDF
top salesforce developer skills in 2025.pdf
PDF
Flood Susceptibility Mapping Using Image-Based 2D-CNN Deep Learnin. Overview ...
PDF
Navsoft: AI-Powered Business Solutions & Custom Software Development
PDF
Raksha Bandhan Grocery Pricing Trends in India 2025.pdf
PDF
Digital Strategies for Manufacturing Companies
PDF
System and Network Administraation Chapter 3
PPTX
Agentic AI : A Practical Guide. Undersating, Implementing and Scaling Autono...
PPTX
Reimagine Home Health with the Power of Agentic AI​
PDF
SAP S4 Hana Brochure 3 (PTS SYSTEMS AND SOLUTIONS)
PDF
Audit Checklist Design Aligning with ISO, IATF, and Industry Standards — Omne...
Odoo POS Development Services by CandidRoot Solutions
Design an Analysis of Algorithms I-SECS-1021-03
How to Choose the Right IT Partner for Your Business in Malaysia
EN-Survey-Report-SAP-LeanIX-EA-Insights-2025.pdf
Agentic AI Use Case- Contract Lifecycle Management (CLM).pptx
Adobe Premiere Pro 2025 (v24.5.0.057) Crack free
T3DD25 TYPO3 Content Blocks - Deep Dive by André Kraus
Odoo Companies in India – Driving Business Transformation.pdf
Lecture 3: Operating Systems Introduction to Computer Hardware Systems
Design an Analysis of Algorithms II-SECS-1021-03
top salesforce developer skills in 2025.pdf
Flood Susceptibility Mapping Using Image-Based 2D-CNN Deep Learnin. Overview ...
Navsoft: AI-Powered Business Solutions & Custom Software Development
Raksha Bandhan Grocery Pricing Trends in India 2025.pdf
Digital Strategies for Manufacturing Companies
System and Network Administraation Chapter 3
Agentic AI : A Practical Guide. Undersating, Implementing and Scaling Autono...
Reimagine Home Health with the Power of Agentic AI​
SAP S4 Hana Brochure 3 (PTS SYSTEMS AND SOLUTIONS)
Audit Checklist Design Aligning with ISO, IATF, and Industry Standards — Omne...
Ad

JAVA PROGRAMING NOTE FOR BEGINNERS 20242

  • 2. What is Java? •Developed by Sun Microsystems in 1995, •Java is one of the most popular and widely used programming languages and platforms. •A platform is an environment that helps to develop and run programs written in any programming language. •It is owned by Oracle, and more than 3 billion devices run Java.
  • 3. It is used for: •Mobile applications (Especially Android apps) •Desktop applications •Web applications •Web servers and application servers •Games •Database connection •And much, much more!
  • 4. Features of Java •Java is a simple language: Java is easy to learn and its syntax is clear and concise. It is based on C++ (so it is easier for programmers who know C++). Java has removed many confusing and rarely-used features e.g. explicit pointers, operator overloading, etc. Java also takes care of memory management and it also provides an automatic garbage collector. This collects the unused objects automatically.
  • 5. •Java is a platform-independent language: The programs written in Java language, after compilation, are converted into an intermediate level language called the bytecode which is a part of the Java platform irrespective of the machine on which the programs run. This makes java highly portable as its bytecodes can be run on any machine by an interpreter called the Java Virtual Machine(JVM) and thus java provides 'reusability of code'.
  • 6. •Java is an object-oriented programming language: OOP makes the complete program simpler by dividing it into a number of objects. The objects can be used as a bridge to have data flow from one function to another. We can easily modify data and function's as per the requirements of the program.
  • 7. •Java is a secure language: Java is recognized for its security features; Java's security features include •No use of pointer directly: •Its robust sandbox environment: A robust sandbox environment refers to a secure and isolated execution environment where software programs can run safely without affecting the rest of the system. In the context of Java, the Java Virtual Machine (JVM) provides this sandbox environment.
  • 8. • JVM (java Virtual Machine)- Java code is compiled into bytecode, which is executed by the JVM. The JVM provides a controlled execution environment, enforcing strict access controls and runtime security checks. This isolation helps prevent unauthorized access to system resources and protects against many common security threats. Operating System (OS) Execution: C++ programs are typically compiled into machine code that directly interacts with the operating system. While this offers more direct control over system resources, it also increases the risk of security vulnerabilities, such as buffer overflows and memory corruption, if not managed carefully. So, while it's true that Java's use of the JVM provides additional security through its controlled execution environment, it's not solely because Java uses the JVM for execution. Other security features inherent to the language and runtime environment also contribute to Java's reputation for security.
  • 9. •Java is a multithreaded language: Java can perform many tasks at once by defining multiple threads. For example, a program that manages a Graphical User Interface (GUI) while waiting for input from a network connection uses another thread to perform and wait's instead of using the default GUI thread for both tasks. This keeps the GUI responsive. •Java programs can create applets: Applets are programs that run in web browsers. But applets support was deprecated in Java 9 release and has been removed in Java 11 release due to waning browser support for the Java plugin. •Java does not require any preprocessor: It does not require inclusion of header files for creating a Java application.
  • 10. Features of Java •Java works on different platforms (Windows, Mac, Linux, Raspberry Pi, etc.) •It is one of the most popular programming languages in the world •It has a large demand in the current job market •It is easy to learn and simple to use
  • 11. •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 which 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
  • 12. The process of Java programming can be simplified in three steps: •Create the program by typing it into a text editor and saving it to a file - HelloWorld.java. •Compile it by typing "javac HelloWorld.java" in the terminal window. •Execute (or run) it by typing "java HelloWorld" in the terminal window. The below-given program is the most simple program of Java printing "Hello World" to the screen. Let us try to understand every bit of code step by step.
  • 13. // This is a simple Java program. // FileName : "HelloWorld.java". class HelloWorld { // Your program begins with a call to main(). // Prints "Hello, World" to the terminal window. public static void main(String args[]) { System.out.println("Hello, World"); } }
  • 14. Output Hello, World Time Complexity: O(1) Space Complexit: O(1) The "Hello World!" program consists of three primary components: the HelloWorld class definition, the main method, and source code comments. The following explanation will provide you with a basic understanding of the code:
  • 15. 1. Class definition This line uses the keyword class to declare that a new class is being defined. class HelloWorld { // //Statements } 2. HelloWorld It is an identifier that is the name of the class. The entire class definition, including all of its members, will be between the opening curly brace "{" and the closing curly brace "}".
  • 16. 3. main method: In the Java programming language, every application must contain a main method. The main function(method) is the entry point of your Java application, and it's mandatory in a Java program. whose signature in Java is: public static void main(String[] args) •public: So that JVM can execute the method from anywhere. •static: The main method is to be called without an object. The modifiers public and static can be written in either order. •void: The main method doesn't return anything. •main(): Name configured in the JVM. The main method must be inside the class definition. The compiler executes the codes starting always from the main function. •String[]: The main method accepts a single argument, i.e., an array of elements of type String.
  • 17. Like in C/C++, the main method is the entry point for your application and will subsequently invoke all the other methods required by your program. The next line of code is shown here. Notice that it occurs inside the main() method. System.out.println("Hello, World"); This line outputs the string "Hello, World" followed by a new line on the screen. Output is accomplished by the built-in println( ) method. The System is a predefined class that provides access to the system, and out is the variable of type output stream connected to the console. Comments They can either be multiline or single-line comments. // This is a simple Java program. // Call this file "HelloWorld.java". This is a single-line comment. This type of comment must begin with // as in C/C++. For multiline comments, they must begin from /* and end with */. Important Points
  • 18. •The name of the class defined by the program is HelloWorld, which is the same as the name of the file(HelloWorld.java). This is not a coincidence. In Java, all codes must reside inside a class, and there is at most one public class which contains the main() method. •By convention, the name of the main class(a class that contains the main method) should match the name of the file that holds the program. •Every Java program must have a class definition that matches the filename (class name and file name should be same). Compiling the program •After successfully setting up the environment, we can open a terminal in both Windows/Unix and go to the directory where the file - HelloWorld.java is present. •Now, to compile the HelloWorld program, execute the compiler - javac, to specify the name of the source file on the command line, as shown: javac HelloWorld.java •The compiler creates a HelloWorld.class (in the current working directory) that contains the bytecode version of the program. Now, to execute our program, JVM(Java Virtual Machine) needs to be called using java, specifying the name of the class file on the command line, as shown: java HelloWorld •This will print "Hello World" to the terminal screen.