I’ve even gotten to the point of asking folks to talk about the difference between the two languages in order to help isolate this issue.
I’ve also met many technical folks who call Java programs, files or applications “java scripts”. This overloading of terms is likely the culprit of not a few mislearnings.
Java is owned and managed by Oracle Corporation (as of this writing, in 2021). It was created in the 1990s my James Gosling. It was originally called “Oak” among other names… you can learn more here.
Oracle gained the rights to Java with the acquisition of Sun Microsystems in 2010. If you don’t know who Sun is, well, you’re just too young. Get off my lawn!
Java was designed to “write once, run anywhere”. It uses a runtime environment to run machine code that is generated by a compiler. Because it is compiled into machine language it is not, strictly speaking, an interpreted language. Because it is interpreted on at runtime virtual machine, it is not, strictly speaking, a compiled language. For many years, people have referred to it as a “hybrid” language, having characteristics of both types of languages.
Java is an Object-Oriented Programming language. The smallest compilable component of a java program is a class which defines the behaviors of an object at runtime.
Classes have strict access definitions (unless you cheat and use reflection to thwart them). Classes contain data, called members and functions called methods.
Java is strictly typed, meaning it has primitives (int, boolean, float, double, char, etc) and higher-level classes which define more complex types. All defined variables must have a type defined (or class). The exceptions to this are interfaces and abstract classes with basically give you malleable type and enable what we call “polymorphism”.
Java’s architecture allows for inheritance from one class to the next of members and methods.
While Java was originally designed and targeted to work for client-based applications, it has become widely used on enterprise and service-side applications.
To the untrained eye, the two languages look very similar, but as you work with each language some major differences become apparent.
For instance, in Java, objects passed to methods are said to (this is a bit of a lie, explained here: https://stackabuse.com/does-java-pass-by-reference-or-pass-by-value/) be passed by reference (primitives are by value). For almost all pragmatic programmers an understanding of java as passing objects by reference works.
Note: technically, java passes the value of a reference to an object, but that’s not really a distinction most people make, in practice its easier to conceptualize as passing by reference.
Even the dot notation is different.
The concept of “this” is completely different between the languages.
Ecosystem (dependency management)
One of the most overlooked differences between programming languages is what I call “ecosystems”. Language ecosystems consist of the tooling near and around the development and deployment of applications built in a language. These tools can be dependency management tools, package managers, IDEs, runtime considerations and configuration, runtime environments (like web server applications), and common partnering applications in tech stacks. For brevity and by way of exemplifying how significant each type of tool can affect those using these languages, I’ll focus on dependency management tools.
Any dependency issues are found at runtime (by virtue of being an interpreted language). Runtime can be simulated, of course, in an IDE or other environments.
Java on the other hand, needs dependencies at “compile time”, when the machine code is generated. Two heavily used dependency management tools in Java are Gradle and Maven. Because my experience in maven is more rich, I’ll talk about it.
Maven is a program (mvn) that runs through a lifecycle related to code development. The actions associated with different phases of that lifecycle are defined in a file called pom.xml. On first running, like npm, maven uses the pom.xml file to find repositories on the internet (or network or local file system) that contain the dependencies defined in the pom.xml file. These are then compiled into the java application at compile time. Maven allows for the type of packaging that should be provided for the compiled code (war, jar, etc). It’s been quite some time since I’ve worked with maven deeply, please feel free to provide updates and references in the comments.
There are many more differences between these languages, but these are a few off the top of my head.
The question sometimes helps me start a conversation. Sometimes it determines if the conversation should continue.
I can’t tell you how many times I have people google the answer to this question and read it to me in a phone screening. Do folks really think I can’t hear them typing? That I haven’t looked up the default answer on google? Bing? others? That I don’t recognize the answers or when I’m being read to?
While I hope you learned something from this post, or found a way to contribute to its betterment, I’m mostly writing it out of selfishness. I guess if I have to choose, I’d rather hear people parrot my writing back to me than duckduckgo the answer for me.
Let me know if this article helps you!