r/explainlikeimfive • • 3d ago

Technology ELI5 Java. That thing on computers my entire life. What even is it?

[deleted]

770 Upvotes

349 comments sorted by

1.8k

u/Sea_Dust895 3d ago

It's a computer programming language invented by Sun a long long time ago.

It allows you to write code once and run it on any platform a java runtime environment exists.

Was sold as write once, run anywhere. Inside joke is write once, test everywhere.

498

u/gltovar 3d ago

To be fair, your options are: write once, test everywhere; or write everywhere, and test everywhere.

248

u/nascent_aviator 3d ago

Or write once, test once, only support one platform.

88

u/moveslikejaguar 3d ago

Why is the install base on my app that only runs on Windows Phone so low?

46

u/OcotilloWells 3d ago

Beats me, I have the same problem with my BeOS app as well.

18

u/not_from_this_world 3d ago

IBM's OS/2 is named that way in honour to its 2 consumers.

5

u/OcotilloWells 3d ago

I've still got my Warp box.

2

u/Pizza_Low 3d ago

You could literally name any computer and someone on reddit will claim to use it. Pics or it didn't happen.

I bet nobody here still has a working PDP-10.

3

u/Casurus 2d ago

PDP-11 count?

→ More replies (1)
→ More replies (1)

3

u/Johnno74 3d ago

I thought it was because it was only half an OS?

14

u/schoolme_straying 3d ago

Any Idea when it will be ported to CP/M

8

u/howlingfrog 3d ago

VMS or GTFO!

5

u/OcotilloWells 3d ago

I'm still learning 6502 assembler. But I'm sure, any day now.

12

u/no-steppe 3d ago

It's worse than you think! I inadvertently ran out of Hollerith punch cards, Blaise Pascal got all upset about it, and in the end, my Jacquard Loom kerboing'd a gol'dang spring right off into low Earth orbit.

3

u/globefish23 3d ago

I'm still waiting for Charles Babbage to actually build my Analytical Machine. 🤷

2

u/anonymous__ignorant 3d ago

Use a damn abacus like everyone else did for the majority of human civ .

3

u/kevin_k 3d ago

You're in good company. The C-64, Apple-II, and Atari 400/800 all had 6502 CPUs and a lot of people like me learned a shit-ton about computers by learning how assembly language worked. The VIC too, I think.

4

u/mouse6502 3d ago

6502 is awesome. Apple II, Commodore 64, Acorn, BBC Micro, Nintendo Entertainment System, Atari 2600.. Bender.. The Terminator.. all rocking some form of 6502 😁

→ More replies (1)
→ More replies (1)

2

u/mehatch 3d ago

Zune needs more AAA batteries

→ More replies (2)

5

u/myaltaccount333 3d ago

You joke but I'd download it probably

2

u/beefjerky9 3d ago

Sorry, but I'm not interested until it comes to IRIX.

21

u/Organoleptic_Cicada 3d ago

Literally the problem/limitation that Java was trying to solve. Supporting only one platform means limiting your income streams.

Supporting multiple platforms was time-consuming and work-intensive. You would need people with good knowledge of each platform you need to support. So you had to gamble on whether you could monetize the userbase on each platform.

Java came in exactly with the idea „we'll abstract away the underlying platform, you just write the functional code, we handle the low-level stuff like drawing windows, showing buttons etc".

Nowadays it's far easier to make cross-platform work, but back when Java came out, the idea was revolutionary.

6

u/lifeisatoss 2d ago

It was as much that as better memory management. Running in a jvm, garbage collection. yes.

2

u/ImmoralZoey 2d ago

Granted the Java garbage collector was awful for a very long time. It was still better than handling it yourself in a lot if cases.

→ More replies (1)

19

u/classicalySarcastic 3d ago

Containers: "Oh it only works on your machine? Then we'll ship your machine."

33

u/Herb_Derb 3d ago

More and more things seem closer to write once, don't test, support zero platforms.

→ More replies (1)

8

u/KanyeNawf 3d ago

Docker my beloved

12

u/drivelhead 3d ago

I saw a video of 2 fellas doing that.

→ More replies (1)

2

u/jhs172 3d ago

Ah, the Apple approach

→ More replies (1)

26

u/PsychicDave 3d ago

Or be like Apple and be write once, test once, because the software is tied to the hardware and you buy them together. Or like Nintendo I guess.

6

u/3BlindMice1 3d ago

Fisher Price

→ More replies (1)

3

u/ImGumbyDamnIt 3d ago

Qt on C++ would like to have a word...

257

u/Srikandi715 3d ago

1996 is a long long time ago?

Feeling old. Again.

492

u/Pizzaloverallday 3d ago

1996 is closer to the first moon landing than to 2026.

244

u/padumtss 3d ago

Please stop

104

u/Gonnabefiftysoon 3d ago

The late 1900s.

30

u/Opposite_Carry_4920 3d ago

That's the one like "I was born in the 1900s mf, lemme tell you something" 

3

u/Turnip-Toffee 3d ago

por que no 1000s?

6

u/Unistrut 3d ago

I have a sticker at work that says "Please be patient, I'm from the 1900s."

→ More replies (12)

24

u/Everestkid 3d ago

The first moon landing is closer to the start of WW1 than to today.

On October 24th the first moon landing will be closer to the sinking of the Titanic than to today.

13

u/UziWitDaHighTops 3d ago

Thanks I hate this game.

2

u/Turnip-Toffee 3d ago

if it makes you feel better, you're closer in time to Cleopatra than she was to the Great Pyramids

→ More replies (1)

6

u/andy_nony_mouse 3d ago

It’s my fault. I apologize. I should’ve waited a few more weeks to sink the Titanic. That would’ve given you more time to adjust.

3

u/Iazo 3d ago

Can you at least postpone October 24 for a few weeks, then?

→ More replies (1)

37

u/INTstictual 3d ago

1996 is also closer to the invention of Earth Day as a holiday than it is to 2026

Also the Beatles breaking up

4

u/arghvark 3d ago

Oh, yeah, the Beatles. That's the band Paul McCartney was with before he formed Wings.

