Understanding Java Fundamentals: Keywords, Comments, and Escape Characters Explained with Real-World Analogies

navindecr23 15 views 35 slides Oct 28, 2025
Slide 1
Slide 1 of 35
Slide 1
1
Slide 2
2
Slide 3
3
Slide 4
4
Slide 5
5
Slide 6
6
Slide 7
7
Slide 8
8
Slide 9
9
Slide 10
10
Slide 11
11
Slide 12
12
Slide 13
13
Slide 14
14
Slide 15
15
Slide 16
16
Slide 17
17
Slide 18
18
Slide 19
19
Slide 20
20
Slide 21
21
Slide 22
22
Slide 23
23
Slide 24
24
Slide 25
25
Slide 26
26
Slide 27
27
Slide 28
28
Slide 29
29
Slide 30
30
Slide 31
31
Slide 32
32
Slide 33
33
Slide 34
34
Slide 35
35

About This Presentation

This presentation provides a clear and beginner-friendly explanation of three fundamental concepts in Java — Keywords, Comments, and Escape Characters.
Each topic is explained with real-world analogies, code examples, and visual comparisons that help in understanding how Java works behind the scen...


Slide Content

NAVIN PRASATH R
COMMENTS
KEYWORDS
ESCAPE CHARS

TABLE OF
CONTENTS
Comments
1
Keywords
2
Escape chars
3 4
Debugging

Comments in Java are non-executable statements used to explain the code,
improve readability, or temporarily disable code during testing.
They are ignored by the Java compiler and are meant only for programmers.
COMMENTS
TYPES:
Single-line Comment //comments
Multi-line Comment /* comment */
Documentation Comment /**comment*/

public class Singleline {
public static void main(String[] args) {
// This is a single-line comment
Hey
System.out.println("Hello World");
}
}
COMMENTS
public class Multiline {
public static void main(String[] args) {
/* This is a
multi-line comment */
System.out.println("Java Comments");
}
}
/**
* This class performs addition of two numbers.
*/
public class Calculator {
/**
* Adds two integers and returns the sum.
* @param a First number
* @param b Second number
* @return Sum of a and b
*/
public int add(int a, int b) {
return a + b;
}
public static void main(String[] args) {
Calculator c = new Calculator();
System.out.println("Sum = " + c.add(5, 10));
}
}

public class Singleline {
public static void main(String[] args) {
// This is a single-line comment
Hey
System.out.println("Hello World");
}
}
COMMENTS
public class Multiline {
public static void main(String[] args) {
/* This is a
multi-line comment */
System.out.println("Java Comments");
}
}
By Running this command:
javadoc Calculator.java
Then it generates a Files like this:
index.html
stylesheet.css
package-summary.html

COMMENTS

Keywords in Java are reserved words that have a predefined meaning in the
Java programming language.
They are part of the syntax and cannot be used as identifiers (like variable
names, class names, or method names).
KEYWORDS
KEY POINTS:
All keywords are written in lowercase.
There are about 67 keywords in Java.
They define the structure, logic, and behavior of Java programs.

int
float
double
char
boolean
long
short
byte
KEYWORDS
public
private
protected
class
interface
extends
implements
this
if
else
switch
case
default
for
while
do
break
super
new
try
catch
finally
throw
throws
...ETC..,

public class KeywordEg{
public static void main(String[] args) {
int a = 10;
int b = 20;
if (a < b) {
System.out.println("a is less than b");
} else{
System.out.println("a is greater than or equal to b");
}
}
}
KEYWORDSSo the highlighted
words are called as
Keywords in java

Escape characters in Java are special sequences that begin with a backslash (\)
and are used to represent characters that cannot be typed directly or have
special meanings in a string.
They allow the inclusion of new lines, tabs, quotes, backslashes, and other non-
printable or control characters within string literals.
ESCAPE CHARS
USING BACKLASH(\)
CHARACTER

