General Question

Hypocrisy_Central's avatar

What does Java run, operate, or do?

Asked by Hypocrisy_Central (26879points) October 27th, 2015

Figure I might as well get what I need on the way out the door.

I have Googled it and either gets near misses or nebulous explanations. I understand Java is a language, as C+ and C++, etc. though not exact as them. Google sent me to sites that says what industries etc. make use of Java, or which gadgets make use of Java but I have not really found any that says ”Java is used for this, this and that”. I JUST KNOW someone here has an inkling of what it does. Does it compile, crunch numbers, arrange data, track data, what? When you GA someone and it shows up immediately or soon after on the Fluther leaderboard on the right, was that an example of Java, or something else? Where is that Ben guy when you need him? If I read right, Java is a server side application where JavaScript is a client side or browser based application, but Java does something, what does or can you do with it?

Observing members: 0 Composing members: 0

25 Answers

gorillapaws's avatar

This is a bit complicated, but I’ll do my best to explain. At a fundamental level a computer program is simply a series of instructions the CPU in your computer executes in sequence. Programming languages are either compiled or interpreted from code that people understand into code the machine uses to execute those very basic instructions. This code is known as assembly code (which is ultimately converted to machine code). Theoretically you could write a program like Photoshop in pure assembly code, but it would take you several lifetimes and your eyes would start bleeding within a couple of days of trying to work 100% in assembly. Not to mention that version of photoshop you wrote would only ever work on that particular chip architecture.

Java is a compiled language, that means you pass your finished code to a Java compiler program which converts your human-readable Java code into assembly code that your CPU understands how to execute (and is really hard for people to understand). The compiler will catch many of your mistakes and will throw errors if you’re trying to violate the “grammar” (more commonly known as “syntax” in programming) of the Java language. One misplaced ’}’ or ’;’ and the whole process of compiling your program will fail.

I’m not sure how Fluther is written, so it’s hard to say, but if it was written in Java, then yes, giving someone a GA will trigger code to execute on the server and it will update the webpage to display an incremented number next to the post (as well as other updates in other places).

JavaScript and Java are two very different languages, despite both having “Java” in the name. Javascript was named that way as a marketing thing because “Java” was a popular language at the time and it was trying to “ride the coattails” of the Java name. JavaScript is not compiled by the way. It runs in an interpreter. Interpreters are constantly running. They take code and execute it “on the fly” as it comes in instead of having it all finished ahead of time and then converting it to assembly code all at once. A program that was compiled will run much faster than one that’s running in an interpreter, because there’s overhead (memory and CPU usage) involved in running the interpreter.

Here’s a way to thing about it: Say there’s a book written in Korean (assuming you don’t speak it). In a compiled language, it would be like having the Korean book translated to English and published in an English book version for you to use. You could jump to any page and start reading the English version. An interpreted version would be like buying the Korean book, and getting your friend who speaks Korean to sit with you and you pointing to a paragraph in the book and having them translate it into English for you while you wait. It’s an inherently slower process to do “on the fly.”

Hope that helps a bit.

Hypocrisy_Central's avatar

@gorillapaws Hope that helps a bit.
Yes it does, even some of the parts that backtracked over what I did know. Having taken HTML I understand syntax, I also knew Java and JavaScript were different but you explained it in a more streamline way than the Web sites I visited. However, the part you missed, if you can expound upon, is where or what is Java used for? I hear all the time that Java runs a lot of apps or such on Smartphones, cellphones, etc. which I do not really use, or in several banking type industries. Exactly what Java does, or if I even see it at work I have no clue. If I did I might think why did they use Java there instead of C++ or something like that.

jerv's avatar

If the average person even notices that Java is running, then whoever coded it did a shoddy job; if you haven’t seen Java in action, then that means they did it right. However, the question does require a little disambiguation; Java could refer to either the language or the software platform. While Java is technically a compiled language that outputs to byte code, the Java environment involves “just in time” execution of byte code, which makes the Java environment resemble an interpreted language.

Java (the language) is nice in that it’s byte code runs on anything capable of running a Java Virtual Machine (JVM), including browsers with the proper plugins. It is totally platform-agnostic; the same hunk of Java code will do the same thing on my Win10 desktop, my buddy’s Debian box, or a MacBook. While C++ can be compiled to spit out something capable of running in whatever OS the compiler is set for, it cannot be run “on the fly”, making it a poor choice for things like web-apps where you have no idea what sort of system the user is running. With Java (the language), the site builder just compiles some Java to byte code, puts that intermediate byte code up, and leaves the whole interpreting to machine code thing up to the client (who, presumably, has a JVM going).