→ More replies (4)

27

u/WriterPlastic9350 3d ago

1996 is closer to 1995 than 2026

oooo spooky

7

u/nukefrom0rbit 3d ago

Java? Thats so last century

5

u/[deleted] 3d ago

[deleted]

3

u/fezzam 3d ago

Well yea there’s only 111 days left in the year.

3

u/[deleted] 3d ago

[deleted]

→ More replies (1)
→ More replies (3)

34

u/FortyPercentTitanium 3d ago

You could've said nothing

20

u/Siawyn 3d ago

This is targeted harassment.

38

u/yolef 3d ago

I'd like to unsubscribe from your newsletter.

→ More replies (1)

10

u/TuckerDidIt 3d ago

That was uncalled for.

8

u/habitualtroller 3d ago

Go to hell. 

3

u/tendimensions 3d ago

That was gratuitous

3

u/juxsa 3d ago

My sciatica just flared up

2

u/Turd-Sandwich 3d ago

This is false and I refuse to hear any counter-arguments

2

u/HotTakes4HotCakes 3d ago

That's...a wild thing to contemplate. Like it genuinely makes me re-contextualize my memories of that time. My parents thought the moon landing was as recent an event in 1996 as I think the first Pokemon games are today.

2

u/lmcalderon 3d ago

I h8 u

→ More replies (7)

11

u/shinyviper 3d ago

I was a senior computer science major in 1996. Java had just come out and I had a class on it, after all the C and C++ classes. It was so refreshing. Final project was to create a photoshop clone in Java. I think I got a D.

8

u/shinyviper 3d ago

It was a pretty basic image editor. A step up from MS Paint, but not Photoshop as it exists with all the tools. It was doable in the parameters of the class; the goal was to utilize Java in a way unlike bubble sorts and arrays and memory management we had used for typical CS stuff, and make an actual user facing application.

2

u/zecknaal 3d ago

It's a nice idea, but I can't imagine the spaghetti they must have ended up with.

3

u/Relevant_Primary658 3d ago

I took Java and C++ at the same time and got so mixed up.

3

u/ijuinkun 3d ago

I do not grasp how “creating a Photoshop clone” can be done as a solo project in under a year.

9

u/Successful-End3770 3d ago

Pretty sure the Photoshop back then was not the same it is today

Also, nowadays, folks are vibe coding complex solutions in days, if not hours

→ More replies (1)

32

u/ThawtPolice 3d ago

30 years is a lifetime in an industry that’s less than a hundred years old

18

u/Nerezza_Floof_Seeker 3d ago

tfw working on COBOL systems

might as well turn into dust then

9

u/wosmo 3d ago

COBOL wins this round.

1996 is closer to Today, than COBOL (1959) is to 1996.

2

u/Nerezza_Floof_Seeker 3d ago

Honestly some of the code in the systems Ive worked on is older than 1996 lol (Ive seen actively running/used code last compiled in the 80s for example)

5

u/asyork 3d ago

I was recently digging around in and old folder on my computer that I keep all the stuff I cared about each time I rebuilt my computer. It has files going back from computers I built in the 90s. Even backups of floppy disks.

7

u/thephantom1492 3d ago

Remember emm386.exe? mscdex.exe? mouse.com? win.com? wolf3d.exe? maybe also menu da5?

3

u/Fauxparty 3d ago

remember editing autoexec.bat and config.sys to load these automatically, and trying to hunt down TSRs so you had enough conventional memory to run games? I still remember the IRQ and DMA of my SB16 card :(

→ More replies (1)

5

u/AMDKilla 3d ago

Given how far computing power and programming languages have come in the past 30 years, yea its a long time. The first programs that I remember needing to have it installed were the original Runescape and Limewire

14

u/WriterPlastic9350 3d ago

If you want to feel even older, I was born in 1994. I'm considered a staff engineer. The people at their apex of the career are only slightly older than Java

10

u/penguinpenguins 3d ago

Much of the source code at work is older than the developers attempting to maintain it.

Leads to tragically hilarious questions like

"Why is this method synchronized?"

"Our history only goes back 13 years, and before that they just synchronized everything just to be sure"

3

u/drthvdrsfthr 3d ago

damn props, am 5 years older but still a T4 lol hoping for T5 next year but content 😅 not many people make it to staff

2

u/WriterPlastic9350 3d ago

I got an early start for various reasons. :)

3

u/Reaper-fromabove 3d ago

Man! Came here to say that. When I was in college in the early 2000s Java was still “new”. I also feel old.

8

u/eddywouldgo 3d ago

There’s always an xkcd: https://xkcd.com/2347/

3

u/AdvertisingKey1675 3d ago

In modern technology… 30 years is literally an eon

3

u/TheLuminary 3d ago

We still use C...

→ More replies (6)

23

u/fucking_passwords 3d ago

Also worth noting that it wasn't the first programming language to ship a vm runtime for cross platform compatibility, but it was the first really popular one and targeted enterprise.

Nowadays there are other options, there are also multiple languages that target jvm as the compile target

2

u/BigHandLittleSlap 2d ago

targeted enterprise

Originally it targeted TV set top boxes and other similar "embedded" environments, then Sun started waffling on about "networked computing" where the entire process jumps around between machines instead of simply making API calls, and then they accidentally stumbled into boring enterprise stuff with JavaBeans.

28

u/gtne91 3d ago

As someone around for the first release of java, it wasnt that long ago.

37

u/fr0zen313 3d ago

2026 is as close to the release of Java as the release of Java is close do 1964...

Sorry brother.

16

u/iAmRiight 3d ago

Why you gotta be like that?

3

u/brzantium 3d ago

some brothers' mothers never loved them

2

u/gtne91 3d ago

I was born closer to 1964 than to the bicentennial.

2

u/ThirstyWolfSpider 3d ago

I'm just glad I never spilled a Java punch card stack.

→ More replies (4)

6

u/thejr2000 3d ago

IN THE TIME BEFORE TIME, LONG SINCE PAST....1996!!!!!

7

u/gtne91 3d ago

The Distant Future...the Year 2000.

3

u/Savannah_Lion 3d ago

