🛣️☕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.