SlideShare a Scribd company logo
2
Most read
3
Most read
8
Most read
Unit 1. Programming in Java
• Java Architecture
• Java Buzzwords
• Path and ClassPath variables
• Sample Java Program
• Compiling and Running Java Programs
• User Input in java
Java Programming Fundamentals: Complete Guide for Beginners
What is Java?
• Java is a popular programming language, created in 1995.
• It is owned by Oracle, and more than 3 billion devices run Java.
• It is used for:
• Mobile applications (specially Android apps)
• Desktop applications
• Web applications
• Web servers and application servers
• Games
• Database connection
Java is a high-level, object-oriented programming language
known for its "Write Once, Run Anywhere“
(WORA) capability due to its platform-independent nature.
• Java is a programming language and computing
platform first released by Sun Microsystems in 1995.
• It has evolved from humble beginnings to power a
large share of today’s digital world, by providing the
reliable platform upon which many services and
applications are built. New, innovative products and
digital services designed for the future continue to rely
on Java, as well.
• While most modern Java applications combine the Java
runtime and application together, there are still many
applications and even some websites that will not
function unless you have a desktop Java installed
Why Use 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
Java Components:
• Java Development Kit (JDK)
– Contains tools for developing, debugging, and monitoring
Java applications.
– Includes Java Compiler (javac), Java Runtime Environment
(JRE), and other utilities.
• Java Runtime Environment (JRE)
– Provides the libraries and Java Virtual Machine
(JVM) required to run Java programs.
• Java Virtual Machine (JVM)
– Executes Java bytecode.
– Provides platform independence by converting bytecode
into machine-specific instructions.
How Java Works?
• Write Java code (.java file).
• Compile using javac to generate bytecode
(.class file).
• Execute bytecode using java command, which
runs on JVM.
Java Programming Fundamentals: Complete Guide for Beginners
Java Buzzwords (Key Features)
Java is known for its core features:
• Simple (Easy to learn, no pointers, automatic memory
management)
• Object-Oriented (Supports encapsulation, inheritance,
polymorphism, abstraction)
• Platform-Independent (Bytecode runs on any JVM)
• Robust (Strong memory management, exception
handling)
• Secure (No explicit pointers, bytecode verification)
• Multithreaded (Supports concurrent execution)
• Portable (WORA – Write Once, Run Anywhere)
• High Performance (Just-In-Time compilation)
• Distributed (Supports networking capabilities)
• Dynamic (Supports dynamic class loading)
Environment Setup
To run Java programs, we need to set up JDK and
configure Path and ClassPath.
• Steps to Install Java:
• Download JDK from Oracle’s official website.
• Install JDK (Follow installation steps for your OS).
• Set Environment Variables:
– JAVA_HOME: Points to the JDK installation directory.
– Path: Allows running java and javac from any
directory.
– ClassPath: Specifies where JVM should look
for .class files.
Setting Path (Windows)
• Open System Properties → Environment
Variables.
• Under System Variables, add:
– JAVA_HOME = C:Program FilesJavajdk-
<version>
– Edit Path → Add %JAVA_HOME%bin
Java Programming Fundamentals: Complete Guide for Beginners
Basic Structure of a Java Program
A simple Java program consists of:
// Class Declaration
public class HelloWorld {
// Main Method (Entry Point)
public static void main(String[] args) {
// Print Statement
System.out.println("Hello, World!");
}
}
• Class Name → Must match the filename (HelloWorld.java).
• main() Method → Execution starts here.
• System.out.println() → Prints output to console.
javac HelloWorld.java // Generates HelloWorld.class
java HelloWorld // Executes the program (No .class extension)
How to Get Input from User in Java ?
In Java, there are several ways to accept user input.
The most common methods are:
• Using Scanner class (Recommended for beginners)
• Using BufferedReader class (Efficient for large
inputs)
• Using Console class (For password input, but less
common)
Using Scanner Class (Most Common)
• The Scanner class (from java.util package) is the
easiest way to read input.
Steps:
1) Import Scanner
– import java.util.Scanner;
2) Create a Scanner object
– Scanner scanner = new Scanner(System.in);
3) Read Input
– next() → Reads a single word (stops at space)
– nextLine() → Reads entire line (including spaces)
– nextInt(), nextDouble(), etc. → Reads numbers
import java.util.Scanner;
public class UserInputExample {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.print("Enter your name: ");
String name = scanner.nextLine(); // Reads full line
System.out.print("Enter your age: ");
int age = scanner.nextInt(); // Reads integer
System.out.println("Hello, " + name + "! You are " + age + " years old.");
scanner.close(); // Close scanner to avoid resource leaks
}
}
Enter your name: John Doe
Enter your age: 25
Hello, John Doe! You are 25 years old.
Using BufferedReader (Faster for
Large Inputs)
BufferedReader (from java.io package) is more efficient
but requires more code.
Steps:
1) Import BufferedReader and InputStreamReader
– import java.io.BufferedReader; import
java.io.InputStreamReader; import java.io.IOException;
2) Create a BufferedReader object
– BufferedReader reader = new BufferedReader(new
InputStreamReader(System.in));
3) Read Input
– readLine() → Reads a line as String
– Convert to numbers
using Integer.parseInt(), Double.parseDouble(), etc.
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class BufferedReaderExample {
public static void main(String[] args) throws IOException {
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
System.out.print("Enter your name: ");
String name = reader.readLine(); // Reads full line
System.out.print("Enter your age: ");
int age = Integer.parseInt(reader.readLine()); // Converts String to int
System.out.println("Hello, " + name + "! You are " + age + " years old.");
reader.close(); // Close reader
}
}
Enter your name: Alice
Enter your age: 30
Hello, Alice! You are 30 years old.
Using Console Class (For Password Input)
The Console class (from java.io) is useful for
reading passwords securely (input is hidden).
import java.io.Console;
public class ConsoleExample {
public static void main(String[] args) {
Console console = System.console();
if (console == null) {
System.out.println("Consolenot available!");
return;
}
System.out.print("Enter username: ");
String username = console.readLine();
System.out.print("Enter password: ");
char[] password = console.readPassword(); // Password is hidden
System.out.println("Username: " + username);
System.out.println("Password: " + new String(password)); // Not recommended in real apps
}
}
Enter username: admin
Enter password: (hidden input)
Username: admin
Password: secret123
Java Programming Fundamentals: Complete Guide for Beginners
Java Programming Fundamentals: Complete Guide for Beginners

