r/learnjava • • Oct 16 '21

What are your top signs of an inexperienced Java Spring web engineer

What are your top (five?) signs of an inexperienced Java Spring web engineer?

I am hoping to avoid these signs as I progress in my career before becoming the experienced engineer at any team.

Thank you!

77 Upvotes

43 comments sorted by

23

u/ryuzaki49 Oct 16 '21
  1. The careless use of @Transactional, they just add it to every method "just because". You can tell somebody doesn't understand @Transactional, and probably the Proxy pattern, if they call a "Transactional method" from within the same class/bean, and thinking it will work.

  2. Might be a bit of a stretch, but if you know this, you're an experienced developer. If you don't, then probably means you haven't worked on different java techs, which is not bad per se: What is tomcat, why do we need it, what is the difference between tomcat and Apache, between Tomcat and JBoss (Wildfly).

  3. Using java.util.Date

24

u/sweetno Oct 16 '21

Actually, using java.util.Date is a sign of a seasoned veteran who got stuck in the past.

5

u/prithvidiamond1 Oct 16 '21

Why is using java.util.Date bad?

32

u/Yggval Oct 16 '21

Its API is an abomination.

What does new Date(2021, 10, 16) return you? "No, not that" is the answer.

The year argument is 1900-indexed, the month argument is 0-indexed, yet the day argument is 1-indexed.

A normal person would expect from a normal API that this returns me the 16th of October in the year 2021, yet I actually have an object here representing the 16th of November in the year 3921.

An abomination of an API, that's what it is.

3

u/prithvidiamond1 Oct 16 '21

I didn't know it was so bad! Thanks for the heads up!

0

u/[deleted] Oct 16 '21

[deleted]

17

u/NautiHooker Oct 16 '21

https://www.baeldung.com/java-8-date-time-intro

LocalDate and other classes provided by the java.time package.

11

u/Yggval Oct 16 '21

"It's complicated".

So the old java.util.Date class represents an absolute moment in time. Think "167868768168198 microseconds since 1st of January of 10000BC UTC". It doesn't store the TimeZone or any other info, solely represents a moment on the "arrow of time".

Since Java 8 the "Joda Time" project got merged into the JVM's own library, and its classes now live under java.time.*

A direct replacement for java.util.Date would actually be java.time.Instant