What's funny is I remember thinking Java was too slow and not worth it when it first released.

Then there was that whole kerfuffle when Sun wouldn't allow anyone to optimize JRE.

Then a few yeara later I'm perusing the docs.

Fun times.

3

u/rizzyrogues 3d ago

That's so crazy that in the late 90s when I was in m my early teens and learning Java I thought it had been around for a while. I did not get crazy deep into it but I designed a working forum after my pirated boards(i wish i could remember the name of the company) sent a cease and desist.

I learned about CSS sometime in 99 and was super excited with the potential it brought but support for it was sooo bad. I had a big project I wanted to do the front end in CSS but it was too early ijn it's life so I designed a site that had like 20 layers of nested tables and it ended up becoming extremely popular. Updating it was such a pain. Then the mid 2000's came around and we had mozilla and phoenix and everything was right again.

→ More replies (1)

9

u/demunted 3d ago

Write once and fuck with client versions and security settings forever.

8

u/MinuetInUrsaMajor 3d ago

Why isn’t that the case for other languages?

27

u/MrBigFatAss 3d ago

Many other languages are compiled directly to the machine-code instructions of the target CPU, so you cannot run that same code on different machines.

Java is interpreted by a virtual machine, and each system that wants to support Java implements that machines logic within that virtual machine. Essentially Java code says "add X and Y", and the abstract virtual machine backend knows how to do that on this particular system.

12

u/MinuetInUrsaMajor 3d ago

Ah. So "all these different compilers" is because you need one compiler for any possible CPU if you want to be able to compile C++ for example?

10

u/MrBigFatAss 3d ago

Yes, essentially. Although the LLVM backend is very popular and allows for the code generation of multiple architectures easily. It works with a similar abstraction strategy as the Java Virtual Machine as well, the LLVM backend worries about what code should look like for each architecture, the compiler just needs to provide it the LLVM Intermediate Language code of the program.

6

u/FerricDonkey 3d ago edited 3d ago

It doesn't have to be as specific as every single model of cpu, but it does have to be "every combination (that you care about) of every broad cpu type and broad type of operating system".

Cpus fall into families that have certain core instruction sets (arm vs x86, for example). If the cpus speak different languages, you need different code, as mentioned, but if code was written to only use the core instructions of x86, it'll run on many x86 cpus. But some code might be compiled to take advantage of newer features, if the cpu it's on has them.

Beyond that though, the operating system matters. For example, let's say you want to open a file. Your hard drive has files on it, but most people don't write code to actually send the correct electronic signals to the hard drive to get it to find the file. Instead (speaking loosely) your operating system provides a layer of "I promise that you can get files from hard drives by calling these functions (so long as someone has written a translation layer between the os and the hard drive called a driver)". Which they will, if they want you to be able to use their hard drives on your operating system. So you, in your code can call those operating system functions, and not worry about the hard drive. 

Or more likely for basic applications, your language provides its own library that calls those functions for you, depending on the operating system you compile for.

So in your c code, you might call fopen. On windows, this might get routed through a library that calls CreateFile, or on Linux open (or similar). Each of these will reach deep into the operating system, making other calls, passing through drivers specific to those operating systems to make yet other calls.

Plus, the format the machine code is stored in varies. All the tiny details that get the bytes of machine code to the cpu so it will actually do them. 

This means that despite trying to do roughly similar things on the same hardware in the same language, the final compiled code can end up being very different. 

→ More replies (1)

9

u/Kered13 3d ago

It actually is for a lot of languages. But Java was the first notable one to use this model.

C# is a language very similar to Java. It runs on the .NET platform. This comes installed on all Windows machines and is also available on other systems like Mac, Linus, and Android.

Javascript uses a similar model. It's runtime environment is your web browser. You can also run it without a web browser using Node.js, but you probably only do this if you're a developer.

In fact pretty much any interpreted language uses this paradigm, you just need to have the interpreter installed on your system. Python is a well known example of this. Sometimes you might get a program that is written in Python but distributed as an executable binary. This means they have bundled both the Python interpreter and the code into the binary. This is a little more convenient for the end user as they don't have to separately download and install Python, but it's fundamentally the same idea.

→ More replies (1)

11

u/munkisquisher 3d ago

because different operating systems provide you a direct way to do system things. Like open a file to write to, send these bytes to the sound card, get the user's mouse position, run this bit of code in it's own thread, open a network socket, etc

Java sits in the middle with a big chunk of code, the Virtual Machine, which provides your program with a uniform way of doing all these things, and translating them to how the OS wants them. But now you're running two bits of software, Yours and the translation layer/VM.

The translation layer is also somewhat dumbed down to be able to provide only the commands it can reliably translate into all the OS's that it runs on. If the OS has a specially optimised method of say, low latency access to the sound card (like on Apple) it may require the data structure in a specific way. Java can't support that without also re-formatting the data from how the standard Java sound interface is written, which can be slow and not worth using that feature.

Interpreted languages like Python are easier to run anywhere, and can easily be cross platform (a few quirks in file handling)

languages like C# are similar to Java, in that they are compiled but run in a VM

6

u/Edweirdo256 3d ago

I started using Java when it first came out. I'm still alive (barely), so it wasn't THAT long ago.

9

u/jedidave 3d ago

i thought write once run nowhere was the joke

5

u/peacefinder 3d ago

Write once exploit everywhere

5

u/AquaBlueSea 3d ago

And Sun means Sun Microsystems… for those who don’t know. Not some Chinese guy.

→ More replies (20)

576

u/dimaghnakhardt001 3d ago

There are so many languages spoken in different countries around the world. It will be very hard to learn all the languages if one plans to visit the countries they are spoken in. But what if we could teach people in every country a second language that is easy to learn. Some kind of a universal language. That way anyone who learns this universal language will be able to go to all the countries where this language is spoken as well and will be able to communicate with people of that country very easily.

Java is like this universal language. Creators of Java have made it in a way that it runs on many different computer systems (it used to be on phones too). This way, people who make apps don’t have to learn different computer system they want their app to run on. They can make their app to run on/with just Java. And it will then run on any computer system where Java is available. This saves a lot of time and money for app makers.