More Related Content

Similar to Java Programming Fundamentals: Complete Guide for Beginners (20)

PDF
java notes.pdf
JitendraYadav351971
 
PPTX
Welcome-to-Java-Basics to advanced level
RohithH8
 
PPTX
Programming in java ppt
MrsRLakshmiIT
 
PPTX
Programming in java ppt
MrsRBoomadeviIT
 
PPT
Java SpringMVC SpringBOOT (Divergent).ppt
Aayush Chimaniya
 
PDF
Java Programming
Prof. Dr. K. Adisesha
 
PPT
Java for the Beginners
Biswadip Goswami
 
PDF
Introduction to Java Programming.pdf
AdiseshaK
 
PDF
Java interview question
simplidigital
 
PPTX
1.introduction to java
Madhura Bhalerao
 
PPTX
Introduction to java
Java Lover
 
PDF
Introduction java programming
Nanthini Kempaiyan
 
DOCX
OOP-Chap2.docx
NaorinHalim
 
PDF
Java programming material for beginners by Nithin, VVCE, Mysuru
Nithin Kumar,VVCE, Mysuru
 
PPT
Servlets and JavaServer Pages (JSP) from the B.Sc. Computer Science and Infor...
RaguV6
 
DOCX
Srgoc java
Gaurav Singh
 