Escape Description Example Output
\n New Line "A\nB"
A
B
\t Tab Space "A\tB" A B
\" Double Quote "She said \"Hi\"" She said "Hi"
\' Single Quote "It\'s fine" It's fine
\\ Backslash "\\path" \path
\r Carriage Return "Hi\rBye" Bye
\b Backspace "AB\bC" AC
\uXXXX Unicode \u20B9 ₹

COMMENTS KEYWORDS ESCAPE CHARS
Imagine you’re
writing an Exam :
you have Rough side
on the right side of
your answer paper
with some scribble
and working out
maths etc..,
The teacher ignores it
while marking —
same as how the
compiler ignores
comments.
Imagine you’re
writing a recipe :
you have certain
fixed instruction
words like “Add”,
“Mix”, “Boil”.
You can’t rename
“Boil” to “Hotify” — the
reader wouldn’t
understand!
Escape characters
are like the control
buttons on your
keyboard:
they don’t print
letters, but they
control how text
appears.
Examples like hitting
“Enter” not to print
enter just to go to
new line like ‘\n’
REAL-TIME ANALOGY

public class T1 {
public static void main(String[] args) {
// System.out.println("This is hidden");
/* System.out.println("Is this too"); */
System.out.println("Hello"); // /* confusing? */ */
}
}
DEBUGGING
public class T2 {
public static void main(String[] args) {
/* This is a /* nested */ comment */
System.out.println("Done");
}
}
public class T3 /*This is comment Msg*/
{
public static void main(String[] args) /* Missing brace? */
{
System.out.println("Hi");
}
}

OUTPUT:
HELLO
DEBUGGING
public class T2 {
public static void main(String[] args) {
/* This is a /* nested */ comment */
System.out.println("Done");
}
}
public class T3 /*This is comment Msg*/
{
public static void main(String[] args) /* Missing brace? */
{
System.out.println("Hi");
}
}

OUTPUT:
HELLO
DEBUGGING
OUTPUT:
Compilation Error X
public class T3 /*This is comment Msg*/
{
public static void main(String[] args) /* Missing brace? */
{
System.out.println("Hi");
}
}

OUTPUT:
HELLO
DEBUGGING
OUTPUT:
HI
OUTPUT:
Compilation Error X

public class Count1 {
private static final int LIMIT = 3;
public static void main(String[] args) {
for (int i = 0; i < LIMIT; i++) {
if (i == 1) {
continue;
}
System.out.println("Value: " + i);
}
}
}
DEBUGGING
abstract class Shape {
abstract void draw();
}
public class Circle extends Shape {
@Override
void draw() {
System.out.println("Drawing Circle");
}
public static void main(String[] args) {
Shape s = new Circle();
s.draw();
}
}

DEBUGGING
abstract class Shape {
abstract void draw();
}
public class Circle extends Shape {
@Override
void draw() {
System.out.println("Drawing Circle");
}
public static void main(String[] args) {
Shape s = new Circle();
s.draw();
}
}
public, static, int, void, class, private , final,
for, if, continue
Total Keywords : 10

public, static, int, void, class, private , final,
for, if, continue
Total Keywords : 10
DEBUGGING
abstract, class, void, public, extends ,static, new
Total Keywords : 7

public class EscapeChar1{
public static void main(String[] args) {
char newLine = '\n';
System.out.println("Hello" + newLine + "World!");
}
}
DEBUGGING
public class EscapeChar3{
public static void main(String[] args) {
System.out.println("A\tB\nC\\tD\\nE");
}
}
public class EscapeChar2 {
public static void main(String[] args) {
System.out.println("12345\rABC");
}
}
public class EscapeChar4{
public static void main(String[] args) {
System.out.println("ABCDE\b\bXY");
}
}

DEBUGGING
public class EscapeChar3{
public static void main(String[] args) {
System.out.println("A\tB\nC\\tD\\nE");
}
}
public class EscapeChar2 {
public static void main(String[] args) {
System.out.println("12345\rABC");
}
}
public class EscapeChar4{
public static void main(String[] args) {
System.out.println("ABCDE\b\bXY");
}
}
OUTPUT:
Hello
World!

