I have been learning java for about six months, at the moment I know quite well the core, I solved a bunch of tasks and wrote one VK bot. And now I’m set on trying to make my own web-application (website with image editing). So I would like to know, with the help of what technologies are web-projects being implemented now? What do I need to learn to create my web application? How can I learn how to plan the structure of my project? I have a lot of free time and I want to devote myself completely to java.
Closed due to the fact that it is necessary to reformulate the question so that it was possible to give an objectively correct answer by the participants aleksandr barakin , 0xdb , Anton Sorokin , AK ♦ , freim 15 May at 8:07 .
The question gives rise to endless debates and discussions based not on knowledge, but on opinions. To get an answer, rephrase your question so that it can be given an unambiguously correct answer, or delete the question altogether. If the question can be reformulated according to the rules set out in the certificate , edit it .
- fourJava EE and Spring. - Sergey Gornostaev
- Walls C. - Spring in Action - 2019 - Alexey
- Possible duplicate issue: Books and learning resources for Java - Anton Sorokin
2 answers
Of course Java EE and Spring are cool, but now this trend has gone, using frameworks in the blind. The market is full of junes that wave their spring, how cors works or http can’t be answered.
As a learning goal, it is useful to write your first web application on core java, I'm not saying that you need to try to take into account all the features of authentication type or sessions, although this is a feasible task.
After that, armed with spring or JavaEE, you will already understand what you need to do on a deeper level, you will understand what the framework does, and not just blindly stuff the code with pieces found on the Internet, and the more motivation to use the framework, and most importantly, I hope there will be an understanding when it can not be used at all :)
In general, it is useful to know web technologies, in which there are many subtleties that are not related to the programming language in which the web application is implemented.
It is extremely useful to understand what is waiting for the front-end from the server, so this is also a good place to look into this forest and henceforth html js and css (at least) are your sworn friends.
Here is a simple example:
index.html
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Kali fractal</title> </head> <body> <canvas></canvas> <script type='glsl/vertex'> attribute vec2 coords; void main(void) { gl_Position = vec4(coords.xy, 0.0, 1.0); } </script> <script type='glsl/fragment'>precision highp float; uniform vec4 mr; // (m)ouse position and screen (r)esolution void main(void) { vec2 p = gl_FragCoord.xy; vec2 q = (p + p - mr.ba) / mr.b; for(int i = 0; i < 13; i++) q = abs(q)/dot(q,q) - mr.xy/mr.zw; gl_FragColor = vec4(q, qx/qy, 1.0); } </script> <script> let canvas = document.querySelector('canvas'); canvas.width = window.innerWidth; canvas.height = window.innerHeight; let gl = canvas.getContext('webgl') || canvas.getContext('experimental-webgl'); var h = gl.drawingBufferHeight; var w = gl.drawingBufferWidth; let pid = gl.createProgram(); shader('glsl/vertex', gl.VERTEX_SHADER); shader('glsl/fragment', gl.FRAGMENT_SHADER); gl.linkProgram(pid); gl.useProgram(pid); let array = new Float32Array([-1, 3, -1, -1, 3, -1]); gl.bindBuffer(gl.ARRAY_BUFFER, gl.createBuffer()); gl.bufferData(gl.ARRAY_BUFFER, array, gl.STATIC_DRAW); let al = gl.getAttribLocation(pid, "coords"); gl.vertexAttribPointer(al, 2 /*components per vertex */, gl.FLOAT, false, 0, 0); gl.enableVertexAttribArray(al); let mr = gl.getUniformLocation(pid, 'mr'); // (m)ouse position and screen (r)esolution window.addEventListener('mousemove', draw); window.addEventListener('touchmove', draw); draw(); function draw(e) { let ev = e && e.touches ? e.touches[0] : e; let x = ev ? ev.clientX : 250; let y = ev ? h - ev.clientY: 111; gl.uniform4f(mr, x, y, w, h); gl.viewport(0, 0, w, h); gl.clearColor(0, 0, 0, 0); gl.drawArrays(gl.TRIANGLES, 0, 3 /* 3 vertices */); } function shader(name, type) { let src = [...document.scripts].find(s => s.type === name).innerText; let sid = gl.createShader(type); gl.shaderSource(sid, src); gl.compileShader(sid); gl.attachShader(pid, sid); } </script> <style> body { margin: 0; overflow: hidden; } </style> </body> </html> SimpleWebServer.java
import com.sun.net.httpserver.HttpExchange; import com.sun.net.httpserver.HttpHandler; import com.sun.net.httpserver.HttpServer; import java.io.ByteArrayOutputStream; import java.io.FileInputStream; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.io.PrintWriter; import java.io.StringWriter; import java.net.InetSocketAddress; import java.util.HashMap; import java.util.Map; public class SimpleWebServer implements HttpHandler { public static void main(String[] args) throws IOException { HttpServer server = HttpServer.create(new InetSocketAddress(8080), 0); server.createContext("/", new SimpleWebServer("/", "./static/")); server.start(); System.out.println("server started, please visit http://localhost:8080/index.html"); } private String routePath; private String fsPath; private Map<String, String> headers = new HashMap<String, String>(){{ put("html", "text/html"); }}; public SimpleWebServer(String path, String filesystemPath) { routePath = path; fsPath = filesystemPath; } @Override public void handle(HttpExchange http) throws IOException { OutputStream outputStream = http.getResponseBody(); http.getRequestBody(); String request = http.getRequestURI().getRawPath(); byte[] result; int code; try { try { String path = fsPath + request.substring(routePath.length()); System.out.println("requested: " + path); result = read(new FileInputStream(path)).toByteArray(); String ext = request.substring(request.lastIndexOf(".") + 1); if (headers.containsKey(ext)) http.getResponseHeaders().add("Content-Type", headers.get(ext)); code = 200; } catch (IOException e) { result = (404 + " " + request).getBytes(); code = 404; } } catch (Exception e) { StringWriter sw = new StringWriter(); e.printStackTrace(new PrintWriter(sw)); result = sw.getBuffer().toString().getBytes(); code = 500; } http.sendResponseHeaders(code, result.length); outputStream.write(result); outputStream.close(); } static ByteArrayOutputStream read(InputStream is) throws IOException { ByteArrayOutputStream buffer = new ByteArrayOutputStream(); int nRead; byte[] data = new byte[1024]; while ((nRead = is.read(data, 0, data.length)) != -1) { buffer.write(data, 0, nRead); } buffer.flush(); is.close(); return buffer; } } more / less universal (and uncomplicated) answer / advice:
Collector / dependency manager (Maven or Gradle), Framework (SpringBoot), DB (PostgreSQL or MySQL) + SpringData and Hibernate, container for executing java code (Tomcat), Logger (Log4j), Testing (JUnit + Mockito)
besides (later), nginx and the Linux Server (for example, Debian) come in handy - so that an application already written on the Internet is spinning
PS There may be variations