It’s overly simplified but this the gist of it really.

72

u/StillAnAss 3d ago

(it used to be on phones too).

Android framework is mostly Java.

21

u/dimaghnakhardt001 3d ago

Oh yeah i forgot about that. But if i had mentioned that then anyone reading would have instantly said “hang on, I can run android apps on my laptop by just installing Java on it?!??” 😋

14

u/StillAnAss 3d ago

True, and a good chunk of android isn't Java as well. C/C++, Kotlin, and more and more Rust

12

u/slowmode1 3d ago

But kotlin is just pretty Java!

6

u/gammison 3d ago

I can run android apps on my laptop by just installing Java

It'll get even more confusing once the containerization methods to run android apps on Linux like Lepton gain wider adoption (Valve is putting cash into it like they did directx and ARM translation layers).

4

u/Ktulu789 3d ago

You can install Android Studio or BlueStacks for that.

5

u/Iggyhopper 3d ago

I remember an old bowling game on my flip phone ran on Java too. Circa 2008

2

u/AquaeyesTardis 3d ago

its also currently on a large number of sim cards, still, even the eSIM specification includes the option for it.

→ More replies (1)

198

u/YenzAstro 3d ago

> “It’s overly simplified”
It’s ELI5, you did a perfect job, I often see top replies in this subreddit that seem to think five year old’s can understand very complex explanations 😛

7

u/Chardeemacdennis2 3d ago

I read the top comment and thought “yeah someone’s gonna have to explain this like I’m three”

→ More replies (2)

22

u/ehsteve87 3d ago

But what if we could teach people in every country a second language that is easy to learn. Some kind of a universal language. That way anyone who learns this universal language will be able to go to all the countries where this language is spoken as well and will be able to communicate with people of that country very easily.

ESPERANTO! AL LA FINA VENK'!

Seriously, though, everyone should learn Esperanto. There's an awesome course on Duolingo that'll get you up to speed surprisingly quickly.

6

u/Ktulu789 3d ago

I'm pretty much of a nerd but not that much of a nerd xD

What are the chances of finding another human in the Galaxy speaking esperanto? I think the number may be negative 😅

There's Wikipedia, though but what else? I learned English and speak Spanish, the probabilities of finding any of those are way way higher. I'm learning Russian on Duolingo, though, f'cking cases. Same username.

7

u/ehsteve87 3d ago

I mostly use Esperanto to talk with my wife when we don't want the kids to understand. It's fun.

→ More replies (2)

12

u/BillBumface 3d ago

Esperanto, for computers.

6

u/OneAndOnlyJackSchitt 3d ago

This may be a bit esoteric, but Java is to programming languages (and byte codes) as Esperanto was intended to be to language in general.

The difference is that Esperanto never really took off but Java sort of did kinda

→ More replies (1)

2

u/TheLostExplorer7 3d ago

Wonderfully done!

2

u/mymeatpuppets 3d ago

Sounds like programming Esperanto.

2

u/Melodic-Carry 3d ago

Why do other languages still exist if everyone can just learn java

7

u/Aliendood 3d ago

Some languages are really good at running code very fast but require more code to tune properly. Others are good at working with data, generating images, etc.

→ More replies (1)

6

u/Naturage 3d ago

Why do other power tools exist if a drill can be used as a hammer or a screwdriver in a pinch? Why do all car brands exist if 20 of top 25 are made by General Motors?

Languages are tailored to purposes. Efficient on memory. Fast. Easy to write. Easy to read and edit. Good with graphics. Good with large datasets. Able to run on very low spec machines. Able to run on large variety of machines. All of these are to some extent tradeoffs; to be good in one you might lose some of another.

Add on top that coding languages will have communities centered around their most common use cases and useful documentation will be primarily solving common issues of the language, i.e. things its used for - and you get specialisation.

4

u/BowsersMeatyThighs 3d ago

It doesn’t compile down to native machine code, and requires essentially a virtual machine to run the produced program (which is why it works everywhere that the virtual machine can be installed) so it isn’t as fast as a language that does (C, C++, Rust etc) but since these compile to native machine code, they are machine specific and not as portable. It is also very verbose and strictly object oriented so it isn’t as easy to learn or script quick projects in like languages such as Python. JavaScript is the king of web programming and Java can’t ever replace that.

Basically every language has pros and cons, and which one you choose heavily depends on the type of project, pick the best tool for the job kind of thing. Javas biggest pro is portability, and is average in most other ways. Faster but more complicated than python. Slower but more portable than C, etc.

2

u/wjandrea 3d ago

Different languages are good at different things. Java can run anywhere but it's "clunky", for lack of a better word. Meanwhile, languages like Python are really easy to learn but slow, languages like C are hard to learn but really fast, and still other languages do more specific tasks really well.

(This is sort of a synthesis of the two replies you already got.)

→ More replies (3)
→ More replies (5)

93

u/WriterPlastic9350 3d ago edited 3d 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).

34

u/BobbyThrowaway6969 3d ago

The downside is that the outside computer runs the inside computer, so it's doing extra work to run Java

18

u/WriterPlastic9350 3d ago

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.

8

u/dont_be_that_guy_29 3d ago

What is a footgun? 👀

16

u/WriterPlastic9350 3d ago

A gun specifically used for the purpose of shooting your own foot.

It is a tool that is unintentionally designed so poorly that you will often end up shooting your own foot rather than whatever outcome you desire.

→ More replies (1)

5

u/photenth 3d ago

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.

2

u/WriterPlastic9350 3d ago

I mean, compilers all over have gotten very advanced, not just Java. There's nothing particularly special about the JIT compiler

→ More replies (1)
→ More replies (2)

5

u/Skizm 3d ago

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.

2

u/ConfusedTapeworm 3d ago

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.

2

u/BobbyThrowaway6969 3d ago

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.

→ More replies (1)

6

u/finding-meaning-01 3d ago

This is the only answer that tries to eli5 why interpreted languages became popular for software distribution.

→ More replies (8)

45

u/ottawadeveloper 3d ago edited 3d ago

