[VV22] increment operator, jdbc template, react routing, behavior driven development, chatGPT unit test, asking questions, Lombok

[VV22] increment operator, jdbc template, react routing, behavior driven development, chatGPT unit test, asking questions, Lombok

??? JAVA CERTIFICATION QUESTION: increment and decrement operators

?? Do Java expressions such as ii[++i] = 0, ii[i++]++, or i = +(i--) give you a headache?

Given the following Calc class:

class Calc {
??Integer i;
??final int[] ii = {0};

??{
????ii[++i] = 0; // line 1
????i--;?????// line 2
????ii[i++]++;??// line 3
????(i--)--;???// line 4
????i = +(i--);?// line 5
??}

}        

Which statement is correct? Choose one.

  • A. Compilation fails at line 1 only.
  • B. Compilation fails at line 2 only.
  • C. Compilation fails at line 3 only.
  • D. Compilation fails at line 4 only.
  • E. Compilation fails at line 5 only.
  • F. Compilation fails at more than one line.
  • G. All lines compile successfully.

#java?#certificationquestion?#ocp

Answer: Compilation fails at line 4 only.

First, line 1 would throw a NullPointerException exception as i is initialized by default with null (and doing ++i with i=null fails).

Still, line 1 does compile, so according to the question, we're good with line 1.

Next, lines 2 and 3 same stories as line 1: it throws an NPE but compiles.

Line 4 would fail to compile.

One of the requirements for using the increment and decrement operators is that the target of such an operator must be in storage that can be updated.

Such a value is sometimes referred to as an L-value, meaning an expression that can be on the left side of an assignment.

In line 4, the expression is (i--)-- and the problem is that while i-- is valid in itself, the resulting expression is simply the numeric value that is contained in the object to which i now refers.

And, in the same way, that you cannot write 3++ (where would you store the result?), you cannot increment or decrement such a simple expression.

Line 5 is syntactically valid, the unary plus operator has no effect.

Conclusion: Compilation fails at line 4 only.

?



???? SPRING CERTIFICATION QUESTION:?When does the JDBC template acquire (and release) a connection ?? - for every method called or once per template?

Answer:

???????????????????????? acquires and releases connection of each called method.

???????????????????????? source code confirms that (look at ????????????????????????#???????????????).

This connection acquiring/releasing strategy is used to minimize connection holding time allowing other clients to utilize free connections.

#spring?#certificationquestion?#vcp

?? ?? JdbcTemplate source code ???https://lnkd.in/ev-N8ph3

?



QUOTE ???

No alt text provided for this image
Gain the ability to analyze complex code and simplify it by refactoring it. It will then be very difficult for bugs to hide.

?



REACT: example of routing ??? in React using the React Router library would be as follows:


import { BrowserRouter as Router, Route, Routes } from "react-router-dom";
import Home from "./components/Home";
import About from "./components/About";


function App() {
? return (
? ? <Router>
? ? ? <Routes>
? ? ? ? <Route exact path="/" element={<Home />} />
? ? ? ? <Route path="/About" element={<About />} />
? ? ? </Routes>
? ? </Router>
? );
}


export default App;        

In this example, the Router component is used to wrap the entire application, and the Route component is used to specify which component should be rendered when the user navigates to a certain path. The exact prop is used to make sure that only the component specified for the root path is rendered when the user is on the root path. The path prop is used to specify the path that the component should be rendered for.

In this example, when the user navigates to the root path (/), the Home component will be rendered. When the user navigates to the /about path, the About component will be rendered.

https://github.com/vinny59200/VV-React-Routing

?



SCRUM DEVELOPER CONCEPT: Behavior-Driven Development ?? ????

Behavior Driven Development is a variation ?? / extension of Test-Driven Development methodology, where the main focus is on the following:

1) Behavioral specifications of the product ?? ?? or application (or its features).

2) User ?? ♂? and System ?? Interactions.