As the owner of an Android phone, I use Java a lot even when I am nowhere near my computer. I never think about it. Every Android app is written in Java while Android itself is the interpreter. In truth, there are a few complications like the differences between JVM and Dalvik, but “Android is Java” is close enough for a layman’s explanation.

One downside to Java is that while it normally runs in a virtual machine, it’s quite capable of breaking out of it’s sandbox and doing nasty things. That security concern is enough to make many advise against having anything to do with Java at all. And, as @gorillapaws points out, interpreting on the fly has CPU and RAM overhead that impacts performance compared to, say, C++ that gives up a little flexibility (you have to compile a different version for each OS before execution is even possible) for the sake of faster execution.

* * * * *
@gorillapaws “Theoretically you could write a program like Photoshop in pure assembly code, but it would take you several lifetimes and your eyes would start bleeding within a couple of days of trying to work 100% in assembly.”

I hear Linus Torvalds programs in raw electricity, arranging electrons into binary code using nothing but the powers of his mind.

gorillapaws's avatar

The answer to this adds an additional layer of complexity. All programming languages are pretty simple things at their core, you have the ability to create functions (which you can think of as verbs or actions that may or may not take an input and may or may not return something when it’s done) and you have data types like: booleans (true/false), integers (whole numbers), floats(numbers with decimals), strings (a sequence of letters/characters), and collections of those data types. For example one type of collection is an array (called a list in some languages). You might have an array of integers like [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41]. Lastly you can combine these basic types to create structures and/or objects that represent some concept with multiple properties/fields. So you might have a person object with a firstName string property, a lastName string property, and a shoeSize float property, a boolean property called isAlive and an integer property for that person’s hitPoints. There might be a function (remember it’s like a verb or action) associated with that person called receivedImpactFromFallingAnvil() that has the effect of decreasing the person’s hitPoints by a random number between 6 and 8. If that causes the person’s HP to fall to 0 or below, then it will set the isAlive boolean to “false.”

You can use these objects to make even more complex objects, and so on. The result of this is that people create and share frameworks that allow you to do useful stuff without writing every little detail from scratch. You don’t have to draw each pixel point-by-point and can instead use a drawing framework that someone wrote and call a function in the framework that might look like drawWindow( 0, 0, 300, 500 ). This will create a new window at origin (0, 0) with a height of 300 and a width of 500. You don’t have to understand how the machine is rendering that window onscreen, only how the function is supposed to be used. I hope it’s clear how that simplifies things. If everyone was always trying to reinvent how to make a window all of the time, nothing would get done. Instead someone smart figures out how the window code should work, and then they publish it for everyone to use in a framework.

I’m not very familiar with Java, but I know there are many very popular frameworks that exist for it. So when people say “Java is good for mobile,” what they mean is there are some good mobile frameworks written in Java that you can use to make mobile apps. In this particular case, Android apps are written in Java with Google’s Android frameworks. There are probably many server frameworks for Java that allow you to write server Java code without having to reinvent the wheel that probably take into account the best security practices, etc and you can just trust the framework and make your program.

As I understand it, Java is a decent language. It was very popular in the late 90’s to the early-mid 2000’s. As a result there are many people who know it. That said, there is nothing particularly remarkable about it that I’m aware of, other than being widespread. If you’re researching where to start with programming, I would encourage you to take a look at Python first. It’s a “clean,” “simple,” and “elegant” language that many schools use as a first language (including MIT). It’s interpreted so it’s a bit slower and you’re not going to write a high performance first person shooter in Python, but there are a bunch of frameworks for writing games and web development with Python. Furthermore, by the time you’re ready to write performance critical code, you’ll be able to learn new programming languages much more quickly (so don’t get too hung up on performance in the beginning).

Hope that helps.

@jerv LMFAO

jerv's avatar

While Java is important for any web designer to at least be familiar with, and outright essential for anyone wanting to do Android apps, Python is also an important language for web designers to know, especially with some developers moving from Java to Python while some programs already are written in Python; things like Dropbox and the software manager in Ubuntu.

Python code is definitely more readable; readability is a core part of The Zen of Python.

@gorillapaws I have a T-shirt you’d love; “Python, Programming the way Guido indented it.”

