Java.lang package in AP Computer Science A
In AP Computer Science A, the java.lang package is the built-in group of core Java classes, including String and Math, that every program can use by default. You never need to write an import statement for them (EK 1.11.A.1, EK 1.15.A.2).
What is the java.lang package?
A package in Java is a named group of related classes. The java.lang package is the most basic one. It holds the classes Java treats as essential, so they are available by default. You can write Math.sqrt(16) or String name = "Ada"; without any import line at the top of your file.
The AP CED names two java.lang classes directly. The Math class (EK 1.11.A.1) contains only class (static) methods like abs, pow, and sqrt. The String class (EK 1.15.A.2) represents a sequence of characters. Other classes you've already used, like Integer, also live in java.lang. Think of java.lang as the toolbox that comes pre-opened on your desk. Every other toolbox has to be pulled off the shelf with an import.
Why the java.lang package matters in AP® Computer Science A
java.lang shows up in Unit 1: Using Objects and Methods, across two topics. In Topic 1.11 (Using the Math Class), it supports 1.11.A, which asks you to write expressions that call built-in math libraries and figure out the value they produce. In Topic 1.15 (String Methods), it supports 1.15.A (creating and combining strings) and 1.15.B (calling String methods and predicting the results).
The package itself is a small fact. It explains why the Math and String code you write all year compiles with zero setup. It also explains why the AP Java Quick Reference can list Math and String methods with no import lines attached.
Keep studying AP® Computer Science A Unit 1
How the java.lang package connects across the course
Math class (Unit 1)
Math is the java.lang class you'll use most for calculations. Because it lives in java.lang and has only static methods, you call it by class name, as in Math.pow(2, 3). You never import it and you never create a Math object.
String class and immutability (Unit 1)
String is also in java.lang, which is why string literals work right away in any program. The key String idea tested in 1.15.A is immutability. Methods like substring hand you a new String and leave the original unchanged.
String methods, indexes, and indexOf (Unit 1)
Since String is built in, its methods (length, substring, indexOf) are on the Quick Reference and ready to use. Indexes run from 0 to length() - 1. Going outside that range throws a StringIndexOutOfBoundsException, a classic trap in 1.15.B questions.
System class and Object class (Unit 1)
Two other java.lang classes are hiding in plain sight. System.out.println comes from the System class, and every class you write automatically inherits from Object. That's why equals works on any object.
Is the java.lang package on the AP® Computer Science A exam?
java.lang usually shows up as a quick concept MCQ or as background to a code-tracing question. Typical stems look like this:
- "Which of the following classes is available by default from the java.lang package without requiring an explicit import statement?" The answer is a class like
MathorString. - "A programmer calls
Math.sqrt(16)without any import statements. Which concept explains why this code works?" The answer is that Math is in java.lang, which is available by default. - Code-tracing questions, like a
distancemethod built fromMath.sqrt(Math.pow(x2 - x1, 2) + Math.pow(y2 - y1, 2)). Here you have to know thatpowandsqrtreturndoublevalues.
No released FRQ has used the term "java.lang" verbatim. Still, every FRQ that uses String methods or Math calls relies on it, because you write that code without imports.
The java.lang package vs Math class
java.lang is a package, a container that groups classes. Math is one class inside that container, along with String and others. If a question asks why Math.sqrt works without an import, the answer is about the package (java.lang is available by default). If a question asks what Math.sqrt(16) returns, the answer is about the class method, which returns 4.0.
Key things to remember about the java.lang package
The java.lang package is a group of core Java classes that every program can use without an import statement.
The Math class and the String class are both part of java.lang, according to the AP CED (EK 1.11.A.1 and EK 1.15.A.2).
The Math class has only static methods, so you call them on the class name, as in Math.abs(x) or Math.sqrt(x).
Math.pow and Math.sqrt return double values, even when you pass them int arguments.
Because String is in java.lang, you can create strings with literals and call methods like length, substring, and indexOf right away.
If an MCQ asks why Math or String code works with no import, the answer is that java.lang classes are available by default.
Frequently asked questions about the java.lang package
What is the java.lang package in AP Computer Science A?
It's the built-in package of core Java classes, including Math and String, that is available by default in every program. The CED covers it in Topics 1.11 and 1.15.
Do I need to import java.lang to use Math or String?
No. Classes in java.lang are available by default, so Math.sqrt(16) and String s = "hi"; compile with no import statement at all.
What's the difference between java.lang and the Math class?
java.lang is a package, which is a group of classes. Math is a single class inside it. The package explains why you don't need an import, and the class provides methods like abs, pow, and sqrt.
Is java.lang on the AP CSA exam?
Yes, in Unit 1. It appears in MCQs asking which classes are available by default, and it sits behind every Math and String question tied to learning objectives 1.11.A, 1.15.A, and 1.15.B.
What classes are in the java.lang package?
For AP purposes, the big two are Math and String. Integer, System (as in System.out.println), and Object are also in java.lang.
Keep studying AP Computer Science A
Connect this key term to the AP exam workflow: review the course, practice questions, and check related study tools.
AP Computer Science A hub
Review units, study guides, and course resources.
AP-style practice
Check this vocabulary in multiple-choice context.
FRQ practice
Apply key concepts in written AP responses.
Score calculator
Estimate the exam score you are working toward.
Cheatsheets
Review the highest-yield facts before practice.
Practice exam
Put the full course together before test day.