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
Ad

Recommended

Introduction to java programming tutorial
Introduction to java programming tutorial
jackschitze
 
Java Basics.pptx from nit patna ece department
Java Basics.pptx from nit patna ece department
om2348023vats
 
What is Java, JDK, JVM, Introduction to Java.pptx
What is Java, JDK, JVM, Introduction to Java.pptx
kumarsuneel3997
 
Java Notes
Java Notes
Sreedhar Chowdam
 
Java Notes by C. Sreedhar, GPREC
Java Notes by C. Sreedhar, GPREC
Sreedhar Chowdam
 
JAVA PROGRAMING NOTE FOR BEGINNERS 20242
JAVA PROGRAMING NOTE FOR BEGINNERS 20242
boatengsolo963
 
Java
Java
Zeeshan Khan
 
JAVA Module 1______________________.pptx
JAVA Module 1______________________.pptx
Radhika Venkatesh
 
java notes.pdf
java notes.pdf
JitendraYadav351971
 
Welcome-to-Java-Basics to advanced level
Welcome-to-Java-Basics to advanced level
RohithH8
 
Programming in java ppt
Programming in java ppt
MrsRLakshmiIT
 
Programming in java ppt
Programming in java ppt
MrsRBoomadeviIT
 
Java SpringMVC SpringBOOT (Divergent).ppt
Java SpringMVC SpringBOOT (Divergent).ppt
Aayush Chimaniya
 
Java Programming
Java Programming
Prof. Dr. K. Adisesha
 
Java for the Beginners
Java for the Beginners
Biswadip Goswami
 
Introduction to Java Programming.pdf
Introduction to Java Programming.pdf
AdiseshaK
 
Java interview question
Java interview question
simplidigital
 
1.introduction to java
1.introduction to java
Madhura Bhalerao
 
Introduction to java
Introduction to java
Java Lover
 
Introduction java programming
Introduction java programming
Nanthini Kempaiyan
 
OOP-Chap2.docx
OOP-Chap2.docx
NaorinHalim
 
Java programming material for beginners by Nithin, VVCE, Mysuru
Java programming material for beginners by Nithin, VVCE, Mysuru
Nithin Kumar,VVCE, Mysuru
 
Srgoc java
Srgoc java
Gaurav Singh
 
1.Intro--Why Java.pptx
1.Intro--Why Java.pptx
YounasKhan542109
 
Introduction To Java.
Introduction To Java.
Tushar Chauhan
 
Assignmentjsnsnshshusjdnsnshhzudjdndndjd
Assignmentjsnsnshshusjdnsnshhzudjdndndjd
tusharjain613841
 
JAVA.ppsx java code java edv java development
JAVA.ppsx java code java edv java development
wannabekrishna0
 
01slide
01slide
Global Institute of Information Technology
 
Bob Stewart Acts 18 06 18 2025.pptx
Bob Stewart Acts 18 06 18 2025.pptx
FamilyWorshipCenterD
 
ENGLISh.pptxtausug.pptxtausug.pptxtausug.pptx
ENGLISh.pptxtausug.pptxtausug.pptxtausug.pptx
MervieJadeBabao
 

More Related Content

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

java notes.pdf
java notes.pdf
JitendraYadav351971
 
Welcome-to-Java-Basics to advanced level
Welcome-to-Java-Basics to advanced level
RohithH8
 
Programming in java ppt
Programming in java ppt
MrsRLakshmiIT
 
Programming in java ppt
Programming in java ppt
MrsRBoomadeviIT
 
Java SpringMVC SpringBOOT (Divergent).ppt
Java SpringMVC SpringBOOT (Divergent).ppt
Aayush Chimaniya
 
Java Programming
Java Programming
Prof. Dr. K. Adisesha
 
Java for the Beginners
Java for the Beginners
Biswadip Goswami
 
Introduction to Java Programming.pdf
Introduction to Java Programming.pdf
AdiseshaK
 
Java interview question
Java interview question
simplidigital
 
1.introduction to java
1.introduction to java
Madhura Bhalerao
 