Hypocrisy_Central's avatar

@gorillapaws Lastly you can combine these basic types to create structures and/or objects that represent some concept with multiple properties/fields. So you might have a person object with a firstName string property, a lastName string property, and a shoeSize float property, a boolean property called isAlive and an integer property for that person’s hitPoints. There might be a function (remember it’s like a verb or action) associated with that person called receivedImpactFromFallingAnvil() that has the effect of decreasing the person’s hitPoints by a random number between 6 and 8. If that causes the person’s HP to fall to 0 or below, then it will set the isAlive boolean to “false.”
So, if I ever took up the offer to use Match.com and I enter the fields that indicate what attributes I feel my perfect mate should be, that would be Java in the background? There are floats (I guess you’d call them that) on occupation, marital status, maybe hair and eye color, etc. which once you enter them, and have whatever execute those choices, the program in the background has to know how or which to choose from whatever choices it is programed to choose from, unless it is something it can’t possibly know before hand, such as data the user would have to fill in about themselves.

It’s interpreted so it’s a bit slower and you’re not going to write a high performance first person shooter in Python, but there are a bunch of frameworks for writing games and web development with Python.
Can it do anything other than create games, what about ecommerce, Q&A site, interactive blogs, or other sites?

jerv's avatar

“So, if I ever took up the offer to use Match.com and I enter the fields that indicate what attributes I feel my perfect mate should be, that would be Java in the background?”

Maybe. It definitely could be; Java has that capability.

“Can it do anything other than create games, what about ecommerce, Q&A site, interactive blogs, or other sites?”

I already listed two examples of Python programs; a cloud storage program (DropBox) and a couple rather important parts of the Ubuntu operating system (their Software Center package manager). There are also plenty of programs that use Python as a scripting language; LibreOffice, FreeCAD, and Blender to name a few.

gorillapaws's avatar

@Hypocrisy_Central Python can do just about everything Java can do. In some cases Python may not have the same frameworks as Java (e.g. you’re not going to be using the Android Java frameworks with Python), but there are many awesome frameworks that Python has and Java doesn’t (e.g. the Django web framework is famous). You can certainly build interactive websites with Python frameworks and using HTML + CSS to present the UI. As @jerv mentioned, Dropbox is written with Python, I know Google uses it for a lot of their stuff too.

There are other languages that are great for web development too. Ruby is a popular rival to Python and could be worth investigating as well. You could build something like Fluther or Match.com with a bunch of different languages. If I were looking to learn my first programming language and wanted my first project to be building a dynamic website. I would choose either Python or Ruby. Between the two, I prefer Python, but other people prefer Ruby. If it was 2003 I might choose Java, PHP or Perl. If I wanted to build Android apps, I’d choose Java, and if I wanted to build iOS apps I’d choose Swift.

The thing that’s hard to communicate to someone who has never programmed before is that once you learn one programming language, learning others is reasonably easy. The hard part is learning how to take a real-world problem and break it down into something that code can solve. It’s learning good programming habits and patterns. There is a ton to learn when you’re first starting out, but most of that will cary over to every other language you ever learn.That’s why I recommend Python as a good first language. You’ll have enough to worry about trying to learn general programming concepts, so going with a language that’s pretty straightforward and easy to follow without a lot of complexity or visual noise, messy syntax, and difficult concepts like complex memory management (like in some languages) allows you to focus on developing the critical core programming skills.

Hypocrisy_Central's avatar

@gorillapaws The thing that’s hard to communicate to someone who has never programmed before is that once you learn one programming language, learning others is reasonably easy. The hard part is learning how to take a real-world problem and break it down into something that code can solve.
I do not know if HTML would be considered a programming language, but it is where I get the concept of syntax (less the little DOS I hardly remember), however the early HTML, don’t know about the latter versions, was not so anal that case or in some cases spaces mattered. I know with the advent of newer HTML I feel some of the ”gadgets”, or bells and whistles distract from the site more than they add, they do not seem to add, for me, an increase to my interactiveness on the site. Having the site be able to do real time and useful stuff is more important to me, finding out what can do it sometimes gets nebulous.

gorillapaws's avatar

HTML is a markup language. Programming languages are different in what they’re designed to do. You’re right that there are similarities in terms of the strictness of the syntax.

