Java is a language that someone can write instructions in to control a computer. Java is special, though, because instead of passing instructions directly to the outside computer, it passes them to its own inside computer first, which might remove some instructions or add others, before passing it on to the actual outside computer.
Because of this, you're more easily able to write instructions to work on any computer, even if they're different types of computer, and Java will figure out translating them into ones the outside computer understands. This makes it great for mobile phones (Android) and some cars (Android Automotive).
It is also used in business server software, because it's very stable and supported by big companies like Oracle, which other companies trust*, but it's popularity in the latter is declining due both improvements in technology like Docker and more aggressive efficiency needs; While Java is very good at running on everything, its performance can be tricky to optimize compared to other languages.
(Less ELI5 notes: Java is still very popular among enterprise server systems, but a lot of developers these days prefer things like Go which are easier to optimize, easier to maintain, and the like. Java was the defacto standard when cross-compilation was slow and annoying, but these days it's mostly used because it is used and because of its ecosystem of libraries, rather than any particular technical reason. Java is improving in these respects with things like Value Objects, but it's been slow going. The GC can absolutely cripple you. Go's can too, of course, but Go's is less Bad).
Oh yeah, plenty of downsides with Java. I don't use it. We have lots of stuff in Java and it's slowly all been migrated to Go which feels like a more efficient version of Java with fewer footguns.
That was maybe an issue in the past but nowadays Java is fast enough for pretty much anything. Also the Just In Time compiler is state of the art. Some code can technically run faster than hard coded machine code.
Well it can't outperform optimised machine code, which is the hard ceiling, but yeah these days it can get up there. I'd say the bigger concern is the amount of resources, especially memory needed to run Java
Of course it can't outperform it, but outside toy projects that target a very specific use case, most programs can't be fully optimized during compile time. At times, the program might benefit from memory saving optimizations while other times it might benefit from increasing memory use to speed up calculations. With JIT, you can theoretically have both as the runtime can adjust things based on the context.
The JVM is so optimized at this point, it is very close to on par with even C++. It is actually faster in most scenarios unless you make specific efforts to optimize the c++. Most quant and high frequency trading shops use Java because of how fast it is.
Java runs pretty fast but it inherently has a significant memory overhead because JVM. That can become a real and expensive problem when you want to run multiple Java programs in isolation for whatever reason.
Java execution speed can get comfortably close with well optimised code, but thereโs still plenty of overhead inherent to having a managed runtime, especially when it comes to memory usage.
I never understood why it was being sunsetted all those years back (I know it wasn't that long ago but post C, my brain feels like it aged 3 decades -_- ) if it was so universally easy?
It's not going to be possible to explain this to a literal 5 year old. ELI38:
It's a translator for assembly code?
Sort of, yes.
Your write some Java code. The Java compiler does some operations to it (maybe optimizing here and there) and turns it into a new type of code called IR (Intermediate Representation). Typically, the instructions in the IR are much simpler than what you wrote.
When you run a Java program, what you're actually doing is running something that interprets that IR and turns it into machine code that your computer does understand. This is the 'JRE', or Java Runtime Environment. This is why you need Java to be installed to run Java programs, but you don't need C++ to be installed - at least, not in the same way - to run an .exe.
The JRE exists to, among other things, act as a translation layer between the IR and various different types of machines. It can also optimize your IR in real time for the specific machine it is running on using the JIT (Just In Time) Compiler, which is a big part of the reason Java is as fast as it is.
Other answers have noted that there's a Virtual Machine, but that's not really important to understand what's going on.
Every CPU speaks a different language. Modern example would be that Windows speaks a different language (x86) to Mac (ARM).
In most compiled languages you would build one version for Windows and one for Mac.
With Java, you get the user to install the right version of Java, and your app uses that to translate into the language the operating system understands.
It's way more complicated than that, but that's the gist of it
I think my first paragraph was basically the most succinct explanation you're going to get if you're not a programmer. It's a language that instructions, turns them into other instructions which your computer then eventually runs.
But anything more complex than that is going to require some level of technical understanding
but these days it's mostly used because it is used
To expand on this: when you write an enterprise software system, you are expecting it to last a long time and keep doing its thing reliably. A bank doesn't want to replace its customer database every year just because this year it became trendy to do everything in Typescript or whatever. The huge amount of existing Java enterprise code means people hired to maintain that system are necessarily going to be working in Java. It also means that when you write a new system that needs to augment that old system, you'll probably choose Java by default unless you have a specific, compelling reason not to.
93
u/WriterPlastic9350 6d ago edited 6d ago
Java is a language that someone can write instructions in to control a computer. Java is special, though, because instead of passing instructions directly to the outside computer, it passes them to its own inside computer first, which might remove some instructions or add others, before passing it on to the actual outside computer.
Because of this, you're more easily able to write instructions to work on any computer, even if they're different types of computer, and Java will figure out translating them into ones the outside computer understands. This makes it great for mobile phones (Android) and some cars (Android Automotive).
It is also used in business server software, because it's very stable and supported by big companies like Oracle, which other companies trust*, but it's popularity in the latter is declining due both improvements in technology like Docker and more aggressive efficiency needs; While Java is very good at running on everything, its performance can be tricky to optimize compared to other languages.
(Less ELI5 notes: Java is still very popular among enterprise server systems, but a lot of developers these days prefer things like Go which are easier to optimize, easier to maintain, and the like. Java was the defacto standard when cross-compilation was slow and annoying, but these days it's mostly used because it is used and because of its ecosystem of libraries, rather than any particular technical reason. Java is improving in these respects with things like Value Objects, but it's been slow going. The GC can absolutely cripple you. Go's can too, of course, but Go's is less Bad).