Introduction to java
Introduction to java
Java Lover
 
Introduction java programming
Introduction java programming
Nanthini Kempaiyan
 
OOP-Chap2.docx
OOP-Chap2.docx
NaorinHalim
 
Java programming material for beginners by Nithin, VVCE, Mysuru
Java programming material for beginners by Nithin, VVCE, Mysuru
Nithin Kumar,VVCE, Mysuru
 
Srgoc java
Srgoc java
Gaurav Singh
 
1.Intro--Why Java.pptx
1.Intro--Why Java.pptx
YounasKhan542109
 
Introduction To Java.
Introduction To Java.
Tushar Chauhan
 
Assignmentjsnsnshshusjdnsnshhzudjdndndjd
Assignmentjsnsnshshusjdnsnshhzudjdndndjd
tusharjain613841
 
JAVA.ppsx java code java edv java development
JAVA.ppsx java code java edv java development
wannabekrishna0
 
01slide
01slide
Global Institute of Information Technology
 
Welcome-to-Java-Basics to advanced level
Welcome-to-Java-Basics to advanced level
RohithH8
 
Programming in java ppt
Programming in java ppt
MrsRLakshmiIT
 
Java SpringMVC SpringBOOT (Divergent).ppt
Java SpringMVC SpringBOOT (Divergent).ppt
Aayush Chimaniya
 
Introduction to Java Programming.pdf
Introduction to Java Programming.pdf
AdiseshaK
 
Java interview question
Java interview question
simplidigital
 
Introduction to java
Introduction to java
Java Lover
 
Java programming material for beginners by Nithin, VVCE, Mysuru
Java programming material for beginners by Nithin, VVCE, Mysuru
Nithin Kumar,VVCE, Mysuru
 
Assignmentjsnsnshshusjdnsnshhzudjdndndjd
Assignmentjsnsnshshusjdnsnshhzudjdndndjd
tusharjain613841
 
JAVA.ppsx java code java edv java development
JAVA.ppsx java code java edv java development
wannabekrishna0
 

Recently uploaded (20)

Bob Stewart Acts 18 06 18 2025.pptx
Bob Stewart Acts 18 06 18 2025.pptx
FamilyWorshipCenterD
 
ENGLISh.pptxtausug.pptxtausug.pptxtausug.pptx
ENGLISh.pptxtausug.pptxtausug.pptxtausug.pptx
MervieJadeBabao
 
Joint Family And Nuclear Family to .. pdf.
Joint Family And Nuclear Family to .. pdf.
shrujapanchal813
 
ENGLISh.pptxENGLISh.pptxENGLISh.pptxENGLISh.pptx
ENGLISh.pptxENGLISh.pptxENGLISh.pptxENGLISh.pptx
MervieJadeBabao
 
Bob Stewart Acts 17 Study 06 11 2025.pptx
Bob Stewart Acts 17 Study 06 11 2025.pptx
FamilyWorshipCenterD
 
Analysis of Tausog Language English.pptx
Analysis of Tausog Language English.pptx
MervieJadeBabao
 
Briefing on the upcoming UNFSS +4 Stocktake
Briefing on the upcoming UNFSS +4 Stocktake
Francois Stepman
 
puskhar camel yauvh on the hot wheels for
puskhar camel yauvh on the hot wheels for
nandanitiwari82528
 
FL Studio Crack Full Version [Latest 2025]
FL Studio Crack Full Version [Latest 2025]
Jackson lithms
 
Types of Information Sources (Primary, Secondary, and Tertiary Sources)
Types of Information Sources (Primary, Secondary, and Tertiary Sources)
jenicahmendoza1
 
The Love of a Father 06 15 2025.pptx
The Love of a Father 06 15 2025.pptx
FamilyWorshipCenterD
 
PEN TO PODIUM powerpoint presentation.pptx
PEN TO PODIUM powerpoint presentation.pptx
Vanessa accad
 
Japan's Media and Telecom Markets: Evolution, Global Competition, and NTT Law...
Japan's Media and Telecom Markets: Evolution, Global Competition, and NTT Law...
Toshiya Jitsuzumi
 
