Java Introduction
Java is a popular programming language used to build apps, websites and business software.
What is Java?
- Java is a programming language first released by Sun Microsystems in 1995
- Today it is owned by Oracle, and new versions come out every six months
- Java is object-oriented: programs are built from classes and objects
- Java is compiled into bytecode, and the bytecode runs on the Java Virtual Machine (JVM)
What is Java Used For?
| Area | Examples |
|---|---|
| Mobile apps | Many Android apps are written in Java |
| Web servers | Back-end systems of banks, airlines and online shops |
| Desktop software | Tools like IntelliJ IDEA are written in Java |
| Big data | Tools such as Hadoop and Kafka run on the JVM |
| Games | Minecraft (Java Edition) is written in Java |
How Java Runs Your Code
When you write Java, you save it in a file that ends with .java. Running it takes two steps:
- The compiler (
javac) turns your.javafile into a.classfile full of bytecode. - The JVM (
java) reads the bytecode and runs it on your computer.
Because every operating system has its own JVM, the same .class file works on Windows, macOS and Linux. You do not need to rewrite anything.
A Small Java Program
Here is a program that prints two lines:
Example
public class Main {
public static void main(String[] args) {
System.out.println("Welcome to Workownix");
System.out.println("Let's learn Java");
}
}Welcome to Workownix Let's learn Java
Do not worry if this looks strange. In the next chapters you will learn what class, main and System.out.println mean.
Java Can Do Maths Too
Java can calculate values and print the result:
Example
public class Main {
public static void main(String[] args) {
int price = 250;
int quantity = 4;
System.out.println(price * quantity);
}
}1000
Here Ali buys 4 notebooks at Rs 250 each, and Java works out the total.
Why Learn Java?
- It runs on almost every kind of device
- It has clear rules, so it is a good language for learning how to program properly
- It is fast, safe and used by big companies
- Knowing Java makes it easy to learn C#, Kotlin and many other languages
Java and JavaScript are two different languages. They only share part of their name. Java is used for apps and servers; JavaScript mostly runs inside web browsers.
Exercise
Exercise
What runs Java bytecode on a computer?