The tricky part of programming is to take a real world problem like “I want to take a list of all files in a given directory and strip the extension off of the filename if it has one.” And accomplish that using variables, conditionals, loops and functions (possibly objects too). Your general approach to solving that problem will be very similar in nearly every programming language, even if some of the details are different in each one. It’s much like how writing a good essay in English and in Korean will probably follow similar principles even if the grammar and vocabulary are very different.

jerv's avatar

@gorillapaws That is why I feel that those who wish to learn programming should start off ignoring languages altogether and start with flowcharts. How can you write code in any language if you don’t know what even needs to be done?

gorillapaws's avatar

@jerv I can get behind that. I often sketch the flow of my code on paper before writing it out. There is something to be said though for the magic of seeing the machine execute your code though that is hard to replicate with a pen/paper. Also, when you make a logical error, it’s often not apparent in a flowchart as it would become when the program executes.

jerv's avatar

@gorillapaws True, but I find it hard to write code that does what I want it to do without even knowing what it is I want to do in the first place.

I suppose that if I were a quantum computer I could just write all possible code and then collapse the waveform to get a hunk that does what I want, but I’m not so I can’t.

Hypocrisy_Central's avatar

@jerv That is why I feel that those who wish to learn programming should start off ignoring languages altogether and start with flowcharts. How can you write code in any language if you don’t know what even needs to be done?
How does that not bite you in the arse if you write a flow chart of what you want to happen but not know if there is a program that will do it, or would you have to use JAVA, Python, JQuery, etc. to build a way to do it from scratch?

jerv's avatar

Well, that depends.

In the Linux world, many people have a thing against reinventing the wheel, so there are certain places you can go to find all sorts of code from people who have had a problem, come up with a solution and now feel like sharing that solution with the world.

Of course, sometimes coding your own from scratch is easier than trying to find someone else’s code, but there is very little way to know whether it exists without looking. Even if what you need seems esoteric like trying to find a library to help you talk to an obscure brand of electronic toaster through your DVI port, there is a chance that someone out there was actually bored enough to do that, write the necessary code, and post it before that crazy idea popped into your head.

In general, those who code a lot also have other knowledge that helps them though, like where to look for “recyclable” code. In fact, looking for such bits is part of the planning process, just as when I cook I check to see that I have all the ingredients and shop as-needed before I start the actual process of turning those ingredients into food.

Hypocrisy_Central's avatar

Discovered Fluther was created with Python and Dejango (or something close to it). I guess that means they could not do it in Java? There were other things involved like Ubuntu and MySQL (which I have no idea what they do)

jerv's avatar

Many things on teh web use LAMP;

Linux – The majority of servers run some form of Linux. Ubuntu is one of the most popular Linux distros.
Apache – The most widely used HTTP server program in the world.
MySQL – Sites generally have a database behind them, so you need something. The three most popular are MySQL, Microsoft SQL Server, and Oracle. MySQL is popular because it’s open-source, which matters to many for reasons far beyond the scope of this question.
Programming language – You can pick just one, but the three most common all start with the letter P; Perl, PHP, and Python.

Django is a web application framework; a tool for using Python more effectively. More to the point, Django is geared towards handling complex databases in ways that someone running a site that relies more heavily on databases might find desirable. Like MySQL, it’s also open-source; it’s maintained by a certified 501c3 non-profit foundation.

It’s likely that this site could have been made in Java but wasn’t simply due to the preferences and skillsets of those involved. Then again, Django is pretty well-suited for databases, so even if we stipulate equal proficiency in both Java and Python, Django may have been a compelling argument to choose the route they did.

gorillapaws's avatar

@Hypocrisy_Central They could have built Fluther with lots of different languages/frameworks. As @jerv says, they CHOOSE to do it for any number of reasons:
1. Maybe they like Python better than Java
2. Maybe they already knew Python and didn’t want to take the time to learn Java
3. Maybe they WANTED to learn Python/Django and this site was their excuse to try something new.
4. You get the idea.

They could have made Fluther with Ruby using Ruby On Rails.

Ubuntu is just a version of Linux running the server somewhere.
MySQL is a database. There are many different types of databases. MySQL is popular, but Postgres is gaining traction (It’s also open-source… but with a more-permissive open-source license) and is better in nearly every way. At some point you’ll want to learn how to write SQL so you can store info in databases. For this I suggest Postgres.

Hypocrisy_Central's avatar

^ Now you have my head spinning, I will have to go study all those now to see what exactly they are suppose to do.

