Introduction to Java · Lesson 1 of 150
Introduction to Java
Java is a programming language that lets you write instructions a computer can follow to solve a problem or run an application.
01What is Java?
Java is a programming language that lets you write instructions a computer can follow to solve a problem or run an application. It was built to be simple to read, safe to use, and able to run on almost any device without changes to the code. Today, Java powers everything from Android apps to banking software to large enterprise systems.
02Why is it used?
Companies choose Java because one Java program can run on Windows, Linux, or Mac without being rewritten. It also has strong safety checks built in, a huge collection of ready-made tools (called libraries), and a massive community, so help is always available when you get stuck.
03Real-Life Example
Think of Java like a universal remote control. A normal remote only works with one brand of TV, but a universal remote works with almost any TV brand. In the same way, a Java program, once written, can run on almost any computer or device that has Java installed.
04Syntax
java// A Java program always starts inside a class public class MyFirstProgram { public static void main(String[] args) { // instructions go here } }
05Example Program
javapublic class Welcome { public static void main(String[] args) { System.out.println("Welcome to Java!"); } }
Output:
Welcome to Java!06Key Points to Remember
- Java is a general-purpose, object-oriented programming language.
- "Write once, run anywhere" is Java's biggest selling point.
- Java is used in mobile apps, web servers, desktop software, and more.
Practice Problems
Try each question yourself first, then check the answer.
Explain the slogan
In one sentence, explain what "write once, run anywhere" means and name the component that makes it possible.
Show answerHide answer
Predict the output
javapublic class Main { public static void main(String[] args) { System.out.println("Java"); System.out.println("powers Android apps"); } }
What exactly is printed?
Show answerHide answer
Java
powers Android appsSpot the mistake
A beginner writes their print statements straight into a file with no class around them, and the program will not compile. Which rule did they break?
Show answerHide answer
main method inside it.Recall
Name three real-world areas where Java is used, as mentioned in the notes.