[VV61] Learn Kotlin, synchronized & lock, security matchers, readibility, code review, scrum value
[VV61] The Java Fullstack Newsletter

[VV61] Learn Kotlin, synchronized & lock, security matchers, readibility, code review, scrum value

Learn Kotlin: short introductory course by W3School

Kotlin is a modern, trending programming language.

Kotlin is easy to learn, especially if you already know Java (it is 100% compatible with Java).

Kotlin is used to develop Android apps, server side apps, and much more.

Start learning Kotlin now ?




???JAVA CERTIFICATION QUESTION: synchronized and locks

Given:

public class MsLunch {
    private long c1 = 0;
    private long c2 = 0;
    public void inc1() {
        c1++;
    }
    public void inc2() {
        c2++;
    }
}        

How do you make c1 and c2 incrementing atomic?

* set inc1() and inc2() as synchronized

* set inc1() synchronized while inc2() stays the same

* wrap the body of inc1() and inc2() in a synchronized block with the same lock

* wrap the body of inc1() and inc2() in a synchronized block with different lock

#java #certificationquestion #ocp

https://www.udemy.com/course/ocp-oracle-certified-professional-java-developer-prep/?referralCode=54114F9AD41F127CB99A

Answer: wrap the body of inc1() and inc2() in a synchronized block with different lock

Synchronized statements are useful for improving concurrency with fine-grained synchronization.

Suppose, for example, class MsLunch has two instance fields, c1 and c2, that are never used together.

All updates of these fields must be synchronized, but there's no reason to prevent an update of c1 from being interleaved with an update of c2

— and doing so reduces concurrency by creating unnecessary blocking.

Instead of using synchronized methods or otherwise using the lock associated with this, we create two objects solely to provide locks.

See:

public class MsLunch {
    private long c1 = 0;
    private long c2 = 0;
    private Object lock1 = new Object();
    private Object lock2 = new Object();

    public void inc1() {
        synchronized(lock1) {
            c1++;
        }
    }

    public void inc2() {
        synchronized(lock2) {
            c2++;
        }
    }
}        

Use this idiom with extreme care. You must be absolutely sure that it really is safe to interleave access to the affected fields.

https://docs.oracle.com/javase/tutorial/essential/concurrency/locksync.html




???? SPRING CERTIFICATION QUESTION: Which is the recommended securityMatchers method ?

* antMatchers

* mvcMatchers

* regexMatchers

* requestMatchers

#spring #certificationquestion #vcp

https://www.udemy.com/course/spring-professional-certification-6-full-tests-2v0-7222-a/?referralCode=04B6ED315B27753236AC

Answer: requestMatchers

In Spring Security 5.8, the antMatchers, mvcMatchers, and regexMatchers methods were deprecated in favor of new requestMatchers methods.

The new requestMatchers methods were added to authorizeHttpRequests, authorizeRequests, CSRF configuration, WebSecurityCustomizer and any other places that had the specialized RequestMatcher methods. The deprecated methods are removed in Spring Security 6.

These new methods have more secure defaults since they choose the most appropriate RequestMatcher implementation for your application. In summary, the new methods choose the MvcRequestMatcher implementation if your application has Spring MVC in the classpath, falling back to the AntPathRequestMatcher implementation if Spring MVC is not present (aligning the behavior with the Kotlin equivalent methods).

To start using the new methods, you can replace the deprecated methods with the new ones. For example, the following application configuration:

@Configuration
@EnableWebSecurity
public class SecurityConfig {

    @Bean
    public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception {
        http
            .authorizeHttpRequests((authz) -> authz
                .antMatchers("/api/admin/**").hasRole("ADMIN")
                .antMatchers("/api/user/**").hasRole("USER")
                .anyRequest().authenticated()
            );
        return http.build();
    }

}        

can be changed to:

@Configuration
@EnableWebSecurity
public class SecurityConfig {

    @Bean
    public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception {
        http
            .authorizeHttpRequests((authz) -> authz
                .requestMatchers("/api/admin/**").hasRole("ADMIN")
                .requestMatchers("/api/user/**").hasRole("USER")
                .anyRequest().authenticated()
            );
        return http.build();
    }

}        



QUOTE ???

Master code analysis and refactoring to expose fewer bugs in complex code.



Optimizing Code Readability

Research shows that reading and navigating code consume more time than typing.

To enhance readability, we focus on three optimizations: making code easy to scan, emphasizing expressive layout, and adopting a compact format.

?? Code easy to scan

Leveraging human pattern recognition and standardizing non-essential elements in code makes accidental complexity fade into the background.

Consistent layouts help distinguish code behavior and structure within classes.

?? Code expressive layout

Choosing meaningful names is key to code clarity.

Code layout is also expressive.

Teams often adopt automatic formatters as a starting point, fine-tuning manually.

This hand-finished style aligns with code intent, surpassing automated formatters.

?? Code Compact format

Maximizing on-screen content reduces cognitive load.

Traditional long comments and whitespace were suitable for older technology, but modern IDEs offer syntax coloring and cross-linking.

Every pixel should aid code comprehension, with layout serving this purpose effectively.

?? Code is like poetry: everything in the text has a purpose.




