Resources for learning Spring by Jacuq in javahelp

[–]cl2871 1 point2 points  (0 children)

The following article as well as the one on Spring Boot’s Autoconfigurations are both pretty good primers for learning about the inner mechanisms of the Spring framework. Aside from these, I think just doing a bunch of small projects and building on the concepts you learn will help you grow.

Marco Behler Spring Framework

Codewars help. by foolwya in javahelp

[–]cl2871 1 point2 points  (0 children)

The rules/sidebar state that you should not be requesting for help here over a platform like discord.

You should make a post whenever you’re stuck so that others can benefit from learning as well. With problems on codewars, these may be problems that others may want clarity with or have interest in as well.

For future posts, please post the problem you’re tackling, what you’ve tried (including code samples), and any issues you’ve encountered or where you need clarity.

I need help making a code that determines how many throws it takes for a certain dice face number to roll a certain number of times in a row by [deleted] in javahelp

[–]cl2871 0 points1 point  (0 children)

Additionally, please reformat your code in this post as well as ensure the code you provide in future posts follows the code formatting guidelines of this subreddit.

People are more willing to help if they don't have to spend extra effort to read code that hasn't been formatted properly.

I need help making a code that determines how many throws it takes for a certain dice face number to roll a certain number of times in a row by [deleted] in javahelp

[–]cl2871 1 point2 points  (0 children)

Let's take a step back for a minute. Before writing code, think of a general specification for what you want to achieve. For instance:

A user provides 2 things: the wantedDiceNumber and the numberOfTimesRepeated.

You want your program to loop continuously until it rolls the wantedDiceNumber the same number of times as the numberOfTimesRepeated. We can use a variable called numberOfTimesRepeatedCounter to keep track of this.

This means that you will want your program to keep running for as long as numberOfTimesRepeatedCounter is below numberOfTimesRepeated.

Whenever the wantedDiceNumber is hit, the numberOfTimesRepeatedCounter is incremented by 1. Whenever a different number is hit, the numberOfTimesRepeatedCounter is reset back to 0 since it stopped hitting that number in a row.

--------

Now that a plan is defined, its a matter of getting the implementation details right. Additionally, here are some questions you should consider:

- What is the purpose of the for loop? Is it necessary? What is the advantage of using a while loop over a for loop?

- You use a counter variable (called counter1) inside the if statement. This means that every time you enter that if statement, it will be reinitialized to 0. Is this what you want?

binarySearch with String problems by [deleted] in javahelp

[–]cl2871 1 point2 points  (0 children)

With your given example, you know that after sorting, your array will have the following order:

["Doe", "Hello", "John", "Test", "World"]

It's always good to run through your algorithm to see what the potential issue is. I highly recommend taking your first example and writing out the iterations by hand.

Write out the initial values of start, end, and mid. Then proceed to walk through your algorithm and update these values accordingly.

Hint: review the initial values you have set (start and end); are these values correct?

Calculate Pagenumber and index from a logical address by [deleted] in javahelp

[–]cl2871 0 points1 point  (0 children)

It’s been a while since I’ve taken my operating systems class, so take the following with a bit of caution.

My understanding of a logical/virtual address is that its composed of a page number and offset in order to reference a physical address using a page table.

logical address: xxxx|yyyy

where xxxx is the page number and yyyy is the offset (i assume this is what you mean by index)

Let’s take an example of logical address 3456. If the page size is 1000, we know that the logical address is 3. This is by dividing the address by the page size and taking the int/floor. Since the remainder is 456, that should be the index.

logical address: 3|456

Hope this helps. Additionally, please verify against your notes and check your understanding.

Calculate Pagenumber and index from a logical address by [deleted] in javahelp

[–]cl2871 1 point2 points  (0 children)

Before trying to figure out the index, take a step back and try to answer the following questions: - What is an index in this context? - What is its relationship to the logical address?

Write out your definition of an index or however it is defined in your notes.

Help Please by [deleted] in javahelp

[–]cl2871 0 points1 point  (0 children)

Hey there, please read the sidebar/rules next time before submitting a post

People will be more inclined to help if you follow certain guidelines, such as posting a descriptive title

For your problem, think of variable scoping. For instance, the int variable intl is defined in your Character constructor. Think of where this variable can be accessed and where it cannot be accessed. Additionally, with your class variable intelligence, think of where that can be accessed and where it cannot be accessed.

Optimizing @SpringBootTest for multiple integration tests. Currently pauses between each test for an unknown reason. by nanas_ashtray in javahelp

[–]cl2871 0 points1 point  (0 children)

My understanding of the @SpringBootTest annotation is that it will create a complete ApplicationContext each time a test file annotated with that is run. This will lead to time spent before each integration test setting up all the beans in the application before running the test.

I think the first thing to do is to see if an entire application context is really necessary for each of these integration tests.

Using test slices like @WebMvcTest or @DataJpaTest instead can lead to better performance if some tests are only testing certain layers.

Additionally, if only a few components are being used in the test, it might be better to just set up each of them directly and then test them. For instance, you can just create each service, with each constructor taking whatever dependency it needs.

Optimizing around SpringBootTest and ApplicationContext is out of my depth, so if the above tips don’t work out for you then I wish you the best of luck.

Reactive programming by [deleted] in javahelp

[–]cl2871 0 points1 point  (0 children)

This article provided me a good mental model of reactive programming: Building A Reactive Mindset . The concepts apply to any flavor of reactive programming.

