r/javahelp • • Jun 05 '20

How does Java and Javascript work together in building websites?

I'm learning Java right now, but eventually I want to learn Javascript as well to be able to build website and servers. But I'm not sure how they actually come together.

It will be great if someone can eli5 using an example... let's say I want to make a website for a bakery shop. How can I use Java and Javascript to create a website that enables me to receive orders, ship them out to my customers, and store the data somewhere in my computer so I can write algorithms to analyze the data?

And then maybe use that data and feed it back into the website. For example I send data from my warehouse back into the website, so the customers can see which kind of bread is most popular and which sold out.

That kind of communication. I don't know how it happens and I am curious to find out how I can make it happen with Java and Javascript.

It'll be great if you can also enlighten me on the specific things I should learn. This will give me some kind of direction and serve as milestones perhaps?

Also, I heard one can build entirely using Javascript. Is there an advantage/disadvantage to doing so as opposed to using Java for back-end and Javascript for front-end?

Thank you in advance.

32 Upvotes

26 comments sorted by

View all comments

Show parent comments

2

u/nutrecht Lead Software Engineer / EU / 20+ YXP Jun 06 '20 edited Jun 06 '20

I really don't understand why you're using NodeJS (and related tech) when the OP is asking how Java and JavaScript would work together. Why not simply mention Java frameworks there?

In a simple SPA the front-end (Angular for example) JavaScript would just talk to a Java REST back-end. There's no NodeJS or Express there. In addition Mongoose is JavaScript back-end technology, not Java. You would not use Mongoose in a Java back-end.

There's even more mistakes: you don't 'talk' to the front end through RestTemplate at all. That would generally be used for a back-end to talk to other back-ends.

-1

u/snaket2003 Jun 06 '20

I’m obviously not going to engage in a long winded debate about this. For years, I have built Spring Boot back end Java apps that leverage Spring Web and RestTemplate to set up REST APIs which front end and middleware apps use to interact with backend services. (Regardless of being browser or Node based)

I work as a full stack dev and often leverage Node.js (JavaScript last time I checked) to set up middleware services.

Mongoose is just a lightweight framework that eases interaction with MongoDB. Nothing else.

When it comes to Express, as I mentioned before, is just an easy way of creating web servers, APIs, etc useful to someone trying to understand and learn the basics without having to use vanilla JS to make API calls right away. Plus OP wants to get into backend so I don’t know how Node is something I shouldn’t make reference to.

Unfortunately, I feel comments like this overly mystify development for newcomers and if we don’t use easy to understand metaphors, how could newcomers ever get started? If OP wanted the technical documentation response, he wouldn’t be asking in this subreddit for an ELI5... SMH

2

u/nutrecht Lead Software Engineer / EU / 20+ YXP Jun 06 '20

I’m obviously not going to engage in a long winded debate about this.

If that is how you respond to people just pointing out some mistakes in your post, you should not be posting on a beginner sub.

Unfortunately, I feel comments like this overly mystify development for newcomers and if we don’t use easy to understand metaphors, how could newcomers ever get started?

That's not the problem with your post at all. The 'bakery' analogy is fine. The problem is that you are making some rather specific plain mistakes. And not only that; when someone points out the mistakes you downvote their reply and act as if I personally attack you.

He was asking how JavaScript and Java interact. The JavaScript would be the front-end 'clerk', the Java the 'baker'. Again; that analogy is fine. The problem is that in your analogy you're for no appearant reason are also using JavaScript in the back-end, which is not at all what the OP is asking about, making the answer more confusing than needed.

1

u/snaket2003 Jun 06 '20

Fair enough. However, I ask you that you formulate a full analogy that can help and not confuse OP like I did where I am just plain wrong