Tino Intro To Java

Last modified: January 07, 2024

Goodbye JavaScript. Hello Java

In the first semester, you learned the JavaScript programming language on CodeHS.

In this semester, you will learn the Java programming language.

Java is a high-level, general-purpose, object-oriented, and machine-independent programming language.

While both languages contain "java" in their names, Java and JavaScript are two distinct programming languages with different syntax, purpose, and design. Although, much of the syntax looks virtually the same, there are important differences.

Differences between Java and JavaScript

Here are some basic differences between the two languages:

Java JavaScript
Created 1996 1995
By James Gosling Brendan Eich
Typing Static Dynamic
Purpose Backend Frontend
Executed by JVM Browser

Here are some details on the biggest differences you will run into when transitioning between Javascript and Java:

Java JavaScript
Semicolons are strictly required in Java. Semicolons are optional in Javascript because the interpreter will automatically insert them as needed when parsing the code.
Java variables must be assigned a specific type when declared and that type cannot be changed during program execution. For example, in Java, to store an integer value, you would declare a variable int x and x will only be able to store integer values like 5 (not decimals like 5.8 or String objects like "hello"). In Javascript a given variable can store different types of data at different times during program execution. For example, you could declare var x and x could be assigned to an integer like 5 at one point and later be assigned a decimal value like 5.8 and then later assigned a string value like "hello".
When working with Java, you must write and use classes because Java is a strictly Object Oriented Programming language (OOP) that requires all code to be written inside a class. In Javascript you can get along fine without writing any classes. Although you can still write classes in Javascript and you will likely still use classes from libraries such as the Circle, Rectangle or Randomizer classes from the CodeHS library, you can go a long time without being aware of the concept of classes in Javascript because Javascript programs do not need to be strictly written in classes. It is entirely possible that you just found out classes even exist in Javascript.
When working in Java, there are two stages to running a program. First you have to compile the program, which is a process where the compiler translates your human readable code into instructions called bytecode that are only meant to be read by a Java Virtual Machine (JVM). Second, when you actually run the program, the Java Virtual Machine translates the bytecode into low level instructions to be run on a specific system such as Windows or MacOS and executes those instructions. To run Java, the user needs to have a Java Runtime Environment (JRE) installed. The JRE includes a JVM along with compiled libraries and other supporting files. To develop a program in Java, you need to download a Java Development Kit (JDK) which, in addition to containing a JRE, also includes a compiler and some other development tools. When working with Javascript, to run a program, you can simply execute the program in the browser, in fact if you open your browser console you can even write code directly into the console and it will execute on the page immediately. While there are other ways to run Javascript, it was original designed to be executed line by line in a browser to add dynamic features to a website rather than having to be packaged into a complete program before execution. Thus, there is only one step required to run Javascript code.

The History of Java

Source: Java Point

In the early 1990s, a computer scientist from Sun Microsystems named James Gosling was tasked with developing an interactive software for TV screen.

James Gosling - founder of java

To create the software, Gosling first tried to use the C++ programming language, but quickly realized that C++ could not adequately fulfill the objective.

So, Gosling created his own programming language. He initially titled it "Oak". However, after discovering that Oak has already been trademarked, Gosling had to change the name of his new language to Java.

That was the birth of the Java we know today.

Java Today

Today, more 10 million software engineers use Java to create backend servers, laptop applications, video games; control robots, perform data analysis, and the list goes on...

Thanks to its versatility and employment-competitiveness, Java is frequently chosen as the programming language for high school and university-level CS courses. It is also the star of the Intro Java (which you are taking right now) and AP Computer Science at CHS.

Dark Mode

Outline