A Brief Introduction to the Java Programming Language

Java is a general purpose programming language developed at Sun Microsystems starting in the early 1990’s. Some programming languages are developed for a specific purpose, such as typesetting (TeX and LaTeX), printing (PDF), mathematics (Mathematica), civil engineering (COGO), and manufacturing (APT). Computer scientists at Sun Microsystems developed Java to be a general purpose programming language so that a software developer could use it to solve problems in many computing disciplines. In 2010, Oracle Corporation aquired Sun Microsytems which is why you can download Java from Oracle’s website today.

Java was designed to make programming easier and less error prone than other popular languages, especially C and C++. To make programming easier and less error prone, Java includes garbage collection, array index checking, and primitive data types with a defined size and eliminates unsigned data types. To enable programmers to write a program once and run it on any computing device, Java was designed to compile to an intermediate computer language known as bytecode.

To create a running Java program, a software developer does the following:

  1. Writes Java code in a text file. The name of the text file must end with ".java"
  2. Runs the Java compiler which compiles the Java code to bytecode. The bytecode is stored in a file with the same name as the Java code except the bytecode filename ends with ".class" instead of ".java"
  3. Runs the Java virtual machine which executes the bytecode on a computer.

Many software development environments, including Android Studio, combine steps 2 and 3 into a single step of clicking a run icon.

A software developer must write all Java files to match this template:

package declaration;

import statements;

class declaration {
    attributes;

    methods;
}

Example

package edu.byui.cit.appname;

import androidx.appcompat.app.AppCompatActivity;
import java.util.List;

public class MainActivity extends AppCompatActivity {
}