CS I · Thu Oct 29 · 13.4 · We Do

Before the bell

You are responsible for all of this before the end of class.

  1. The discussion form in the I Do deck. All three sections. If you are here, this should be done.
  2. Your classwork. This form on the right. Section 1 before the exit ticket pops up; Section 2 past the floor.
  3. Today's Bench Basics activity: Count from 0. It opens later in class and lives on slide 4 of this deck.
  4. The exit ticket. It opens 15 minutes before the bell and lives on the last slide of this deck.
Classwork

The classwork form is not linked yet. Use Station View and write your answers in your lab notebook with the item labels.

Count from 0

This reading shows how a computer numbers the letters in a word. The class will see Java count this way with words in December, so today the counting is done by hand, with no code.

Positions

People count the letters in a word starting at 1, but computers count positions starting at 0, so the first letter of a word is at position 0. The table below numbers the letters of the word BRIDGE.

letter     B   R   I   D   G   E
position   0   1   2   3   4   5

The top row lists the 6 letters of BRIDGE, and the bottom row gives the position of each one. The first letter, B, is at position 0, and the last letter, E, is at position 5, which is one less than the number of letters. For this reason, the letter at position 3 is D, not I. A person who counts from 1 picks I, which is the third letter, but position 3 holds the fourth letter.

Ranges That Stop One Short

A range is a group of positions that sit next to each other. The words "from 1 up to but not including 4" mean positions 1, 2 and 3, so the letters are R, I and D. Position 4 is where the range stops, and the letter there is not part of the range.

range                                  positions     letters
from 0 up to but not including 3        0, 1, 2       B R I
from 1 up to but not including 4        1, 2, 3       R I D
from 2 up to but not including 6        2, 3, 4, 5    I D G E
from 3 up to but not including 3        none          (nothing)

Every row in the table follows the same pattern, in which a range from a up to but not including b holds exactly b − a letters. The range from 2 up to but not including 6 holds 6 − 2 letters, which is 4 letters. A range that starts and stops at the same position holds no letters at all, because 3 − 3 is 0.

Two Mistakes to Check

The bench catches two common mistakes, and the first is starting the count at 1, which gives the letter one place too early. The second is including the position where the range stops, which adds one letter too many. Each answer can be checked in two steps. First, write the positions under the letters, starting at 0. Then, list the positions from the start of the range up to the stop, and leave the stop position out.

Sources: Oracle, Class String, Java SE 21 API documentation (2023).

Where Java Runs

This section explains where Java programs run, what the back end of an application does, and what part Java plays in packaging AI.

Java source code is written in plain text files, and a compiler turns those files into bytecode. Bytecode is the machine language of the Java Virtual Machine, which runs the program. The Java Virtual Machine is available on many operating systems, so the same bytecode can run on Windows, on Linux and on a Mac. That is why Java is called portable.

Applications and Their Back Ends

An application is a program that people use to get a task done, such as a banking app, a game or a map. Many applications have two parts. The part on a phone or laptop screen is the front end, which shows information and collects what the user types or taps. The back end is the part of an application that runs on servers, where it stores the data, does the work and sends results back to the front end. Only its results reach the user's screen, so the user never sees the back end. For example, a bank's back end stores account information and lets only the right people view an account, while the front end shows the balance. The screen a customer taps on is the front end, not the back end, because the back end runs on servers the customer never sees.

A language model by itself is not an application. It becomes part of an application only when a program carries a person's question in and the answer back out.

Places Java Runs

Android apps are written in Java or Kotlin, and since 2019 Google has recommended that new Android apps start with Kotlin. Oracle, the company that leads Java's development, calls Java the language of choice for business applications.

Big-data tools also run Java. Apache Kafka moves streams of data between systems. Apache Hadoop processes large sets of data on groups of up to thousands of computers. Elasticsearch searches and analyzes stored data. The code of all three projects is written mostly in Java, and Kafka's second language is Scala. Kafka's project page reports that 7 of the 10 largest banks use it. So Java runs in the back ends of most of the largest banks.

Minecraft: Java Edition, which its store page calls the original version of the game, runs on Windows, macOS and Linux. A Java Edition server cannot start until a Java runtime has been installed.

Libraries

A library is code that someone else already wrote and tested, which a program can use instead of writing that part again. Java's standard library comes with Java. Oracle describes it as a large collection of ready-made parts, grouped into packages of related code. Many other Java libraries are free to use, and Spring AI and LangChain4j are two of them. A Java library is code that a program uses for one part of its job, so it is different from a building full of books and smaller than a whole application.

Java in an AI Tool

The back end of an AI tool is the program that receives the user's question, adds the system prompt, sends the request to the model and returns the answer to the front end. A request to a Mistral model names the model and carries a list of messages, each with a role such as system or user. Figure 1 shows this path from left to right, with Java in the back end.

That back end can be written in Java, and a library can do the work of calling the model. LangChain4j's stated goal is to make it simpler to connect language models to Java applications. It works with more than 20 model providers. Spring AI is written in Java, and it can call the models from Mistral AI and from other companies.