Code review: why and how?

?? The Importance of Code Reviews

Code reviews are crucial for improving code quality and reducing defects.

However, misconceptions and bad experiences have led some programmers to dislike them.

In some organizations, formal reviews are mandatory, with architects or lead developers conducting them, resulting in bottlenecks and inefficiencies.

?? Avoiding Rigid Processes

While some organizations may require rigid code review processes, most benefit from a more flexible approach.

Formal reviews can make reviewees feel judged and slow down the development process.

Instead, the focus should be on sharing knowledge and establishing coding guidelines, promoting collective code ownership.

?? Effective Code Review Practices

Effective code reviews involve gentle, constructive feedback and diverse roles in the review meeting to distribute the workload.

Regular code review days with a rotating reviewee pattern and role switching among team members help maintain engagement.

Involving both newcomers and experts ensures a well-rounded perspective.

?? Making Code Reviews Enjoyable

To ensure successful code reviews, make them enjoyable for the participants.

Emphasize knowledge sharing and maintain an informal atmosphere.

Avoid sarcasm and introduce small, enjoyable elements like sharing a meal, which fosters a positive and productive code review culture.

#programmer #programming #code #review #software




SCRUM: So Where Is The Value??? by Steve Trapps

In everything we do, there should be some value. If not, then why do it?

We need to see the value in what we're doing.

???? A Developer

will see the value when they create the changes they've been asked to work on.

However, is there always value in the work that they've done?

Not if it's buggy and nobody uses it.

?? A Scrum Master

will see the value when they see the team working as a self-organising team,

with the stories being moved into "Done".

???? A Product Owner

will see the value when the release is made and they can explain to the stakeholders what improvements have been made.

What would happen though if the market has moved on and what we thought was valuable no longer is?

??????????????Stakeholders

will see the value when more customers come to use the product as it is the market-leading one.

As you can see, to each person involved in the process the value comes at different times.

However, it is only when the product reaches the customer that the true value is attained

Until that time we're carrying "Value Debt".

Assessing project success often prioritizes timescale ? and budget??, but these are indicators, not the core value.

Meeting deadlines alone doesn't add value?; functionality and worth?? matter more to customers.

No Customer will ever buy something due to the product being there on time if the functionality/worth/value isn't there.

In conclusion: We must never lose the value of why we do something.

#scrum #product #value




???? Digital biting dog

#Student> I'm sorry, my dog ate my homework

#ComputerScienceProfessor> Your dog ate your coding assignment?

#Student> ...

#ComputerScienceProfessor> ...

#Student> It took him a couple of bytes

It took him a couple of bytes

The programming course student is not being truthful when he claims his coding homework was devoured by his dog. The humor in this situation lies in his clever punchline, blending a physical 'bite' with 'digital bytes,' a reference to the unit of memory size in computing, where a byte comprises eight bits.


要查看或添加评论,请登录

Vincent Vauban的更多文章

  • ?? Unrestricted Resource Consumption – API4:2023 ??

    ?? Unrestricted Resource Consumption – API4:2023 ??

    I'm kicking off a series of articles on API Security ?? to help us—developers ????????—better understand and implement…

  • ?? Broken Object Property Level Authorization – API3:2023 ??

    ?? Broken Object Property Level Authorization – API3:2023 ??

    I'm kicking off a series of articles on API Security ?? to help us—developers ????????—better understand and implement…

  • [VV111] The Java 21 Newsletter

    [VV111] The Java 21 Newsletter

    ????2??1?? Dear followers, let's prepare for Java 21 certification together! 1?? How would you answer this question:…

    18 条评论
  • ?? Broken Authentication – API2:2023 ??

    ?? Broken Authentication – API2:2023 ??

    I'm kicking off a series of articles on API Security ?? to help us—developers ????????—better understand and implement…

  • ?? BOLA – The #1 API Security Threat (API1:2023)

    ?? BOLA – The #1 API Security Threat (API1:2023)

    I'm kicking off a series of articles on API Security ?? to help us—developers ??????????—better understand and…

  • [VV110] The Java 21 Newsletter

    [VV110] The Java 21 Newsletter

    ????2??1?? Dear followers, let's prepare for Java 21 certification together! 1?? How would you answer this question:…

  • ?2??4?? Java 24 features with Thiago

    ?2??4?? Java 24 features with Thiago

    (Thanks Thiago Gonzaga ) Here are some insights based on Thiago X content. Java 24: JEP 491 Boosts Virtual Threads! ??…

  • [VV109] The Java 21 Newsletter

    [VV109] The Java 21 Newsletter

    ????2??1?? Dear followers, let's prepare for Java 21 certification together! 1?? How would you answer this question:…

  • [VV108] The Java 21 Newsletter

    [VV108] The Java 21 Newsletter

    ????2??1?? Dear followers, let's prepare for Java 21 certification together! 1?? How would you answer this question:…

    2 条评论
  • [VV107] The Java 21 Newsletter

    [VV107] The Java 21 Newsletter

    ????2??1?? Dear followers, let's prepare for Java 21 certification together! 1?? How would you answer this question:…

社区洞察

其他会员也浏览了