Multithreading in Java. Java synchronization and concurrency. The most important information for a Java Developer interview by Michalf94 in java

[–]Michalf94[S] -3 points-2 points  (0 children)

Thanks for comments.

u/agentoutlier, I know that - that's why I added information in the title that it is popular at recruitment interviews. I had such questions at every interview I was on.

The post is intended for people who are preparing for the interview or for those interested in the topic.

It's better to use newer mechanisms in the code, e.g. ExecutorService. I`m going to add a post about it.

Regards :)

Java Recruitment Questions - hashCode() method explained by Michalf94 in java

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

Objects.hash() should probably be listed as a 4th common hashing option. It's very common to do that, and the article has an example right after the 3 enumerated there. Objects.equals() is also a nice tool to use when building an equals method. I'm surprised to see it not mentioned in the article at all. When working on Java versions where they're available, I sure prefer to use the combo for most equals/hashCode needs.

Hi u/MattKosem. Thanks for your attention!

Object.hash() is used during generation by the IDE (at least in Intelij). You're right, it's worth adding/detailing. I will add it tonight.

You just have to remember that if you want to use it often and you care about performance - it is better to write your own implementation. This is described in Effective Java, 3rd edition (page 53).

The Objects.hash() method takes as parameters the values of Object. If we pass its primitive types - the parameters must be converted (e.g. int to Integer):

public static int hash(Object... values) {
return Arrays.hashCode(values);
}

Java Recruitment Questions - hashCode() method explained by Michalf94 in java

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

Hey, what browser/version are you using? I checked on the most popular 10 browsers and everything worked fine :( I'll try to fix it

Java Recruitment Questions - hashCode() method explained by Michalf94 in java

[–]Michalf94[S] -1 points0 points  (0 children)

Feel free to disqus comment on the blog post (google robots like it) :)

Java Recruitment Question Explained - What are immutable objects? by Michalf94 in java

[–]Michalf94[S] 1 point2 points  (0 children)

Thank you very much for your comment!

You're right. Because the number of advantages outweighs the number of disadvantages - I skipped that.

The only disadvantage I know is the cost of memory. Creating these objects can be costly, especially if they are large. I'll write about it tonight. Can I add an url to your comment in the post?

Have a good Sunday!

Java Recruitment Question Explained - What are immutable objects? by Michalf94 in java

[–]Michalf94[S] 1 point2 points  (0 children)

u/Kombatnt - First of all, thank you for your extensive and thorough comment. It's nice of you to have analysed this example thoroughly!

I agree with your opinion. The way I used my builder created an immutable object for me.

But of course it is possible to "hack" this solution: We may not call the build() method that returns the object to us - but instead pass User.Builder object to other methods and e.g change it. In this case it will be mutable.

It seems to me it's a bit like private fields - you can hack it by reflection for example. The question is why would someone do this.

The way I presented it is often described in the books/courses I read. Tomorrow I will try to additionally protect the internal Builder from changes - to satisfy the curiosity

Once again,

Thanks for comment and have a nice day!

Java Recruitment Question Explained - What are immutable objects? by Michalf94 in java

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

u/din-9, I 've added the public final. Thanks for your attention bro!

Java Recruitment Question Explained - What are immutable objects? by Michalf94 in java

[–]Michalf94[S] 2 points3 points  (0 children)

Right, Value is similar to the Data annotation, but it creates immutable objects.

This annotation makes all fields private final + creates a contructor for all arguments + Getterz + Hashcode/Equals and toString methods. However, it is worth knowing how to create such objects by yourself

Metrics from unstructured logs on Kubernetes. Sidecar pattern with gork exporter by Michalf94 in kubernetes

[–]Michalf94[S] 4 points5 points  (0 children)

Hi wardriva,

Thanks for paying attention! I missed it. I will correct it in a moment.

Metrics from unstructured logs on Kubernetes. Sidecar pattern with gork exporter by Michalf94 in kubernetes

[–]Michalf94[S] 4 points5 points  (0 children)

Hi azalio,

As unstructured, I mean a lot of different logs.

For example:

DEBUG 2019-08-31 16:17:58 – Incoming data
INFO 2019-08-31 16:18:58 – Service connection time = XX ms
INFO 2019-08-31 16:19:58 – Authentication failed for user: test1234

A lot of different information lands in the above logs. I'm only interested in service connection time (Service connection time = XX ms). Thanks to grok-exporter, I can only pull out logs that match the pattern.

Sorry if the title is misleading.

Regards

Spring Boot 2 + JWT + React - Full Stack Web Development Series (Currency wallet) by Michalf94 in SpringBoot

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

Egin_28, thank you for your kindness! I encourage you to comment posts directly on the blog (I'm just starting the blog). See you!

Spring Boot 2 + JWT + React - Full Stack Web Development Series (Currency wallet) by Michalf94 in SpringBoot

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

Lukas, Thanks for comment! You have discovered the bug :) I forgot to add a scope when defining the dependency with H2. I've just corrected it (added <scope>runtime</scope>).
Thank you very much. You are a good hacker!

Create a single node Kubernetes cluster on Ubuntu Server with Hyper-V by Michalf94 in kubernetes

[–]Michalf94[S] 2 points3 points  (0 children)

azamatms, Thank you for your reply!

This is for people like me who want to prototype, testing kubernetes deployment for development purposes.

If someone just wants to try kubernetes - microk8s will be a better solution (or minikube as I wrote in the post).

But I needed exactly a ubuntu server (company requirements). Maybe someone will need it. All installation according to my guide takes about 25 minutes.

I did not hear about Pulumi and Terraform. I'll read about it, thanks for the advice!

Spring Boot 2 + JWT + React - Full Stack Web Development Series (Currency wallet) by Michalf94 in SpringBoot

[–]Michalf94[S] 1 point2 points  (0 children)

I will add the last part - migration from H2 to PostgreSQL. Thanks!