What say you - ethical issues in research
What say you - ethical issues in research
ssuser8aff01
 
Google Algorithm Updates – A Complete Guide for Digital Marketing Students.pdf
Google Algorithm Updates – A Complete Guide for Digital Marketing Students.pdf
Nithinks37
 
case ObGy - Post term pregnacy.pptx case presentation
case ObGy - Post term pregnacy.pptx case presentation
fortuneassey
 
Josaya - Abstract for the research of the youth development.pdf
Josaya - Abstract for the research of the youth development.pdf
Josaya Injesi
 
AC_Manufacturer_Strategy_Commercial_Government.pptx
AC_Manufacturer_Strategy_Commercial_Government.pptx
ajajsain
 
Personal letter personal letter personal letter.pptx
Personal letter personal letter personal letter.pptx
GedeJuliana2
 
Heating_Effect_of_Solar_Corona_Presentation.pptx
Heating_Effect_of_Solar_Corona_Presentation.pptx
Hanumamshukla
 
Bob Stewart Acts 18 06 18 2025.pptx
Bob Stewart Acts 18 06 18 2025.pptx
FamilyWorshipCenterD
 
ENGLISh.pptxtausug.pptxtausug.pptxtausug.pptx
ENGLISh.pptxtausug.pptxtausug.pptxtausug.pptx
MervieJadeBabao
 
Joint Family And Nuclear Family to .. pdf.
Joint Family And Nuclear Family to .. pdf.
shrujapanchal813
 
ENGLISh.pptxENGLISh.pptxENGLISh.pptxENGLISh.pptx
ENGLISh.pptxENGLISh.pptxENGLISh.pptxENGLISh.pptx
MervieJadeBabao
 
Bob Stewart Acts 17 Study 06 11 2025.pptx
Bob Stewart Acts 17 Study 06 11 2025.pptx
FamilyWorshipCenterD
 
Analysis of Tausog Language English.pptx
Analysis of Tausog Language English.pptx
MervieJadeBabao
 
Briefing on the upcoming UNFSS +4 Stocktake
Briefing on the upcoming UNFSS +4 Stocktake
Francois Stepman
 
puskhar camel yauvh on the hot wheels for
puskhar camel yauvh on the hot wheels for
nandanitiwari82528
 
FL Studio Crack Full Version [Latest 2025]
FL Studio Crack Full Version [Latest 2025]
Jackson lithms
 
Types of Information Sources (Primary, Secondary, and Tertiary Sources)
Types of Information Sources (Primary, Secondary, and Tertiary Sources)
jenicahmendoza1
 
The Love of a Father 06 15 2025.pptx
The Love of a Father 06 15 2025.pptx
FamilyWorshipCenterD
 
PEN TO PODIUM powerpoint presentation.pptx
PEN TO PODIUM powerpoint presentation.pptx
Vanessa accad
 
Japan's Media and Telecom Markets: Evolution, Global Competition, and NTT Law...
Japan's Media and Telecom Markets: Evolution, Global Competition, and NTT Law...
Toshiya Jitsuzumi
 
What say you - ethical issues in research
What say you - ethical issues in research
ssuser8aff01
 
Google Algorithm Updates – A Complete Guide for Digital Marketing Students.pdf
Google Algorithm Updates – A Complete Guide for Digital Marketing Students.pdf
Nithinks37
 
case ObGy - Post term pregnacy.pptx case presentation
case ObGy - Post term pregnacy.pptx case presentation
fortuneassey
 
Josaya - Abstract for the research of the youth development.pdf
Josaya - Abstract for the research of the youth development.pdf
Josaya Injesi
 
AC_Manufacturer_Strategy_Commercial_Government.pptx
AC_Manufacturer_Strategy_Commercial_Government.pptx
ajajsain
 
Personal letter personal letter personal letter.pptx
Personal letter personal letter personal letter.pptx
GedeJuliana2
 
Heating_Effect_of_Solar_Corona_Presentation.pptx
Heating_Effect_of_Solar_Corona_Presentation.pptx
Hanumamshukla
 
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