PPTX
1.Intro--Why Java.pptx
YounasKhan542109
 
ODP
Introduction To Java.
Tushar Chauhan
 
PPTX
Assignmentjsnsnshshusjdnsnshhzudjdndndjd
tusharjain613841
 
PPSX
JAVA.ppsx java code java edv java development
wannabekrishna0
 
java notes.pdf
JitendraYadav351971
 
Welcome-to-Java-Basics to advanced level
RohithH8
 
Programming in java ppt
MrsRLakshmiIT
 
Programming in java ppt
MrsRBoomadeviIT
 
Java SpringMVC SpringBOOT (Divergent).ppt
Aayush Chimaniya
 
Java Programming
Prof. Dr. K. Adisesha
 
Java for the Beginners
Biswadip Goswami
 
Introduction to Java Programming.pdf
AdiseshaK
 
Java interview question
simplidigital
 
1.introduction to java
Madhura Bhalerao
 
Introduction to java
Java Lover
 
Introduction java programming
Nanthini Kempaiyan
 
OOP-Chap2.docx
NaorinHalim
 
Java programming material for beginners by Nithin, VVCE, Mysuru
Nithin Kumar,VVCE, Mysuru
 
Servlets and JavaServer Pages (JSP) from the B.Sc. Computer Science and Infor...
RaguV6
 
Srgoc java
Gaurav Singh
 
1.Intro--Why Java.pptx
YounasKhan542109
 
Introduction To Java.
Tushar Chauhan
 
Assignmentjsnsnshshusjdnsnshhzudjdndndjd
tusharjain613841
 
JAVA.ppsx java code java edv java development
wannabekrishna0
 

Recently uploaded (19)

DOCX
How Digital Marketplaces are Empowering Emerging MedTech Brands
Ram Gopal Varma
 
PPTX
Pastor Bob Stewart Acts 21 07 09 2025.pptx
FamilyWorshipCenterD
 
PDF
Model Project Report_36DR_G&P.pdf for investors understanding
MeetAgrawal23
 
PPTX
AI presentation for everyone in every fields
dodinhkhai1
 
PPTX
presentation on legal and regulatory action
raoharsh4122001
 
PPTX
some leadership theories MBA management.pptx
rkseo19
 
PDF
The Family Secret (essence of loveliness)
Favour Biodun
 
PPTX
STURGEON BAY WI AG PPT JULY 6 2025.pptx
FamilyWorshipCenterD
 
PPTX
Presentationexpressions You are student leader and have just come from a stud...
BENSTARBEATZ
 
PDF
The Origin - A Simple Presentation on any project
RishabhDwivedi43
 
PPTX
Great-Books. Powerpoint presentation. files
tamayocrisgie
 
PDF
From Draft to DSN - How to Get your Paper In [DSN 2025 Doctoral Forum Keynote]
vschiavoni
 
PPTX
Inspired by VeinSense: Supercharge Your Hackathon with Agentic AI
ShubhamSharma2528
 
PPTX
BARRIERS TO EFFECTIVE COMMUNICATION.pptx
shraddham25
 
PDF
Leveraging the Power of Jira Dashboard.pdf
siddharthshukla742740
 
PDF
Committee-Skills-Handbook---MUNprep.org.pdf
SatvikAgarwal9
 
PDF
The Impact of Game Live Streaming on In-Game Purchases of Chinese Young Game ...
Shibaura Institute of Technology
 