The model itself is usually built with a different language. GitHub reported in 2024 that Python is used heavily for machine learning and is the top language for data science and research. PyTorch, a library for building deep-learning models, is written mostly in Python, with large parts in C++. Python does not do all of the work, and the back end around the model can be written in Java. On Friday, the class looks at the course where students learn to read and write Java, which is AP Computer Science A.

Summary

An application is a program people use to get a task done, and its back end runs on servers that the user never sees. Java runs in Android apps, in bank back ends, in big-data tools such as Kafka, Hadoop and Elasticsearch, and in Minecraft: Java Edition. In an AI tool, a Java back end can use a library such as Spring AI or LangChain4j to call a model, which is usually built with Python.

Sources: Oracle, About the Java Technology (n.d.); MDN, Introduction to the server side, What is JavaScript? and UI (n.d.); Android Developers, Application fundamentals (n.d.); Android Developers, Android's Kotlin-first approach (n.d.); Oracle, Java (n.d.); Apache, Apache Kafka (n.d.); Apache, Apache Hadoop (n.d.); Elastic, elasticsearch repository (n.d.); Microsoft Store, Minecraft: Java Edition (n.d.); Mojang, Minecraft Server Download (n.d.); Spring, Spring AI Reference (2026); LangChain4j, Introduction (n.d.); Mistral AI, Chat Completion API (n.d.); GitHub, Octoverse 2024 (2024); PyTorch, PyTorch documentation (n.d.).

Classwork · Section 1 — Reading 2

The classwork form is not linked yet. Use Station View and write your answers in your lab notebook with the item labels.

MC 1. Which of these is an application?

  • a map app that a person uses to find a route across town
  • a language model by itself, with no program around it
  • the room of servers where a company keeps its computers
  • one line of code copied out of a larger program

MC 2. A person uses a music app on a phone. Which part of the app is the back end?

  • the song list and buttons on the phone's screen
  • the code on the company's servers that stores the playlists and sends songs to the phone
  • the playlist of songs that the person made last week
  • the phone's speaker that plays each song out loud

MC 3. In Java, what is a library?

  • a building where people go to borrow books and read
  • a complete application that people use to get a task done
  • code that someone else already wrote and tested, which a program can use
  • a folder where a programmer saves her own finished programs

MC 4. In an AI tool, where can Java run, and where is Python more common?

  • Java trains the model, and Python sends each request to the model.
  • Java runs in the back end that calls the model, and Python is used to build the model.
  • Java runs on the phone's screen, and Python runs on the server.
  • Java and Python both run only on the screen the user taps.

MC 5. In the word CANDLE, what is the position of the first letter, C?

  • 0
  • 1
  • 5
  • 6

MC 6. In the word GARDEN, which letter is at position 2?

  • A
  • R
  • D
  • E

MC 7. The word KITCHEN has 7 letters. What is the position of its last letter, N?

  • 7
  • 6
  • 5
  • 0

MC 8. In the word MARKET, which letters are in the range from 1 up to but not including 4?

  • M A R K
  • A R K E
  • A R K
  • M A R

MC 9. How many letters does the range from 2 up to but not including 7 hold?

  • 4
  • 5
  • 6
  • 7

MC 10. In the word FOREST, which range gives exactly the letters R, E and S?

  • from 2 up to but not including 5
  • from 2 up to but not including 4
  • from 3 up to but not including 6
  • from 3 up to but not including 5

CR 1. Number the positions of the word WEATHER, starting at 0. Then name the letters in the range from 0 up to but not including 3, and the letters in the range from 3 up to but not including 7.

Write your answer in your lab notebook, labeled CR 1.

CR 2. In two sentences, explain what a back end does in an AI tool. Use one fact from the passage.

Write your answer in your lab notebook, labeled CR 2.

Figure 1. In an AI tool, the front end on the screen sends the question to the back end on a server. The back end adds the system prompt and uses a library to call the model. Java also runs in Android apps, bank back ends, big-data tools and Minecraft: Java Edition.
Classwork · Section 2 — Past the floor

The classwork form is not linked yet. Use Station View and write your answers in your lab notebook with the item labels.

CR 3. The word MONSTER has 7 letters. Write the range "from a up to but not including b" that gives exactly the letters S, T and E. Then say how many letters the range holds, and show how you know.

Write your answer in your lab notebook, labeled CR 3.

CR 4. Pick an app you use. Name its front end, one job its back end likely does, and one kind of library its programmers might use. Write two to four sentences.

Write your answer in your lab notebook, labeled CR 4.

Bench Basics

Count from 0

Open the bench, do its six jobs, then paste your credit code into the credit-code form. You can turn in up to three codes per bench; your best score is your grade.

Bench Basics opens during your class period.

Classwork

The classwork form is not linked yet. Use Station View and write your answers in your lab notebook with the item labels.

Exit Ticket

This opens during your class period.