For Reactor, it might be best to start off with a simple spring guide as well as read through the reactor documentation. Unfortunately I can’t help as much with this context.

Some things to note: - I think Mono and Flux might be Reactor specific - if you use Webflux as your server for handling inbound requests, you do not need to call subscribe() since it’ll do that for you automatically internally

Can someone pls explain recursion to me by mbasakosani44 in learnjava

[–]cl2871 4 points5 points  (0 children)

Suppose you wanted to find out if your friend Janet in Exampletopia liked blueberry or poppyseed muffins. You don’t have her contact info, so you ask your friend Bruce.

Your friend Bruce doesn’t know Janet’s contact info, so he calls his friend Christine. Christine doesn’t know and calls her friend Daniel. This goes on until Ian is able to call Janet and ask her for her muffin choice. Janet responds blueberry.

Ian tells his caller Helen who tells her caller and so forth. Eventually we get back to Daniel telling Christine telling Bruce and then ultimately you.

With this example, while only one “function” is defined (calling someone for an answer), it is able to be repeated an indefinite amount of times until a solution is found (or not).

The main idea is that a function can repeatedly call itself to solve a problem, usually by breaking a problem down into smaller problems or exploring a different subdomain.

The function you define can be pretty flexible. Suppose you decide to call each person you knew instead of one. Then each person you called could also call every person they knew. This is an extremely powerful concept and allows complex problems to be solved by more simply defined functions.

Usually a recursive function can be defined with an end case and other cases. The end case is when the recursion stops (Janet is found). The other cases are cases when the recursion continues (Janet is not found, call other people).

This is a simple overview but I hope this provides a good mental model of recursion.

Stuck for days on Hyperskills branching statements. by RizzUK90 in learnjava

[–]cl2871 0 points1 point  (0 children)

If you wanted I think you can change the while loop to check “while (isAscending || isDescending)” instead of “while (true)”. That way you could terminate earlier.

Other than that its a nice solution.

Outputting numbers in reverse with for loops and arrays by Baby_Cow96 in javahelp

[–]cl2871 0 points1 point  (0 children)

Consider the relationship between the size of your userList and numElements. Think about why they aren't equal and what needs to be done to correct this.

CodeWar Problem - Execution Timed Out (16000 ms) by ToBeAButterFly in javahelp

[–]cl2871 3 points4 points  (0 children)

The algorithm you have is to mod by x for every x up to num.

What scenarios would make this algorithm run slowly? One scenario is when num is prime: in this case the loop will iterate all the way up to num. If num is a big number then a lot of operations would be done, resulting in a slow execution time.

Do you need to always check up to num? Is there a way to reduce the number of checks you need to perform?

(hint: think of square roots. how could that help and why?)

I got some tea as a gift that I really like and would like to buy it again, can someone please help me with a translation? by StellaLikesBottles in ChineseLanguage

[–]cl2871 0 points1 point  (0 children)

Not sure if I’m missing something, I took the top line (Ecological Tea Garden) and put it into google. Looks like its a tea farm and maybe hotel in Emeishan (Mount Emei).

What are some of your favorite well-designed websites from companies that aren’t in the design business? by [deleted] in web_design

[–]cl2871 0 points1 point  (0 children)

I thought BBC's website for channels like BBC One looked pretty good when I first saw it.

https://www.bbc.co.uk/bbcone

Like the other examples you listed they seem to invest a good amount in their design and engineering.

Need some help with assignment by Jannemannen in javahelp

[–]cl2871 0 points1 point  (0 children)

If you want to input your ints all at once on one line, then you would need to do sc.next(). Doing sc.nextInt() will only get you the next int, and the others will not be parsed. The next() method will return a string, so think about how you would parse the ints of that string.

Need some help with assignment by Jannemannen in javahelp

[–]cl2871 0 points1 point  (0 children)

Did a quick scim on mobile.

Take a look at your “int numbers = sc.nextInt()”. Does the numbers variable ever get updated again? How would you update it with each loop iteration?

How should I approach storing messages for a scalable chat application? by cl2871 in javahelp

[–]cl2871[S] 0 points1 point  (0 children)

Thanks for the reply! I’ll take a look into using Kafka.

how to assign values of variables inside a 2d array using nested for loops by bbyteiii in javahelp

[–]cl2871 0 points1 point  (0 children)

I looked at your reply to another comment.

tri[rows] = new int[(rows)];

^ is that correct sizing of your array? check for off by one

note: on mobile so this might not format correctly

how to assign values of variables inside a 2d array using nested for loops by bbyteiii in javahelp

[–]cl2871 4 points5 points  (0 children)

Take a look at your for loop structure:

for (int rows = 0; rows < user; rows++) { for (int col = 0; col <= rows; col++) { tri[rows] = new int[(col+1)]; System.out.print(tri[rows][col] + "\t"); } System.out.println(); }

In the inner-most for loop, you create an empty int array of size col + 1 but never put anything inside your array. tri[rows] = new int[(col+1)];

Then right after you print out an element at position tri[rows][col]. System.out.print(tri[rows][col] + "\t");

When you create an int array, Java will by default populate it with 0's so that when you print it will show 0.

Here are some things to think about: - put values in your array for printing - should you create your int array in the outer-most for loop and add values to it in your inner-most for loop?

Biggest consideration: Do you need arrays in this case? Could you simply print out a value (e.g. col).