PDF
Buy Verified Payoneer Accounts — The Ultimate Guide for 2025 (Rank #1 on Goog...
Buy Verified Cash App Accounts
 
PDF
Buy Verified Coinbase Accounts — The Ultimate Guide for 2025 (Rank #1 on Goog...
Buy Verified Cash App Accounts
 
How Digital Marketplaces are Empowering Emerging MedTech Brands
Ram Gopal Varma
 
Pastor Bob Stewart Acts 21 07 09 2025.pptx
FamilyWorshipCenterD
 
Model Project Report_36DR_G&P.pdf for investors understanding
MeetAgrawal23
 
AI presentation for everyone in every fields
dodinhkhai1
 
presentation on legal and regulatory action
raoharsh4122001
 
some leadership theories MBA management.pptx
rkseo19
 
The Family Secret (essence of loveliness)
Favour Biodun
 
STURGEON BAY WI AG PPT JULY 6 2025.pptx
FamilyWorshipCenterD
 
Presentationexpressions You are student leader and have just come from a stud...
BENSTARBEATZ
 
The Origin - A Simple Presentation on any project
RishabhDwivedi43
 
Great-Books. Powerpoint presentation. files
tamayocrisgie
 
From Draft to DSN - How to Get your Paper In [DSN 2025 Doctoral Forum Keynote]
vschiavoni
 
Inspired by VeinSense: Supercharge Your Hackathon with Agentic AI
ShubhamSharma2528
 
BARRIERS TO EFFECTIVE COMMUNICATION.pptx
shraddham25
 
Leveraging the Power of Jira Dashboard.pdf
siddharthshukla742740
 
Committee-Skills-Handbook---MUNprep.org.pdf
SatvikAgarwal9
 
The Impact of Game Live Streaming on In-Game Purchases of Chinese Young Game ...
Shibaura Institute of Technology
 
Buy Verified Payoneer Accounts — The Ultimate Guide for 2025 (Rank #1 on Goog...
Buy Verified Cash App Accounts
 
Buy Verified Coinbase Accounts — The Ultimate Guide for 2025 (Rank #1 on Goog...
Buy Verified Cash App Accounts
 
Ad

Java Programming Fundamentals: Complete Guide for Beginners

  • 1. Unit 1. Programming in Java • Java Architecture • Java Buzzwords • Path and ClassPath variables • Sample Java Program • Compiling and Running Java Programs • User Input in java
  • 3. What is Java? • Java is a popular programming language, created in 1995. • It is owned by Oracle, and more than 3 billion devices run Java. • It is used for: • Mobile applications (specially Android apps) • Desktop applications • Web applications • Web servers and application servers • Games • Database connection Java is a high-level, object-oriented programming language known for its "Write Once, Run Anywhere“ (WORA) capability due to its platform-independent nature.
  • 4. • Java is a programming language and computing platform first released by Sun Microsystems in 1995. • It has evolved from humble beginnings to power a large share of today’s digital world, by providing the reliable platform upon which many services and applications are built. New, innovative products and digital services designed for the future continue to rely on Java, as well. • While most modern Java applications combine the Java runtime and application together, there are still many applications and even some websites that will not function unless you have a desktop Java installed
  • 5. Why Use 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
  • 6. Java Components: • Java Development Kit (JDK) – Contains tools for developing, debugging, and monitoring Java applications. – Includes Java Compiler (javac), Java Runtime Environment (JRE), and other utilities. • Java Runtime Environment (JRE) – Provides the libraries and Java Virtual Machine (JVM) required to run Java programs. • Java Virtual Machine (JVM) – Executes Java bytecode. – Provides platform independence by converting bytecode into machine-specific instructions.
  • 7. How Java Works? • Write Java code (.java file). • Compile using javac to generate bytecode (.class file). • Execute bytecode using java command, which runs on JVM.
  • 9. Java Buzzwords (Key Features) Java is known for its core features: • Simple (Easy to learn, no pointers, automatic memory management) • Object-Oriented (Supports encapsulation, inheritance, polymorphism, abstraction) • Platform-Independent (Bytecode runs on any JVM) • Robust (Strong memory management, exception handling) • Secure (No explicit pointers, bytecode verification) • Multithreaded (Supports concurrent execution) • Portable (WORA – Write Once, Run Anywhere) • High Performance (Just-In-Time compilation) • Distributed (Supports networking capabilities) • Dynamic (Supports dynamic class loading)
  • 10. Environment Setup To run Java programs, we need to set up JDK and configure Path and ClassPath. • Steps to Install Java: • Download JDK from Oracle’s official website. • Install JDK (Follow installation steps for your OS). • Set Environment Variables: – JAVA_HOME: Points to the JDK installation directory. – Path: Allows running java and javac from any directory. – ClassPath: Specifies where JVM should look for .class files.
  • 11. Setting Path (Windows) • Open System Properties → Environment Variables. • Under System Variables, add: – JAVA_HOME = C:Program FilesJavajdk- <version> – Edit Path → Add %JAVA_HOME%bin
  • 13. Basic Structure of a Java Program A simple Java program consists of: // Class Declaration public class HelloWorld { // Main Method (Entry Point) public static void main(String[] args) { // Print Statement System.out.println("Hello, World!"); } } • Class Name → Must match the filename (HelloWorld.java). • main() Method → Execution starts here. • System.out.println() → Prints output to console. javac HelloWorld.java // Generates HelloWorld.class java HelloWorld // Executes the program (No .class extension)
  • 14. How to Get Input from User in Java ? In Java, there are several ways to accept user input. The most common methods are: • Using Scanner class (Recommended for beginners) • Using BufferedReader class (Efficient for large inputs) • Using Console class (For password input, but less common)
  • 15. Using Scanner Class (Most Common) • The Scanner class (from java.util package) is the easiest way to read input. Steps: 1) Import Scanner – import java.util.Scanner; 2) Create a Scanner object – Scanner scanner = new Scanner(System.in); 3) Read Input – next() → Reads a single word (stops at space) – nextLine() → Reads entire line (including spaces) – nextInt(), nextDouble(), etc. → Reads numbers
  • 16. import java.util.Scanner; public class UserInputExample { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); System.out.print("Enter your name: "); String name = scanner.nextLine(); // Reads full line System.out.print("Enter your age: "); int age = scanner.nextInt(); // Reads integer System.out.println("Hello, " + name + "! You are " + age + " years old."); scanner.close(); // Close scanner to avoid resource leaks } } Enter your name: John Doe Enter your age: 25 Hello, John Doe! You are 25 years old.
  • 17. Using BufferedReader (Faster for Large Inputs) BufferedReader (from java.io package) is more efficient but requires more code. Steps: 1) Import BufferedReader and InputStreamReader – import java.io.BufferedReader; import java.io.InputStreamReader; import java.io.IOException; 2) Create a BufferedReader object – BufferedReader reader = new BufferedReader(new InputStreamReader(System.in)); 3) Read Input – readLine() → Reads a line as String – Convert to numbers using Integer.parseInt(), Double.parseDouble(), etc.
  • 18. import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; public class BufferedReaderExample { public static void main(String[] args) throws IOException { BufferedReader reader = new BufferedReader(new InputStreamReader(System.in)); System.out.print("Enter your name: "); String name = reader.readLine(); // Reads full line System.out.print("Enter your age: "); int age = Integer.parseInt(reader.readLine()); // Converts String to int System.out.println("Hello, " + name + "! You are " + age + " years old."); reader.close(); // Close reader } } Enter your name: Alice Enter your age: 30 Hello, Alice! You are 30 years old.
  • 19. Using Console Class (For Password Input) The Console class (from java.io) is useful for reading passwords securely (input is hidden).
  • 20. import java.io.Console; public class ConsoleExample { public static void main(String[] args) { Console console = System.console(); if (console == null) { System.out.println("Consolenot available!"); return; } System.out.print("Enter username: "); String username = console.readLine(); System.out.print("Enter password: "); char[] password = console.readPassword(); // Password is hidden System.out.println("Username: " + username); System.out.println("Password: " + new String(password)); // Not recommended in real apps } } Enter username: admin Enter password: (hidden input) Username: admin Password: secret123