[VV67] Advent of code, static nested class, spring handler, sdkman, REST, URL parts, springboot 3 poll, luhn check, multi-team refinement
????Advent of Code 2023
Advent of Code is an Advent calendar of small programming puzzles for various skill sets and skill levels that can be solved in any programming language you like. People use them for interview prep, company training, university coursework, practice problems, a speed contest, or to challenge each other.
???JAVA CERTIFICATION QUESTION: static nested class
Given:
public class OuterClass{
static class NestedClass{}
public static void main(String[] args){
NestedClass nestedA = new NestedClass();//1
OuterClass.NestedClass nestedB = new OuterClass.NestedClass();//2
NestedClass nestedC = new OuterClass().new NestedClass();//3
NestedClass nestedD = new OuterClass.NestedClass();//4
}
}
Which line fails to compile?
* line 1
* line 2
* line 3
* line 4
* All of the above
#java #certificationquestion #ocp
The wrong syntax is the one in line 3:
NestedClass nestedC = new OuterClass().new NestedClass();
Explanation:
NestedClass nestedA = new NestedClass();
- This line is valid because NestedClass is a static nested class of OuterClass, and it can be instantiated directly.
OuterClass.NestedClass nestedB = new OuterClass.NestedClass();
- This line is also valid. It explicitly mentions the outer class name (OuterClass) followed by the nested class name (NestedClass), and it creates an instance of the static nested class.
NestedClass nestedC = new OuterClass().new NestedClass();
- This line will fail to compile.
It attempts to create an instance of the nested class using the new OuterClass().new NestedClass() syntax, but NestedClass is a static nested class, not an inner (non-static nested) class.
To create an instance of a non-static nested class, you would need an instance of the outer class, but in this case, NestedClass is static.
NestedClass nestedD = new OuterClass.NestedClass();
- This line is similar to line 2 and is also valid.
It creates an instance of the static nested class without requiring an instance of the outer class.
(Note if NestedClass was not static, it would be the syntax at line 3 the right syntax.)
???? SPRING CERTIFICATION QUESTION: HandlerAdapter & HandlerMapping
Which is true about the workflow of mapping an incoming request to a controller method? Choose two.
(A handler method is a method annotated with @RequestMapping/@GetMapping/@PostMapping/... inside a controller class annotated with @Controller/@RestController).
* Incoming requests are mapped to a controller handler method by the DispatcherServlet
* HandlerAdapter defines a strategy for mapping client requests to controllers.
* HandlerMapping handles HTTP requests by invoking the appropriate controller method.
* DispatcherServlet uses components of type HandlerAdapter and HandlerMapping
#spring #certificationquestion #vcp
Right answers:
Incoming requests are mapped to a controller handler method by the DispatcherServlet.
This is true. The DispatcherServlet is the front controller in Spring MVC and is responsible for handling incoming requests.
It uses various components, including HandlerMapping, to determine which controller method (handler method) should handle the request.
DispatcherServlet uses components of type HandlerAdapter and HandlerMapping.
This is true.
DispatcherServlet relies on HandlerAdapter to invoke the appropriate controller method and HandlerMapping to map the request to the correct handler.
Wrong answers:
HandlerAdapter defines a strategy for mapping client requests to controllers.
This statement is false.
HandlerAdapter is responsible for adapting (invoking) the controller method to handle a request, but it does not define the strategy for mapping requests to controllers.
The mapping strategy is the role of HandlerMapping.
HandlerMapping handles HTTP requests by invoking the appropriate controller method.
This statement is false.
HandlerMapping is responsible for determining which controller method (handler method) should handle a specific request by mapping the request to the appropriate handler.
However, HandlerMapping itself does not handle the request; it provides the mapping information to the DispatcherServlet.
The actual handling of the request is done by HandlerAdapter, which is responsible for adapting the request to the controller method.
QUOTE ???
? INSTALL SDKMAN on Windows
SDKMAN is a tool that lets you install and switch between different versions of SDKs for various languages and platforms on Unix systems.
It is inspired by apt, pip, RVM, and Git, and supports Java, Scala, Kotlin, Groovy, Ant, Gradle, Grails, Maven, SBT, Spark, Spring Boot, Vert.x, and more.
A] INSTALL GITBASH
install git bash
copy zip.exe and bzip2.dll from C:\Program Files (x86)\GnuWin32\bin to C:\Program Files\Git\mingw64\bin
reopen git-bash
B] INSTALL SDKMAN
Just launch a new terminal and type in:
$ curl -s "https://get.sdkman.io" | bash
Follow the on-screen instructions to wrap up the installation. Afterward, open a new terminal or run the following in the same shell:
$ source "$HOME/.sdkman/bin/sdkman-init.sh"
Lastly, run the following snippet to confirm the installation's success:
$ sdk version
You should see the output containing the latest script and native versions:
SDKMAN!
script: 5.18.2
native: 0.4.3
C] INSTALL JDK 21
The usage of SDKMan helps you to manage different Java versions on your machine in a simple way, even the last one.
After installing the SDKMan, you should run:
sdk list java
Choose what Java 21 version you want to install, in this example, I will use 21.0.1-oracle
sdk install java 21.0.1-oracle
Then you can set the previous version as the default.
sdk default java 21.0.1-oracle
(Optional) Or only use that on your terminal
sdk use java 21.0.1-oracle
Now you can check the Java version in your environment:
java -version
You should see:
#java version "21.0.1" 2023-10-17 LTS
#Java(TM) SE Runtime Environment (build 21.0.1+12-LTS-29)
#Java HotSpot(TM) 64-Bit Server VM (build 21.0.1+12-LTS-29, #mixed mode, sharing)
(Optional) If not set your JAVA_HOME in your windows environment variables to 'C:\Program Files\Java\jdk-21'
More
?? install on IntelliJ: https://dev.to/danilopdl/using-java-21-on-intellij-36mm
?? Baeldung: https://www.baeldung.com/java-sdkman-intro.
领英推荐
How to (and how not to) design REST APIs by Jeff Schnitzer
Rule #0: DON'T get pedantic
Don't worry about what is or isn't REST; focus on building pragmatic, useful APIs.
Rule #1: DO use plural nouns for collections
?? GET /products/{product_id}
?? GET /product/{product_id}
Rule #2: DON'T add unnecessary path segments
?? GET /v3/application/listings/{listing_id}
?? GET /v3/application/shops/{shop_id}/listings/{listing_id}/properties
The {listing_id} is globally unique; there's no reason for {shop_id} to be part of the URL.
Rule #3: DON'T add .json or other extensions to the url
Rule #4: DON'T return arrays as top-level responses
?? GET /things returns:
{ "data": [{ ...thing1...}, { ...thing2...}] }
?? GET /things returns:
[{ ...thing1...}, { ...thing2...}]
Rule #5: DON'T return map structures
?? GET /things returns:
{
"data": [
{ "id": "KEY1", "foo": "bar" },
{ "id": "KEY2", "foo": "baz" },
{ "id": "KEY3", "foo": "bat" }
]
}
?? GET /things returns:
{
"KEY1": { "id": "KEY1", "foo": "bar" },
"KEY2": { "id": "KEY2", "foo": "baz" },
"KEY3": { "id": "KEY3", "foo": "bat" }
}
Rule #6: DO use strings for all identifiers
Rule #7: DO prefix your identifiers
Stripe's identifiers have two-letter-plus-underscore prefixes.
For customer, it is something like cus_sd9f87gds987, for subscription it is sub_df987gds98fg, for invoice it is in_d98fg7d987fg, and so on. You got the idea.
Rule #8: DON'T use 404 to indicate "not found"
Returning HTTP 404 for "thing not found" is almost like returning HTTP 500 - it could mean the thing doesn't exist, or it could mean something went wrong; the client cannot be sure which.
Rule #9: BE consistent
Please please do your best to keep fields consistent among objects with similar meanings.
Rule #10: DO use a structured error format
My error formats tend to look something like this, roughly shaped like a (Java) exception:
{
"message": "You do not have permission to access this resource",
"type": "Unauthorized",
"types": ["Unauthorized", "Security"],
"cause": { ...recurse for nested any exceptions... }
}
Rule #11: DO provide idempotence mechanisms
Rule #12: DO use ISO8601 strings for timestamps
Someone glancing at "2023-12-21T11:17:12.34Z" might notice that it's a month in the future; someone glancing at 1703157432340 will not.
#rest #api #programming #goodPractices #developer
?? Parts of URL:
for example, if we have this URL :
"https : // blog. vvauban .com /blog/be-a-long-life-learner"
#web #programming #url #urlParts #TIL #vocabulary
???? How did you handle Spring Boot 2.7 end? UPGRADE/ BUY SUPPORT/ DO NOTHING/ NOT CONCERNED
#spring #release #poll #upgrade #springboot3 #java #springboot
Spring Boot end-of-life date??https://endoflife.date/spring-boot
BANKING: The numbers on your credit cards are not random! There is a logic behind all credit card numbers.
All credit cards follow the Luhn algorithm:
1. Starting from the first digit, double every alternate digit
2. If the multiplication results in a two-digit number, add both its digits together.
3. Add all these numbers and the digits we didn’t double in Step 1
4. The sum should be divisible by 10
Let’s run it on the card in the image: 5412 7512 3412 3456
Step 1: Result (10)422 (14)522 6422 64(10)6
Step 2: Result 1422 5522 6422 6416
Step 3: Result: 54
As the result is not divisible by 10, it is not a valid card number.
This algorithm is not intended to detect fraud, but only for typing errors. It can detect a single digit error and most adjacent digit swaps error.
Try it on your card!
Multi-Team Backlog Refinement by Cesario Ramos
What is Product Backlog Refinement?
??activity that Scrum Teams regularly do to clarify potential upcoming Product Backlog Items (PBI)
by
?? But how can you do refinement with multiple teams?
Why multi-team refinement?
Benefits that multi-team refinement can give you:
How to do multi-team refinement?
So, let's say that there are four teams A, B, C, and D.
Then at refinement, I ask the teams to form four new groups, each group consisting of a person from teams A, B, C, and D.
Why? With groups consisting of members from each team, all PBIs are refined by at least one person from every team.
This creates a shared ownership and broad understanding of the PBIs.
Multi-team refinement formats
?? 0. Full Roulette
Each group picks a PBI for refinement and starts refining at their station.
After a timebox -I like 15-minute timeboxes- all groups move to the next station and continue refining where the other group left off;
this is continued until the PBIs are refined or the workshop timebox expires
1. Partial Roulette
Just like Full Roulette, but instead of the whole group moving to another station, 1 person stays at the station.
This person then teaches the new group what was discussed before they continue with refinement.
?? 2. Diverge and merge
One person stays at each station and becomes the teacher.
Then all groups send a person to each of the other stations. So, let's say you gave groups A, B, C and D.
Then 1 person from group A stays at the station to teach back and 1 other person visits group B, another group C, and another group D.
After the teach-back, the persons return to their original group and share their learnings.
???? 3. Teach Back
Each group picks a PBI and refines it.
After the timebox is over, each group teaches their work so far back to the other teams and has a Q&A discussion.
???? Role of the Product Owner and Customers
The Product Owner has to be prepared and understand what is needed from the business perspective.
The PO will discuss overall topics for example a Storymap and also participate in each group when requested.
#scrum #multiTeam #refinement
Learn Scrum ?? https://www.udemy.com/course/professional-scrum-developer-certification-prep-200-question/?referralCode=49CBC321F20A7E381F7C
?? JOKE: variables naming ???
In the initial image titled 'Selecting a Variable Name,' a group of individuals engages in a chaotic brawl, symbolizing the challenge of determining the appropriate variable name. Contrastingly, in the subsequent image named 'Selecting a Loop Variable Name,' a gathering of composed politicians sits in a circle, displaying unanimous agreement on the name 'i' positioned at the center of the circle.
Software That Fits
1 年The headline "static inner class" is misleading because the article actually doesn't use that term, thank goodness.