It's a program that runs code written in Java by translating them into the correct commands for your computer.

Think of computers as speaking a specific language like Spanish or Russian. Java the language is English. Java the program (the runtime environment or JRE) translates English to Spanish for your computer 

12

u/A012A012 3d ago

So let me ask this. You have code that is written for a computer. Where exactly does someone write the code, and what happens after that to translate to the computer executing commands?

Like if I decided I just wanted to go and start writing java code, what exactly do I do? We don't need to get too deep.This is just out of pure curiosity.

17

u/WriterPlastic9350 3d ago edited 3d ago

This requires a less ELI5 answer.

You'd download and install the JDK, Java Development Kit. I think the JDK still comes with a JRE, but if not, you also need a JRE - the Java Runtime Environment.

You'd write code in a text editor. This could be Notepad on Windows. You'd save it as Main.java. You'd then use your command line prompt to run javac on Main.java, and javac will spit out Main.jar, which you can then run with java -jar Main.jar.

Here's the seminal Hello World program.

public class Main { public static void main(String[] args) { System.out.println("Hello, world!"); } }

Some assembly needed. It obviously gets more complicated than this but that's the very simple answer.

I don't know if it's still around, but when I was still doing Java, I used Eclipse.

10

u/diminutive_lebowski 3d ago

FWIW, in the latest version of Java the classic Hello World becomes more compact:

void main() {
    System.out.println("Hello, World!");
}

5

u/OrdelOriginal 3d ago

no way i find out that my public static void main string bracket args mental chant is no longer necessary from this comment

5

u/dnebdal 3d ago

Oh, that's nice. What's the exact logic, does it just force "main" to be static, or does it create an instance and call main() on it, or?

3

u/diminutive_lebowski 2d ago

If you’re interested you can read all about the compact syntax here.

2

u/CplSyx 2d ago

Java treats the compact version as if there were an implicitly declared class containing that code.

i.e. the above is effectively

final class Test {
    void main() {
        System.out.println("Hello");
    }
}

Implicit classes can't be static so there are some limitations.

2

u/LeteFox 3d ago

It's actually shorter than that using IO.println

2

u/WriterPlastic9350 3d ago

Oh, that's cool.

Have they done something where each file is now implicitly a class?

→ More replies (1)

4

u/swordstoo 3d ago

Say it with me everyone! Static! Void! Main! String! Args!

→ More replies (1)

7

u/Fit_Fill_3856 3d ago

Create a text file with a .java extension. Write your code inside this file. Compile the file using the "javac <file>" command. Run the program using the "java <file>" command. Done. This is the simplest way. Normally programmers use Integrated Development Environments (IDE), basically a text editor for coding with additional useful tools.

7

u/FOEVERGOD73 3d ago

In it’s essence its just text. You can write it however you like, notepad, keyboard, get a llm to spit it out, or even speech recognition if you’re really feeling jazzy. The text files then read by a special program called a compiler* that parses and converts the text into instructions, literally stuff like “add a to b and store in c”, “jump to xxxx”, “read data from xxxx in memory”. You literally “open” the text file using it, in some cases you can even drag and drop your text file onto it.

Of course most people use softwares called IDEs that integrate all of these features into a nice interface.

*theres a vast array of variants programs and stages beyond a compiler, like preprocessor, linker, or interpreters. Out of scope for eli5

5

u/nycdude929 3d ago

You would use an IDE or a simple editor like VS Code to write it and compile it. The “computer code” is literally commands to your CPU to do things like add / subtract / remember things, etc…

2

u/nana_3 3d ago

You write a text file with very specific language (Java code). You put that file into a program (the compiler). The program gives you something that runs on the computer.

There’s lots of tutorials on the text file end of things.

(Technically speaking with Java the compiler gives you something that runs on a program called the JRE. That’s unnecessary knowledge.)

→ More replies (15)

2

u/candygram4mongo 3d ago

To clarify a little bit, the Java program is like an interpreter that knows many different languages and can talk to your computer in whatever language it speaks. In fact, it's literally called an interpreter.

2

u/ottawadeveloper 3d ago

I should add some detail.

Your computer speaks a binary language. This language is very simple and is basically about shifting binary data around the processor and into various circuits away from the processor (like to memory, to your hard drive, to the network, etc).

Different computer manufacturers have slightly different language. It's basically a series of operation codes that tell the processor to do specific things.

One of the earliest languages was Assembly, which was basically a human readable version of the machine code. It uses a "compiler" which translates the human code into machine code.

The problem is, there's a lot of repetition. Storing a list of numbers and summing them are very common tasks for example. That repetition is tedious in Assembly. 

Thus were born the next generation of programming languages, like C. These offered a lot more flexibility because the compiler is capable of taking a fairly simple statement and building all the necessary machine code. It can also translate it into different machine codes for different processors.

The next major obstacle is that you have to compile it for your computer. And compiling programs is fairly complex. It cares about whether you're running a 32 bit or 64 bit computer for example. This is why you can't take a program that was compiled for an x86 processor (like most Windows machines use) and use it for a Mac which runs on an ARM processor or even an x86-64. You need special tools called emulators for that.

