Win a copy of Spring in Action (5th edition) this week in the Spring forum!

Beeimbolo Paul

Greenhorn
+ Follow
since Dec 01, 2018
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
3
Received in last 30 days
3
Total given
7
Given in last 30 days
7
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Beeimbolo Paul

Take a look at the method toCharArray() on the String class as I think it will help greatly simplify what you are doing.
6 days ago
Why is it so important you don't expose getters?

I prefer Joshua Blochs stance.. getters are fine but if you return something that could be mutated make an immutable copy.

At any rate why does the product object need an update method at at?

Won't this product data be backed by a database table or similar? Or is this not a Web application?
6 days ago
Why do you need to call toArray(), can't you just call size ()?

I might be wrong but the two times you do call this is it not creating a new array copying your arraylist and then you check the size and do nothing with the array?

I am not entirely sure what it is you're trying to do but you can loop a range like this.

IntStream.range(start, end).forEach(
i -> {
       // some player stuff
});

I typed this on my phone so apologies if syntax isn't quite right!
6 days ago
You could get a spring boot app to do this up and running in minutes and you wouldn't need to install tomcat.

1 week ago
Here is an article on how to autowire it: https://www.fortisfio.com/yaml-file-mapping-values-to-object-list-with-spring-boot/

The formatting is off on my example but you get the general idea, anyway hope it helps!
1 week ago
I thought you could just do that with yml?

1 week ago
I wonder if it is because your are component scanning your configuration package to try to autowire, I havent done that before. In the example below the vendor adapter is just created inside the configuration for the entitymanager factory.



I also noticed I am using spring-orm dependency as well (not sure if I have missed this, or you just dont need it?)

1 week ago

Beeimbolo Paul wrote:Can I see what dependencies you have listed in your pom file please?



And your spring configuration class, the one that is creating the JPA beans.
1 week ago
Can I see what dependencies you have listed in your pom file please?
1 week ago
I guess either, what I am trying to say is that I use variables when it makes sense to, and if that means code is easier to read then I would opt for it.

I don't work on systems with low memory requirements so declaring variables isn't any issue. I just use them when I need to and don't specifically try to go out of my way to write code that avoids using them.

On the same note I don't use them when there is no need, for example to hold the result of a call that I then return immediately.

As one of the posts above describes, it's context specific.
1 week ago
I think a good rule of thumb is to use a variable when you need to and that's dependent on what you're working on but if you require multiple calls like in your example I'd prefer to make a single call and assign that result to a variable, it's cleaner to me.

As a real life example the system I work on right now has very stringent code quality checks performed both locally for maven builds and as part of a jenkins build, and also the jenkins job to merge features to develop.

One sonar enforced build breaking rule is that you cannot have multiple return statements in any one method. So in this instance its considered better practice to assign to a single variable which is also the return variable.

I personally find code easier to read when variables are used over lots of nested method calls.
1 week ago
Are you using maven? You can use cargo and start tomcat and your app by running your integration tests against your running application.

You should be doing something like this anyway. Are you writing integration tests?

1 week ago
I would use springboot, you can get a Web app up and running in minutes using the initializr and you don't need to install tomcat.

Writing servlets by hand is OK for learning but you wont find many (if any) companies who are doing this anymore, only legacy systems.
1 week ago
You could use environment variables if you don't want to put passwords into properties files?
1 week ago
Set up an AWS account and you get free tier access for a year.

You can demo it there. If you use terraform to create your environment then as soon as your demo is over you can just destroy all of your infrastructure.
1 week ago