Java.lang package

The java.lang package is Java's built-in core package, automatically imported into every program, containing fundamental classes like String, Math, Integer, Double, Object, and System that you use constantly on the AP Computer Science A exam without ever writing an import statement.

Verified for the 2027 AP Computer Science A examLast updated June 2026

What is the java.lang package?

The java.lang package is the foundation library that ships with every Java program. It holds the classes you literally cannot write Java without, including String, Math, Integer, Double, Object, and System. Here's the part that matters most for AP CSA: java.lang is implicitly imported. The compiler pulls it in automatically, so you never write import java.lang.String; at the top of your code. That's why you can call Math.sqrt() or build a String on the first line of a brand-new file with zero setup.

Think of java.lang as Java's standard toolbox that's already open on the workbench. Other packages (like java.util, which holds ArrayList) stay in the cabinet until you ask for them with an import statement. Almost everything on the AP Java Quick Reference (the method list you get on exam day) lives in java.lang, which tells you exactly how central this package is to the course.

Why the java.lang package matters in AP Computer Science A

You won't get an FRQ that says "explain the java.lang package," but its contents are the backbone of nearly every unit. String objects and methods show up in Unit 2 (Using Objects) and stay relevant through every FRQ after that. The Math class (Math.random, Math.abs, Math.pow, Math.sqrt) lives in Unit 2 and powers simulation-style problems. Integer and Double wrapper classes matter for autoboxing and for storing primitives in an ArrayList in Unit 7. And the Object class anchors Unit 9 (Inheritance), since every class you write implicitly extends Object. Knowing what's in java.lang explains a quiet pattern in every AP code sample you'll ever read: ArrayList code always has an import line at the top, but String and Math code never does.

How the java.lang package connects across the course

Object class (Unit 9)

Object is the superclass of every Java class, and it lives in java.lang. That's why methods like equals() and toString() exist on every object you create, even when you never wrote them. The inheritance hierarchy in Unit 9 literally starts inside this package.

Math class (Unit 2)

Math is a java.lang class made entirely of static methods, so you call Math.random() or Math.pow() straight off the class name with no object and no import. It's the cleanest example of why java.lang feels invisible: the tools are just there.

System class (Units 1-10)

Every System.out.println() you've ever written works because System sits in java.lang. You've been using this package since your very first "Hello, world" program, probably without knowing it.

Integer and Double wrapper classes (Units 1 and 7)

Integer and Double wrap primitive int and double values as objects. Since ArrayList can only hold objects, you write ArrayList, never ArrayList. The wrappers come from java.lang, so no import is needed even though ArrayList itself requires one.

Is the java.lang package on the AP Computer Science A exam?

The exam never asks "define java.lang" directly. Instead, it tests whether you can fluently use the package's contents. MCQs hand you code calling String methods (substring, indexOf, equals, length, compareTo), Math methods, or Integer/Double values and ask you to trace the output. FRQ 1 almost always involves Strings, Math operations, or both, and you're expected to use these classes without any import statement. Notice that released FRQ starter code only ever shows imports for things like java.util.ArrayList, never for String or Math. If you write an import for a java.lang class on the exam, it won't cost you points, but it signals you don't know it's automatic. The Java Quick Reference you get during the exam lists the java.lang methods you're responsible for, so know that sheet cold.

The java.lang package vs java.util package

java.lang is imported automatically; java.util is not. String, Math, Integer, and Object come from java.lang and need zero setup. ArrayList comes from java.util, which is why AP code that uses ArrayList always starts with import java.util.ArrayList;. Quick gut-check when reading exam code: if there's an import line, the class is probably from java.util; if a class appears with no import at all, it's almost certainly java.lang.

Key things to remember about the java.lang package

  • The java.lang package is automatically imported into every Java program, so you never write an import statement for its classes.

  • String, Math, Integer, Double, Object, and System all live in java.lang, and they account for most of the AP Java Quick Reference.

  • ArrayList is NOT in java.lang; it's in java.util, which is why ArrayList code always needs an explicit import.

  • Every class you write implicitly extends java.lang.Object, which is where inherited methods like equals() and toString() come from.

  • On FRQs, use String and Math methods freely with no import; the graders expect it and the starter code never imports them.

Frequently asked questions about the java.lang package

What is the java.lang package in AP Computer Science A?

It's Java's core built-in package containing fundamental classes like String, Math, Integer, Double, Object, and System. It's automatically imported into every program, so you use its classes without any import statement.

Do I need to import java.lang in my AP CSA code?

No. The compiler imports java.lang automatically, which is why you can use String and Math.sqrt() on line one of any program. Only classes from other packages, like ArrayList from java.util, need an explicit import.

Is ArrayList part of the java.lang package?

No, and this is the most common mix-up. ArrayList lives in java.util, which is why AP code samples using ArrayList always include import java.util.ArrayList; at the top, while String and Math code never shows an import.

Why is the Object class in java.lang important for the AP exam?

Object is the universal superclass of every Java class, so every object automatically has equals() and toString(). Unit 9 (Inheritance) tests this directly, including knowing that your custom classes implicitly extend Object.

Which java.lang classes do I actually need to know for the AP exam?

String (substring, indexOf, equals, compareTo, length), Math (random, abs, pow, sqrt), the Integer and Double wrapper classes, and Object (equals, toString). All of these appear on the Java Quick Reference you get on exam day.