6)We cannot use all the 50 java language keywords as identifier
names.
7)We can take any length as an identifier length.
8)We can take java class names as identifier names also but it is
highly not recommended.
eparators.
S
() -> Method parameters and conditions
{} -> Represents a block of a code
[ ] -> It is a Array dimension/representation
; -> Terminates the statement
, -> Separates multiple parameters/variables
. -> To call a method, to specify the package name
—-----------------------Day 19 29th july—----------------------------
Returning a value from a java method.
) When will the Java compiler come back to the calling method ?
Q
-> Java Compiler will be coming back to the calling method in the
below scenarios.
After executing all the statements present inside a method
1
2 Whenever the compiler comes across the return statement
immediately it will come back to the calling method.
3 If there is an exception.
Keypoints
A return statementneed not be the last statementinside a
1
method, but itshould be the last executable statementinside a
method.
Inside a void method we can write a return statement without
2
returning anything.
It is not mandatory inside void methods, except void method any
3
other method return types 100% we need to write the return
statement.
4 Return type and return value should be compatible and not same.
We have three control sections
1)Selection
2)Iteration
3)Jump
Character data type should be kept inside single quotes
---------------------Day 20 Video not
—
available—--------------------------------
Understanding the main method why it is declared as public static void
main(String[] args)
public static void main(String[] args)
Word Meaning / Significance
public It is anaccess modifier. It means the method is
accessible fromanywhere. The JVM must be able to
access this method to start the program.
static eans this method belongs to theclass, not to anobject.
M
JVM can call itwithout creating an object.
void eturn type. It means the methoddoes not return any
R
value.
main ethod name. It is theentry pointof every Java
M
program. Execution begins from here.
(,) arentheses used to define theparameter listforthe
P
method.
tring[ P
S arameterto the main method. It is anarray of strings
] args that storescommand-line argumentspassed while
running the program. For example: java Test hello
123will store:
args[0] = "hello"and
args[1] =
"123"
[] argsis anarray.
Shows that
args ariable name (can be any name). Used to access
V
command-line arguments.
Full Meaning in one sentence
he line defines apublic method named
T main, whichreturns
nothing, isstaticso JVM can call it directly, andacceptsan array of
stringsas input arguments.
—-------------------------Day 21 1st august—----------------
N Syntax orrect /
C Explanation
o. Incorrect
1 public static ✔️ Correct S
tandard JVM-recognized
void
signature.
main(String[]
args)
2 public static ✔️ Correct S
pace does not matter; same
void
as above.
main(String []
args)
3 public static ✔️ Correct A
rray brackets can be placed
void
next to type or variable.
main(String
[]args)
4 public static ✔️ Correct A
rray notation after variable
void
name is allowed.
main(String
args[])
5 public static ❌
]cannot precede the type;
[
void
Incorrect must come after type or
main([]String
variable name.
args)
6 public static ✔️ Correct K
ishanis only a variable
void
name; can be anything.
main(String[]
Kishan)
7 static public ✔️ Correct O
rder ofpublicand static
void
does not matter. JVM only
main(String[]
needs correct return type
args)
before method name.
8 public static ❌
VM requires
J void. Different
int
Incorrect return type means JVM willnot
recognizeit as entry point.
main(String[]
args)
9 public static ✔️ Correct f
inalis allowed. It just
final void
prevents overriding (static
main(String[]
already prevents overriding).
args)
Public static ❌
10 ava is case-sensitive. Must be
J
void
Incorrect lowercasepublic .
main(String[]
args)
11
final public ✔️ Correct Modifiers order is flexible.
static void
main(String[]
args)
12
Final public ❌
final
Must be lowercase .
static void
Incorrect
main(String[]
args)
public static ✔️ Correct U
13 ses varargs (
... ) instead of
void
array. Works same as
main(String...
String[] args
.
args)
public static ❌
14 main
VM looks for
J mian
, not .
void
Incorrect Case-sensitive.
mian(String[]
args)
public static ❌
15 rray size cannot be specified
A
void
Incorrect in method parameter
main(String[8]
declarations.
args)
public static ❌
16 ompiles, but JVM does not
C
void
Incorrect int[]in main entry
accept
main(int[]
for JVM String[]
signature; must be .
entry
args)
public static ❌
17 String[]or
Must accept a
void main()
Incorrect String...argument.
18
public void ❌
ust be
M static , otherwise
main(String[] Incorrect
JVM cannot call it without
args)
object creation.
public static ❌
19 ain≠
M main
. Case-sensitive
void
Incorrect method name required.
Main(String[]
args)
ata types
D
There are two types of data types
1)Primitive data types
2)Non primitive/userdefined/referenced data types
1. Primitive Data Types
Primitive types arebasic built-in data types.
Theystore simple values, not objects, and do notrequire extra
memory.
Type Description Example default values
byte -byte integer
1 byte b = 10;
0
value
short 2
-byte integer short s = 200;
0
value
int -byte integer
4 int a = 1000;
0
value
long -byte integer
8 long l = 100000L;
0L
value
float -byte decimal
4 float f = 5.6f; 0.0f
value
-byte decimal
oub 8
d double d = 5.899; 0.0d
le value
oole true / false
b boolean flag = true;
false
an
char ingle
s char c = 'A';
null/space/?
character Default value
/u0000
📌 Characteristics of Primitive Types
● Not objects (stored instack memory)
● Fast and memory efficient
● Cannot have methods
2. Non-Primitive (Reference / Object) Data Types
Non-primitive typesrefer to objects.
They storememory addresses (references)rather thanactual
values.
Type Description Example Default values
String Sequence of characters
String s = "Hello"; null
Array C
ollection of similar int[] arr = {1,2,3};
null
elements
Class U
ser-defined blueprint class Student {...}
null
for objects
Object Instance of a class Student st = new Student();
null
Interfa Contract of methods interface Shape {...}
null
ce
Enum Constant values enum Level {HIGH, LOW}
null
📌 Characteristics of Non-Primitive Types
● Created by the user (except String)
● Stored inheap memory
● Can have methods