๐ฃ๏ธโ2๏ธโฃ1๏ธโฃ Dear followers, let's prepare for Java 21 certification together!
- โฟ For loop body
- ๐พ Records members
- โ Period
- ๐ฆฎ record guideline
#vvauban #newsletter #java #java21
QUESTION 1๏ธโฃ
How would you answer this question:
Given:
What will be printed?
A) 0 1 2
B) 1 2
C) 1 2 3
D) It throws an exception at runtime.
E) Compilation fails.
#PathToJava21 #java #certification
๐ก Solution
Let's walk through it carefully:
The given code is:
In a for loop, the structure is:
Here:
๐ฃ Initialization: var i = 0
๐ฃ Condition: i ใ 3
๐ฃ Update: System.out.print(i + " ")
๐ฃ Body: i++
Step-by-step execution:
1) i = 0
2) Check i ใ 3 โ 0 ใ 3 โ true
3) Execute body: i++ โ i = 1
4) Update step: System.out.print(i + " ") โ prints 1
5) Back to condition check: i = 1
6) Check i ใ 3 โ 1 ใ 3 โ true
7) Execute body: i++ โ i = 2
8) Update step: System.out.print(i + " ") โ prints 2
9) Back to condition check: i = 2
10)Check i ใ 3 โ 2 ใ 3 โ true
11)Execute body: i++ โ i = 3
12)Update step: System.out.print(i + " ") โ prints 3
13)Back to condition check: i = 3
14)Check i ใ 3 โ 3 ใ 3 โ false
15)Loop exits.
Thus, the output is:
1 2 3
Answer: โ C) 1 2 3
The for Statement: https://docs.oracle.com/javase/tutorial/java/nutsandbolts/for.html
(Controlling Program Flow)
LESSON 1๏ธโฃ
๐ฌ Java Record Classes Explained with French Actors! ๐ซ๐ท | Custom Accessors, Static Members & More ๐ง๐ป
In this fun and practical Java tutorial, we dive into the world of record classes using a cinematic twist โ featuring French actors as our data models! ๐ฅ
You'll learn:
โ How to declare and customize accessor methods
โ What static members are (including static fields & methods)
โ What you cannot do in records โ
โ How to use nested record classes and instance methods
โ What a native method is โ and why itโs not allowed in records! โ ๏ธ
From Marion Cotillard to award-winning code examples ๐, this video is a perfect blend of Java fundamentals and creative learning!
๐จ๐ซ Great for beginners and intermediate Java developers!
๐ Code examples included
๐ ๏ธ Real-world analogies
๐ Learn faster with themed examples
๐ Don't forget to like, comment, and subscribe if you enjoy coding with a touch of French cinema!
#Java #RecordClass #JavaTutorial #FrenchCinema #JavaProgramming #LearnJava #JavaRecords #MarionCotillard #CodingWithStyle #JavaDev #DeveloppeurJava #ProgrammationJava #CodingTutorial #JavaBeginner #CodeWithMe ๐ฅ๐ป๐ฟ
Prepare your Java certification: https://www.udemy.com/course/ocp-oracle-certified-professional-java-developer-prep/?referralCode=54114F9AD41F127CB99A
QUESTION 2๏ธโฃ
How would you answer this question:
Given:
What will be printed?
A) P1Y12M1D
B) P1Y13M1D
C) P2Y1M1D
D) It throws an exception at runtime.
E) Compilation fails.
#PathToJava21 #java #certification
๐ก Solution
Let's walk through it carefully:
You have:
๐ฃ Period.of(1, 13, 1) means 1 year, 13 months, and 1 day.
๐ฃ normalized() adjusts months to be within 0-11 by converting extra months into years.
- 13 months โ 1 year and 1 month (because 12 months = 1 year).
๐ฃ So 1 year + 1 year = 2 years, and you still have 1 month and 1 day.
Thus, after normalization, the result is:
P2Y1M1D
Final Answer:
โ C) P2Y1M1D
(Controlling Program Flow)
LESSON 2๏ธโฃ
Avoid in-line text blocks within complex expressions, as doing so can distort readability. Consider refactoring to a local variable or to a static final field.