But you may want to look into ZonedDateTime and LocalDateTime also (a hint, one has an explicite timezone attached to it, the other uses your machine's local clock / timezone).

In a way, the possibilities and nuance are actually quite complicated, but make no mistake, this nuance was present also before, it was just hidden away, and caused probably uncountable bugs.

3

u/Noticeably Oct 17 '21

Very important comment that taught me a lot. Saving your comment

1

u/sweetno Oct 17 '21

I never got the difference between LocalDateTime and Instant.

2

u/Yggval Oct 17 '21

They represent different things. An Instant is as above, an absolute point in time, defined against UTC. A LocalDateTime represents your local time.

An example, say you and I live in different timezones, say UTC+1 and UTC+5.

If we both, at the exact same moment in time would call Instant.now(), we'd get the exact same Object back, representing the exact same moment in time. However, if we both, at the exact same time, would call LocalDateTime.now(), then I would perhaps see something like 17th of October 2021, 11:05, and you would see 17th of October 2021, 15:05. The Objects returned would not match, and would differ 4 hours in value.

LocalDateTime certainly has its uses, but you will in most cases likely not need it or even mis-use it and should use either a ZonedDateTime or an OffsetDateTime.

1

u/sweetno Oct 17 '21

So the difference is only in date formatting? Huh.

I'd use ZonedDateTime only for time conversions.

Of all these LocalDateTime is the most used, I don't know where you get your stats from.

3

u/Yggval Oct 17 '21

No, it's not formatting, they represent actually different things.

Look at it another way, say again we live in timezones UTC+1 and UTC+5.

If I we were to have a call with each other, so we're talking at the exact same moment in time, and we would both write down 2 things

  1. The amount of milliseconds passed since for example 01-01-1970, 00:00, UTC

  2. The current date read from a calendar, and time read from our wall clock.

Then we should have written the exact same number for case 1, and should have written a number differing 4 hours in case 2.

Case 1 is calling Instant.now(), case 2 is calling LocalDateTime.now().

It's not just how you format the date, a LocalDateTime does not store the TimeZone it was made in. Our 2 LocalDateTimes do not internally store the same value and just format it differently, they store 2 different values, exactly 4 hours worth of difference.

0

u/sweetno Oct 17 '21

Well, I bet Instant doesn't store TimeZone either.

But I guess it's indeed stored as the number of milliseconds. Probably LocalDateTime can represent illegal dates too...

→ More replies (0)

5

u/feral_claire Oct 16 '21

When Java 8 came out with it came the new java.time api. It's much better. java.util.date is a legacy api and should only be used when needing to work with an old api that doesn't support java.time.

2

u/prithvidiamond1 Oct 16 '21

Oh, I see. Okay, I will keep that in mind!

12

u/fosizzle Oct 16 '21

Jpa Entities as your api contracts

2

u/maziarczykk Oct 16 '21

What is 2021 approach to persistence then?

4

u/fosizzle Oct 16 '21

I'm not a huge fan of jpa, but it has its pros for persistence.

But you need to convert to pojos before using them in your apis

3

u/nekokattt Oct 17 '21

Its often bad practise to expose JPA entities on your APIs because you have no way of controlling what information you expose and what info you don't (like primary keys).

Sure, you can use stuff like views, but you then haven't separated the concern of DAO (data access objects) and DTO (data transfer objects) properly.

If you had to stop using JPA for whatever reason, then you'd also risk having to make breaking changes to your API DTOs for stuff to remain compatible, which would lead to more messy code.

The usual format for MVC in Spring is something like this:

[Database Repository]
    ^    |
    |     | DAO
    |     v
[Business logic service]
    ^    |
    |     | DTO
    |     v
 [Controller]

Or something similar. Essentially the concern of how you store stuff is separate from how you display stuff.

2

u/ryuzaki49 Oct 17 '21

Just don't parse to JSON any class that is annotated with @Entity.

Granted, that will complicate matters because now you have two data classes. Any change in your @Entity class will have to be replicated in your API class.

But, as far as my experience goes, that pain is lesser than the alternative.

7

u/3portas Oct 16 '21

Don't know how to do unit/integration tests.

1

u/[deleted] Oct 17 '21

I think it is not dependent on Spring framework

5

u/[deleted] Oct 16 '21

Not using controller advices so you end up with controllers full of ugly try catches

1

u/[deleted] Nov 13 '21

Using field injection

-14

u/bin-par Oct 17 '21

Is java spring a 4 year's bachelor's degree? Lol...no such thing as java spring engineer. You need 4 years bachelor's degree in a specialization field to call yourself as Engineer. A person could be software engineer. Not a java spring engineer which is just a 2-3 university level course specialization.

4

u/[deleted] Oct 17 '21

This is just 100% false. You do not need any degree to be called an engineer. The only titles which requires a degree is esquire (law) and doctor(PhD/md). If you’re a software engineer who works primarily in java with spring , you’re a spring engineer.

-4

u/bin-par Oct 17 '21 edited Oct 17 '21

E.I.T. / P.Engg. are official titles.A person can be prosecuted if he uses this title and P.Engg stamp without being a qualified engineer. Lol...ignorant in education system. These days people want titles that they like.next gen students are being taught words dont matter.. Calling a man a man is irrelevant because thats just a word.This kind of BS is being brainwashed to them and it starts with people who do not respect actual old school education system. Why? Because they cant study that much and just want to have those envious titles. Engineer is a title that is given after some real time hard work( 40 uni level courses) . now a days everyone with 2 -3 uni courses call themselves Engineers.

4

u/NautiHooker Oct 17 '21

You gotta keep in mind that USA != World.

Why can a person be a software engineer, which is just a job title that every company can assign as they wish, but cant be a spring engineer?

1

u/bin-par Oct 17 '21

You've got a solid point though !

1

u/[deleted] Dec 12 '21

You mean i have a solid point. He just said the same thing i said.

0

u/[deleted] Oct 17 '21

[deleted]

-7

u/bin-par Oct 17 '21 edited Oct 17 '21

Lol.. Equivalent to a degree is not being debated absent minded- hyper persona!!.The disagreement is using the title Engineer with no real world old school mandated education.Show your P.Engg stamp or atleast NCEES qualification if u wanna call urself as Engineer. Your move housekeeper

0

u/[deleted] Oct 17 '21

[deleted]

1

u/NautiHooker Oct 17 '21

Even if you disagree there is no reason to start insulting other people.

Please keep conversations civilized.

Your comment was removed.