jerv's avatar

Just so you know, the reason Linux is generally used for servers is because of it’s performance and reliability. Programmers usually find it easier to work in the same ecosystem as the end result of their labors, so a lot of web developers use Linux simply because the code they make will be running on a Linux box.

I don’t know the cause and effect relationship that has with Linux often coming with all sorts of dev tools preinstalled that a Windows developer would have to go out and get separately, probably paying extra for to boot. However, regardless of which caused which, Linux often already has at least some of those tools by default, and most definitely has them available easily and cheaply. For those devs who are concerned with software prices, that in and of itself is a compelling reason to go Linux for web development.

While it’s possible for a dev to get the tools to work in Windows, they still need to be at least somewhat familiar with Linux and how it handles certain things in order to avoid problems… but which Linux?

Right now, Mint is the big thing; according to Distrowatch it has almost as much as the next two (Ubuntu and Debian) combined. Some are geared more towards those new to computers or who are migrating from Windows, some are specialty builds that only a geek would understand.

There are enough distros for a neophyte to get quickly confused by option shock. And needlessly so since they all run some version of the same Linux kernel; some use older versions than the most recent version that came out (literally) last week, but it’s still the same kernel as every other Linux distro uses. In that regard, all Linux is the same.

gorillapaws's avatar

Just to add to @jerv‘s point about why Linux is often used for servers. One is that a lot of the time you run your server remotely from the command line, in this case the pretty graphics or fancy user interface stuff in an operating system are completely meaningless.

Another huge reason is security. Because these Linux distros are open source, and there are tons of networking/server/security guys living/breathing this Linux server environment stuff, you have a lot of smart people closely scrutinizing the security of the platform. If you find a vulnerability in Windows for example, you have to submit a bug report to Microsoft and it could be months (or longer) before they fix it. When security vulnerabilities are found in Linux it is my understanding that they’re fixed very quickly.

Lastly is cost. Running Microsoft servers are very expensive from a licensing standpoint, by comparison Linux is free.

To expand a bit about the database stuff. Databases are like spreadsheets on steroids. Fluther is built on one, so there is a table for all of our accounts, there is a table for each thread, and a table for posts. Each table has several column. A post would have a reference to the account who posted it, the content of the post (a string), a great answer count, a date it was created, probably some kind of post_ID number used internally to reference them, etc.

There are many different kinds of databases, but nearly all of them use a language called SQL to add/remove entries as well as retrieve them. SQL is known as a declarative language (you “declare” what you want and the machine figures out how to do it for you, most programming languages the programmer is coding all of the stuff that makes it work), and it’s pretty easy to learn the basics. It’s something you would learn down the road after learning a programming language.

If you’re interested in learning how to make a site like Fluther, take a look at this tutorial for Python/Django by Django Girls. It’s targeting a female demographic, but it’s well done and very approachable.

jerv's avatar

Databases are a little world in and of themselves. The thing is, no matter which “dialect” of SQL you learn, that language can only really handle databases; it wasn’t exactly designed for pretty web sites. That means that you’ll be using at least two languages to make a website that relies on a database the way Fluther does.

Also, while Linux is free, it and much of the software available for it are also free. You know all those pages of terms and conditions that most people click through that have all sorts of escape clauses and “gotchas”? Well, forget them. Microsoft reserves the right to do pretty much as they damn well please to Windows and any computer that runs it, but much of the Linux software out there is free of all that. And if you’re a code ninja that needs to modify the code, you are free to do so!

Hypocrisy_Central's avatar

@gorillapaws @jerv So of all the programs you mentioned, hey are all server side applied, or some are browser side applied?

jerv's avatar

Apache is most definitely server-side, almost by definition.

Django is just a tool to make the site; once the site is done, so is Django.

Linux is an operating system and thus kind of transcends the whole client/server thing. While most servers run Linux, not all do. And while some PCs run Linux, most run Windows. Not all clients are PCs either. Some are Macs running OS X, some are iDevices running iOS, many are smartphones running Android (which is kinda-sorta-but-not-really Linux). Linux can be on either end, both or neither.

And my brain just dried up. It’s past my bedtime.

Response moderated (Spam)

Answer this question

Login

or

Join

to answer.

This question is in the General Section. Responses must be helpful and on-topic.

Your answer will be saved while you login or join.

Have a question? Ask Fluther!

What do you know more about?
or
Knowledge Networking @ Fluther