Issue
Can I use Java backend for a browser game with Javascript frontend? Since I already have knowledge in Java aswell as Javascript I was confused if I should forget Java for this purpose and skip to NodeJS for the backend, although I want to focus on Java in my future. Would I need to learn Java Servlets and JSP or would a book aboout Java Networking be enough to deal with communication, or are both required since Servlet are part of a webapplication running on a web container, and Java Networking is not standalone.
Solution
You can! The choice of your technology stack for the frontend does not necessarily need to influence the choice of your backend technology (and vice versa).
Architecture
You can serve your game view directly from your java application. You could use JSP (or other templating solutions) for visual representation and/or include more logic via javascript.
You could also go for a more distributed approach, where your frontend would only be responsible for fetching and displaying the game state, while your backend would be responsible for serving and maintaining the game state. Your frontend could then inquire about and ask to modify the game state via http, and the backend might answer with the current game state represented as, for example, JSON.
Technologies
While reading about Servlets and JSP or basic networking can be of some value in itself; For this specific purpose, I'd rather look into some options to get you started more quickly. You might find using an established, modern framework easier - Since you're familiar with Java and want to focus that, I'd point you towards Spring Boot 2. Getting a web application running that accepts and serves JSON via an http endpoint can be done quite quickly. In my experience, it's well adopted in the industry as well, so you might benefit from that, too.
You are, however, free to chose in what language or framework to implement your backend: A server written in NodeJS any other language can be used for the same purpose, as long as you know how frontend and backend are going to communicate.
Answered By - user3815641