Behavior Driven Development uses Ubiquitous ?? language that can be understood by the developers?? ?? and stakeholders?? ??.

When Behavior Driven Development is adapted to a project, the technical ?? nitty-gritty aspects of the requirements and implementation are outlined in a business-oriented ?? ?? language.

#professionalScrumDeveloper?#theory?#psd1

?



chatGPT: Generating Unit test with chatGPT ????

ChatGPT is a computer program designed to understand and generate human-like text. It can be used for tasks such as language translation, text generation, and creating chatbots. It's a type of Artificial Intelligence model, more specifically it's a language model, that can understand and generate text.

Developers can leverage their coding skills thanks to chatGPT.

Let's see one use case: the generation of a unit test

I first ask chatGPT to generate a Java bean with this prompt (a prompt is a command to give to chatGPT):


Write a Java bean to store a postal address.Use the Lombok annotations to have constructors, getters, setters, and builders.        

chatGPT in reply gave me:


import lombok.Builder;
import lombok.Getter;
import lombok.Setter;


@Builder
@Getter
@Setter
public class Address {
? ? private String street;
? ? private String city;
? ? private String state;
? ? private String zip;
? ? private String country;
}        

which is great ???

Now, let's ask to generate the unit test with the following prompt:

Write a Junit test that tests every fields of the Java bean from the snippet below
import lombok.Builder;
import lombok.Getter;
import lombok.Setter;

@Builder
@Getter
@Setter
public class Address {
    private String street;
    private String city;
    private String state;
    private String zip;
    private String country;
}:        

chatGPT replies with:


import org.junit.Test;
import static org.junit.Assert.assertEquals;


public class AddressTest {
? ? @Test
? ? public void testAddressFields() {
? ? ? ? Address address = Address.builder()
? ? ? ? ? ? ? ? .street("123 Main St")
? ? ? ? ? ? ? ? .city("Anytown")
? ? ? ? ? ? ? ? .state("CA")
? ? ? ? ? ? ? ? .zip("12345")
? ? ? ? ? ? ? ? .country("USA")
? ? ? ? ? ? ? ? .build();


? ? ? ? // Test street field
? ? ? ? assertEquals("123 Main St", address.getStreet());


? ? ? ? // Test city field
? ? ? ? assertEquals("Anytown", address.getCity());


? ? ? ? // Test state field
? ? ? ? assertEquals("CA", address.getState());


? ? ? ? // Test zip field
? ? ? ? assertEquals("12345", address.getZip());


? ? ? ? // Test country field
? ? ? ? assertEquals("USA", address.getCountry());
? ? }
}        

which is great ???

Then I pasted it to IntelliJ and it worked fine. Great job chatGPT! ??

Check it in the video ??[4min]:

https://github.com/vinny59200/GPT-JUnit-test-generation

?



SOFT SKILL: Asking questions??

The big secret it's not the person who's speaking that controls the conversation but the person who's asking the right questions. Such a person has a lot more power.

And if you want to really engage with people, if you want to empathize, if you want to connect: create some questions in advance get used to questions about them, about their interests.

No alt text provided for this image
Create those questions and you will connect more powerfully bonding with people.

  1. Be clear and specific: Clearly state what you want to know and avoid asking broad or open-ended questions.
  2. Do your research: Before asking a question, make sure you have done some background research and are not asking something that has already been answered.
  3. Be respectful and polite: Remember that people are taking time out of their day to help you, so it is important to be polite and respectful in your questioning.
  4. Avoid leading questions: Try to avoid asking questions that suggest a specific answer.
  5. Rephrase and rephrase: rephrase your question if you don't get the answer you need the first time around.

?



POLL: Lombok: FOR or AGAINST ????

No alt text provided for this image
69% are for the use of Lombok in Java Projects

?



????Chuck

Chuck Norris can recite π. Backward.

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

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:…

社区洞察

其他会员也浏览了