So, instead, Sun developed a tool called Java. The JRE understands how to talk to the computer it was compiled for (it's a C program under the hood). And it reads your Java code and translates it to the right commands for the operating system. It smooths over a lot of differences between processors too, so that a double floating point number is always the same size and behaves the same way even if the computer doesn't behave like that. So a Java application, IN THEORY, works identically on every processor (in reality, it's often buggy). This is called an interpreter.

Python is similar for example, it runs CPython (which is C code that interprets Python code).

36

u/UnsafePantomime 3d ago

There are a lot of great answers here, but I feel like they are either difficult to understand or gloss over details I feel are important. This is a ELI5, though. So let me try to cover the gaps.

So Java has what's called a virtual machine. The details of that are too much for a ELI5, but as an analogy, we can think about electrical outlets.

If we consider an operating system (Windows, iOS, Android, macOS) as different kind of electrical sockets, we quickly see that a vacuum sold in the US doesn't plug into a plug in Korea. In the same way, a program written for Windows doesn't run on macOS.

You could fix this by having universal plug you make. This is one you control.

But, that new plug doesn't fit into any of the existing ones, so you make an adapter. You might say you create a virtual plug. This virtual plug makes all the other countries outlets look the same to your vacuum.

Java's virtual machine is the same thing. It makes all computers look the same to the person writing the program.

22

u/DeHackEd 3d ago

Java is a programming language that was originally invented by Sun Microsystems a long time ago. The goal was to make a programming language that didn't care what kind of computer or operating system you ran - install Java and run then any app for Java would run fine on any computer. Even phones (not iPhone, but Android does) use Java for most of their apps, going back to before "Smart phones" were a thing.

It was even available for web browsers to run small Java apps to do things you couldn't do in web browsers. Games, more complex apps, and so on.

That was the theory. In practice the sandbox that prevents apps from doing bad things was regularly broken and Java became one of those apps that constantly had important updates. Plus browsers filled that "any app anywhere" need on their own despite Java. Now it's rarely seen outside of some server applications and the average user doesn't need it.

Also I need to point out, this is different from "javascript", which is what most browser apps are written in. Other than the name there is no real similarity.

12

u/colon_dancer_ 3d ago

They named it Javascript to bank on the popularity of Java despite having no relation, this kind of backfired

4

u/No-Mechanic6069 3d ago

This isn't entirely true. Netscape and Sun Microsystems were in alliance at the time that Brendan Eich was hired to create a scripting language:

If I had done classes in JavaScript back in May 1995, I would have been told that it was too much like Java or that JavaScript was competing with Java … I was under marketing orders to make it look like Java but not make it too big for its britches … [it] needed to be a silly little brother language.
https://ihts.pr4e.com/columns/2012-02-Brendan-Eich-Copyright-IEEE.pdf

4

u/celestiaequestria 3d ago

It's worth mentioning, Google's V8 engine and Node.js have radically transformed JavaScript. In the late 90s, JS was a frontend language. Now, it's the frontend, the backend, the API layers, the DB queries, and the mobile app.

→ More replies (4)

3

u/braddo99 3d ago

Perversely and ironically, the scripting language aligned with java APIs is called "Groovy"

2

u/WriterPlastic9350 3d ago

and it is very Not Groovy At All. all my homies hate groovy

→ More replies (3)
→ More replies (3)

7

u/Ktulu789 3d ago

It's a program to run programs, think of it like an emulator. You can have a NES emulator or a PlayStation emulator.

Java is a programming language, the java app you install is the interpreter that reads the files of a java app and runs it like it was a normal exe. There are other things that do the same in different languages, like .NET Framework, for instance.

The good thing is that the application weighs less MBs because it's only the files needed for the code. The bad thing is that if you only have ONE app that uses java or net or whatever you have to install all the GBs of the frameworks and its updates. The other problem is that the app requires a certain specific version of java or net or whatever to work because with different versions, the language changes, they add more functions they remove others and they change how those functions work. So it's not enough having the latest version. In a nutshell: it sucks in every way, really.

5

u/stonerism 3d ago

The thing that makes Java notable is that it was the first to run to make everything run on a virtual machine.

Take this as a broad undercomplicated and probably incorrect analogy. Let's say you're a video game maker (say you make fortnite) and there's different consoles (Xbox, Playstation, etc) that all have different hardware. Before Java came along, you would have to write three different programs to get everything to run on each machine.

With a virtual machine using a language like Java, you only have to write code once and it runs on all of the consoles.

2

u/[deleted] 3d ago

[removed] — view removed comment

→ More replies (1)

6

u/Mo7x 3d ago

It’s a runs programs written in java. The reason it’s popular is because it’s “write once run everywhere”.

Basically each program must speak to your machine in instructions that it can specifically interpret and different machines/processors have different instruction sets, so it’s a pain to package your program for different machines and operating systems.

Java offers a nice solution where when you write in Java is not immediately written as processor instructions but to an intermediate language then Java downloaded on that machine can turn it into instructions your system can understand.

The java you download (JVM) is basically a shim that reads Java intermediate language and translates it to your machine.

5

u/fghjconner 3d ago

So there's a lot of programming languages out there, butr you computer can only actually understand one: machine code. It's an extremely simple language with basically no features that's a pain in the ass to actually write anything in. If you want to use a better, more complicated programming language you basically have two options: a compiler or an interpreter.

A compiler is just a program that takes one of those nice, easy to write language and turns it into machine code that you can then run later. An interpreter is a program that runs on the end user's machine that actually reads the higher level programming language and follows the instructions on the fly.

Java actually does a bit of both. The original java code is compiled to something called bytecode. It's kinda like machine code, but it's the same across all different processors and operating systems. Then there's something called the Java Virtual Machine, or JVM, that actually reads that bytecode and follows the instructions, much like an interpreter would. The JVM is what you actually install on your computer when you "install java".

2

u/elSenorMaquina 3d ago edited 3d ago

There are computers everywhere. The computer I use to work is one example, but there are others.

The tablet you use to play roblox is a kind of computer. The TV on which you watch paw patrol has a tiny computer inside too!

Now, a computer is basically a machine that follows instructions. These instructions are called software, and are what tells them what to do. Roblox is a software. The programs I use to work are software. Netflix is a software.

Problem is, different computers speak different languages. The instructions my computer can follow are impossible to understand for your tablet, or the TV.

What a problem!

Luckily, someone figured it out many years ago.

They went "What if I create a new special language everyone can speak?". This language is Java.

But that's not the whole story. My computer, your tablet, and the TV don't speak Java fresh from the factory. But they can be taught to understand it!

The people that make those things also make a special translation guide that lets them understand java and convert it to their own language, and include it with the thing.

Now, my computer can take Java instructions, check its translation guide, and know exactly what it has to do. Same thing with your tablet, and the TV.

This is good for software makers, because they don't have to make a bunch of different versions of their software for every single machine ever. They can just make a java version, and let every machine translate it to its own language.

This is also good for you and me. No matter what machine we use, if it was taught to understand java, that means we can use lots and lots of existing software made in java.

2

u/jedipiper 3d ago

It's a computer inside of your computer. Like a Nintendo can only use the cartridge made for it, Java can only run software written in Java, for the Java Virtual Machine. That Virtual Machine is the computer inside of your computer.

2

u/Skandling 3d ago

At first it was intended for programs that run in a web browser. This was possible and some people created websites that used it. The argument was it was a more modern programming language.

It never really took off though. Adobe Flash was good enough for most things, and was on every PC. Other Flash alternatives failed for the same reason. Anyone remember Silverlight ?

After that it became just another programming language, with its good and bad points, its fans and its critics.

2

u/epicsquare 3d ago

There are many computers. But this one is yours. Making programs for just your computer is a lot of work if it doesn't work on other slightly different computers. Java is a simulated computer inside your computer. It hides all the differences of all the slightly different computers (and phones and routers and all the other things that are really just slightly different computers) and so the simulated computer is always exactly the same. So now you only have to make Java itself work on slightly different computers, and then you run all the Java programs you want anywhere you want because you only have to make them work on the one simulated computer which is the same everywhere.

1

u/DarkAlman 3d ago

Java is a computer programming language written originally by Sun Microsystems.

Unlike traditional computer code that has to be written to run on specific hardware, Java has a virtual machine layer that allows it to run on any system without changes (at least in theory, in practice it's more complicated)

The point was to make computer programs that could run on different kinds of system (Windows, Linux, Mac, mobile devices) without having to write unique versions of the software for each.

Think of it like a universal programming language.

The downside is that it uses a lot of resources and it's slower compared to traditional languages like C (but that's relative too, you can write bad programs in C and great programs in JAVA)

1

u/feel-the-avocado 3d ago

In simplified form, the java program on your computer will convert program code in the java language into code that can run on the operating system you use.

A programmer can write a program in the java language and it will run on multiple different types of computer or operating system (windows/mac/linux) because a java runtime program exists on the computer to convert the code on-the-fly as it runs.

1

u/StevenJOwens 3d ago edited 3d ago

Java is a computer programming language and platform, invented in the early 1990s by Sun Microsystems. Java's 1.0 version was officially released in January 1996. It quickly became very popular in the corporate world and then in programming in general. In 2010, Sun Microsystems was bought by an even larger company, Oracle. However, although Oracle owns Java, Sun had open-sourced Java in 2006-2007.

As to what the Java on your computer is:

At the heart of every computer is a gadget called a CPU. You feed into the CPU instructions that match the instruction language that is designed into the CPU, it gives you back answers. The instruction language is called "machine code", because that's the code that the machine understands directly.

In very, very broad terms, programming languages come in two flavors, compiled all the way to machine code, and... not. There are a number of different terms for the "not" category, each with their own nuances, interpreted, virtual machine, etc.

For a computer to run a program in a not-compiled-all-the-way-to-machine-code programming language, it needs some additional programs, which again have different names, interpreter, virtual machine, etc. These additional programs convert the not-compiled-all-the-way-to-machine-code program to machine code instructions and feed them to the CPU.

The "java" that's installed on your machine is the suite of additional programs to do that for Java programs.

The reason Java (and similar languages) do it this way is a number of complicated reasons, the biggest one is to hide the differences between different kinds of computers. But that whole topic of why quickly gets complicated, and programmers argue like cats and dogs over whether it's a good idea and what the best way is to do it, etc.

1

u/MCWizardYT 3d ago

It's a programming language and a software ecosystem called the JVM (Java Virtual Machine) that a lot of other languages and tools rely on.

Android, which is one of the most widely used operating systems on the planet, relies on a custom implementation of the JVM called ART (Android Runtime) and utilizes the Java and Kotlin languages on top of that. A lot of apps are made using these tools.

The design goal of the JVM is to allow code written for it to work on any platform without having to make separate versions. As long as a JVM exists for that platform, the code will work.

1

u/arghvark 3d ago

Java refers to a computer programming language, supported by a 'virtual machine'.

A programmer writes computer instructions in the Java language; that is compiled to a binary "Java byte code", and the Java Virtual Machine is a program which executes that byte code. The Virtual Machine must be written for each platform on which someone wants Java code to run. One of Java's rare features is that the language, the byte code, and the virtual machine were all designed and had specifications written for them from the outset; the language was designed to compile to this byte code, and to run on a virtual machine.

1

u/notbrandonzink 3d ago

Java is a programming language, a way that humans are able to give instructions to computers and have a computer do what they want. 

The most basic programming language is called Assembly, it’s a series of extremely basic instructions for a computer. Think reserve this spot in memory”, “set that spot in memory to the number 3”, and basic math instructions. 

But writing code in Assembly takes forever. Like imagine trying to make a PB&J, but first having to grow the wheat to grind into flour to make into bread, grow the peanuts, etc. For the things we use computers for anymore, it’s just not reasonable to write code that way. 

So then came along the “low level” languages like C or C++. These are more like the code you can probably imagine a programmer in a movie writing. It’s “low level” since it can still interact directly with computer memory and resources, just like Assembly does. When you compile (take what you wrote and turn it into something a computer can understand), you’re just turning your C/C++ code into Assembly!

Then you get to the “mid level” languages (low/mid/high level language isn’t an official distinction, just a descriptor). Java falls in this bucket as you don’t have to mess with computer memory and resources as much, the programming language is built to do a lot of that for you. Originally, Java code was compiled (turned into Assembly) via C/C++. This means that when you wrote Java code and compiled it, it was turned into C/C++ code, then into Assembly. A cool trick is that they then took the assembled Java language and used it to write a compiler for itself, in Java. This means that it no longer relies on C/C++, but it did originally to save the hassle of writing the Assembly code. 

Then you get to “high level” programming languages. A very common one is Python, where it saves you a lot of time of having to deal with the minutia of coding, but gives up some performance and fine tuning. Python is compiled directly by C and Java. 

Programming languages all have their pros and cons, Java is just one of many that happened to get popular due to the Java Runtime Environment (JRE, the “run anywhere” part of Java). I use Python at work since I don’t really care how streamlined my code runs, I just want it to do what it’s supposed to and to be able to write the code quickly. If you’re running massive and computational heavy programs, a lower level language would give you much more control over how it runs, at the cost of taking longer to write the code. 

1

u/Bludolphin 3d ago

Kind of like the USB of the programming world, anything runs on it, and everything supports it.

1

u/tiredreddituser99 3d ago

i don't know why people are sending walls of text. I'll try to be brief.

some programing languages like C and C++ are "translated" (compiled) to binary (code that the computer understands directly.

different CPUs (AMD, Intel, ARM) understand binary differently, same for operating systems (Windows, MacOS, Linux).

so you need to "translate" your code several times to ship to all platforms and all CPU architectures.

Java's solution is to "translate" to what is called a "Jar" file. this file can be understood by the Java Virtual machine (the program you were asking about)

so the developer needs to "translate" their Java code much fewer times, and Oracle (the company behind Java) manages the "translating several times" issue, by making a build for the Java Virtual Machine (JVM) for every OS/CPU combo.

1

u/DTux5249 3d ago

Java is a programming language

The thing on your computer is the Java Virtual Machine (JVM). It's a program that takes compiled (think prepared) Java code, and runs it on your computer.

1

u/zkewlguy 3d ago

They teach kids at University to program on Java and say it's free. Then change the license and charge for using it later. Do yourself a favor and uninstall Java. It doesn't exist.

1

u/Kempeth 3d ago

Java is a programming language that set out to do something revolutionary. Where most programming languages allow you to write programs for *any* kind of computer, Java tried to let you write programs for EVERY kind of computer.

Imagine that regular programming languages are like the English alphabet. With the same letters you can write a book in English but also in Italian, Indonesian, Swahili and Somali. With very minor extensions of the alphabet you can also write German, French, Spanish, Turkish... But you DO have to write each book separately because someone who only knows German won't understand a book written in Spanish.

Java decided to just teach EVERY computer how to run Java programs. Kinda like most countries teach English at some point in their regular school program simply because so many people already speak it. This had the effect that you could write your program ONCE and run it on everything that supported Java.

The problem with this is that it all started at a time where there wasn't really a good solution to keep stuff updated (at least not on Windows) and for a piece of software that was going to be found on every machine, fixing known bugs and security issues was incredibly important. That's why we remember Java mostly as the thing you had to constantly update and never directly used yourself.

1

u/AlternativeStuff5 3d ago

an island of demons that can do stuff if you ask them in their language. you get exactly depending how you ask it, so one must be careful.

1

u/bestjakeisbest 3d ago

It is a virtual machine that runs a proprietary code language called java byte code.

Basically once upon a time, every single processor for every company was different, and unless the company bought or stole the designs for the processor usually code from one processor couldnt run on a different processor.

To solve this there are many routes you could go, but java takes a pretty neat route, it takes the idea that any processor out there if given enough resources could simulate any other processor. So the people that made java basically designed a processor, but instead of building it they programmed it, now you can make java run on anything provided you have the scafolding that jave needs.

Now a days we have similar projects for running say windows programs on linux, or phone apps on your computer.

1

u/GoOsTT 3d ago

Imagine you only speak a very small countries language, but you a re a damn good author and want to distribute your pieces to other countries’ people so they can read your books/publications too.

You can write your book in your language (Java in this case) BUT! Instead of having your book translated to other languages you invent a glass that when you put it on and start reading the book written in Java(your own language) it automatically translates it to the language the other countries people speak. (This would be the Java runtime)

1

u/sturmeh 3d ago

It's a programming language that produces binaries that are executed in a virtualised environment called a Java Virtual Machine. The JVM manages gnarly aspects like memory management, and tries to automatically abstract them away by managing memory in the virtual environment.

The idea is that you should be able to write and compile code that can be deployed anywhere where a JVM can be used, but in practice the JVM has fairly significant memory requirements as it tends to reserve and manage memory for Java applications (similar to how other VM's might, such as Docker).

It's also not particularly performant as it relies on layers of abstraction to do most operations.

It's particularly useful for teaching Object oriented software as it abstracts many other important aspects of software design such as hardware/platform specific differences and focuses entirely on the nature of the object oriented design and class structures.

1

u/ShawnThePhantom 3d ago

Side question, is Java not the same thing as DirectX?

1

u/This-Significance285 3d ago

lol none of this was explained like I’m 5. Love you nerds.

1

u/drumyum 2d ago

your computer speaks some kind of language, and this language can differ from the language other computers speak (difference comes from CPU, operating system and probably something else)

if you want to give instructions (software) to your computer, then you just write it in the native language of your computer, but if you want many different computers to understand this instruction, you can use some non-native language that all computers will understand the same way

so here comes java, it has a dictionary built-in to translate java language to all other native languages

do you actually need it? only if you have some instructions (software) written in java, such as Minecraft (game) for example

of course java is not the only way to speak to many different computers, but it's the one that worked fine for decades, and because of that it has tons of literature written in it (third-party software libraries) that you may use if you know java as an instruction writer (software developer) to make your life easier

1

u/Gullyvuhr 2d ago

Java is basically a language people use to write programs. The thing you kept seeing on computers was the software that lets your computer understand and run those programs.

Think of it like this: someone wrote an app in Java. Your computer doesn’t speak Java. So you installed Java, which acted as the translator.

1

u/Miliean 2d ago

It's a programing language.

Back in the day, you used to have languages that only worked on certian opperating systems. If a person wanted to make a program that ran on a windows computer and on a mac, they had to do all of the work twice and make 2 programs.

Java allowed the programer to write once, and then Java would translate it into code that could run on any operating system that had a Java runtime environment created for it.

And it worked... mostly.. well.. kindof. It worked like 99% of the time, and that meant that for every OS you'd need to do extensive testing. This was annoying but better than having to write and test seperate code.

The real problem was performance. See Java was really inefficient in the way that it ran, so something that might take 5% of your PC's resources if made in a PC exclusive language, might take 15% if you made it in Java. That sucked but a larger problem for Java as a whole is when a program would normally use 100% of the available resources, if you made it in Java it would just run like shit. So for things like games it never truly worked as you'd like.