DEBUGGING
public class EscapeChar3{
public static void main(String[] args) {
System.out.println("A\tB\nC\\tD\\nE");
}
}
public class EscapeChar4{
public static void main(String[] args) {
System.out.println("ABCDE\b\bXY");
}
}
OUTPUT:
Hello
World!
OUTPUT:
ABC45

DEBUGGING
public class EscapeChar4{
public static void main(String[] args) {
System.out.println("ABCDE\b\bXY");
}
}
OUTPUT:
Hello
World!
OUTPUT:
Hello
World!
OUTPUT:
A B
C\tD\nE

DEBUGGING
OUTPUT:
Hello
World!
OUTPUT:
Hello
World!
OUTPUT:
ABCXY
OUTPUT:
A B
C\tD\nE

FAQs
Q2: Can we use keywords as variable names?
Q1: Are main, String, System, and println keywords?
Q4: Is it necessary to include documentation comments in every class?
Q3: What is a documentation comment used for?

FAQs
Q2: Can we use keywords as variable names?
Q1: Are main, String, System, and println keywords?
Q4: Is it necessary to include documentation comments in every class?
No. They are identifiers and class names, not keywords.
Q3: What is a documentation comment used for?

FAQs
Q2: Can we use keywords as variable names?
Q1: Are main, String, System, and println keywords?
Q4: Is it necessary to include documentation comments in every class?
Q3: What is a documentation comment used for?
No. They are identifiers and class names, not keywords.
No, Java does not allow using keywords as
identifiers (variable names, class names, etc.).

FAQs
Q2: Can we use keywords as variable names?
Q1: Are main, String, System, and println keywords?
Q4: Is it necessary to include documentation comments in every class?
Q3: What is a documentation comment used for?
Used to generate external documentation using the javadoc tool.
No, Java does not allow using keywords as
identifiers (variable names, class names, etc.).
No. They are identifiers and class names, not keywords.

FAQs
Q2: Can we use keywords as variable names?
Q1: Are main, String, System, and println keywords?
Q4: Is it necessary to include documentation comments in every class?
Q3: What is a documentation comment used for?
Used to generate external documentation using the javadoc tool.
No, Java does not allow using keywords as
identifiers (variable names, class names, etc.).
No. They are identifiers and class names, not keywords.
Not required, but good practice for large projects or public APIs.

FAQs
Q6: Why do we need escape characters?
Q5: What are escape characters?
Q8: What happens if we write only one backslash (\) in a string?
Q7: Can escape characters be stored in a variable?

FAQs
Q6: Why do we need escape characters?
Q5: What are escape characters?
Q8: What happens if we write only one backslash (\) in a string?
Special character sequences that start with \ (backslash)
and represent non-printable or special symbols.
Q7: Can escape characters be stored in a variable?

FAQs
Q6: Why do we need escape characters?
Q5: What are escape characters?
Q8: What happens if we write only one backslash (\) in a string?
Special character sequences that start with \ (backslash)
and represent non-printable or special symbols.
To insert newlines, tabs, quotes, or backslashes inside
strings.
Q7: Can escape characters be stored in a variable?

FAQs
Q6: Why do we need escape characters?
Q5: What are escape characters?
Q8: What happens if we write only one backslash (\) in a string?
Q7: Can escape characters be stored in a variable?
Special character sequences that start with \ (backslash)
and represent non-printable or special symbols.
To insert newlines, tabs, quotes, or backslashes inside
strings.
Yes, they can be stored in a char variable.

FAQs
Q6: Why do we need escape characters?
Q5: What are escape characters?
Q8: What happens if we write only one backslash (\) in a string?
Q7: Can escape characters be stored in a variable?
Special character sequences that start with \ (backslash)
and represent non-printable or special symbols.
To insert newlines, tabs, quotes, or backslashes inside
strings.
Yes, they can be stored in a char variable.
It causes a compile-time error, because Java expects
a valid escape sequence after \.

NAVIN PRASATH R
THE END