JAVA LAB / ITD102L
Week 12–15 · Interactive lecture companion

From Java basics
to real-world apps.

Explore how Java handles text, validates input, persists data, serializes objects, and builds desktop interfaces. Learn by changing values, running mini-simulations, and connecting each concept to software used in the IT industry.

Learning approach: try first, observe the result, then read the explanation. Examples are teaching simulations; browser demos do not execute Java code.
String input = "Build";
StringBuilder app = new StringBuilder(input);
app.append(" something");
System.out.println(app);
03Learning modules
10+Interactive experiments
06Swing components
0%Knowledge check score
Module 01 · Text processing

Strings, Characters & Regular Expressions

Applications receive text constantly: names, search queries, form fields, log messages, and identifiers. Correct text handling improves reliability, usability, and security.

char / Character

Inspect one character

char stores one UTF-16 code unit. Character provides utility methods such as isDigit, isLetter, and case conversion.

Industry: checking input characters, parsing codes, and text transformations.

String

Immutable text

A String cannot be changed after creation. Methods such as concat return a result; they do not mutate the original object.

Industry: safer sharing of text values, configuration, and identifiers.

StringBuilder

Build text efficiently

StringBuilder is mutable. Its append, insert, delete, and reverse methods update a character sequence.

Industry: building reports, CSV output, and repeated string changes.

Experiment A — String vs StringBuilder

Change the starting text and append a phrase. Watch which value changes.

Original / result
Original: Java
StringBuilder: Java
Concept: s.concat("!") returns a new String. If its return value is not assigned, s remains unchanged. sb.append("!") changes the builder.
String s = "Java"; s.concat("!"); // s is still "Java" s = s.concat("!"); // now s is "Java!" StringBuilder sb = new StringBuilder("Java"); sb.append("!"); // sb now contains "Java!"

Experiment B — Character inspector

Enter one character to explore common Character checks.

Letter: true · Digit: false · Uppercase: true
Character.isLetter(c) Character.isDigit(c) Character.isUpperCase(c) Character.toLowerCase(c)

Java char represents a UTF-16 code unit, not every possible Unicode symbol as one unit. Some symbols require a surrogate pair.

Experiment C — Split into tokens

Tokenization divides a string into smaller pieces. Common use: parsing CSV-like input, tags, or delimited records. Production CSV needs a CSV parser when quoting/escaping rules apply.

applebananaorange
String[] tokens = text.split(","); for (String token : tokens) { System.out.println(token); }

Experiment D — Regex pattern tester

Regex describes a pattern. Try the supplied pattern and input; the demo uses browser regex syntax to illustrate the idea.

Ready to test.
Important: client-side validation improves feedback but is not a security boundary. Validate on the server too. A regex email check only checks a format, not whether an address exists.

Method quick reference

length()
number of UTF-16 code units

charAt(i)
unit at index i

substring(a,b)
from a up to, not including, b

indexOf(x)
first matching index or -1

equals(x)
content equality

compareTo(x)
lexicographic comparison

For Java strings, use equals() to compare content; == checks whether references point to the same object.
Module 02 · Persistence

Files, Streams & Object Serialization

Programs need durable storage so data survives after the application closes. RAM is volatile; files and other storage are designed for persistence.

01 · In-memoryData lives in variables/RAM while the program runs. Closing the process usually loses it.
02 · File I/ORead bytes or characters from a source, or write data to a destination. Choose text or binary APIs appropriately.
03 · Persistent workflowSave records, logs, exports, and settings. Handle errors, permissions, encoding, and resource cleanup.

Experiment E — Stream simulator

Simulate writing and reading a text file. The browser keeps this demo in page memory only; it does not write to your computer.

File state
No file written yet.
Activity log
Waiting for an action…
try (BufferedWriter writer = Files.newBufferedWriter(path)) { writer.write(content); }

Use try-with-resources in modern Java to close streams reliably, including when an exception occurs.

Java I/O toolbox

Choose a task to see an appropriate family of APIs.

Text files

FileReader, FileWriter, BufferedReader, and BufferedWriter work with character data. Set an explicit charset for predictable text encoding.

Package guide: java.io contains classic stream and reader/writer APIs. java.nio.file provides Path, Files, and directory/file operations.

Experiment F — File metadata

Explore the kind of metadata a file utility might show. Values below are illustrative, not actual files on your device.

No metadata loaded.
Path path = Paths.get("data.txt"); long size = Files.size(path); FileTime created = (FileTime) Files.getAttribute(path, "creationTime");

Real metadata calls can throw I/O or permission exceptions. Check the exact API and platform behavior.

Experiment G — Serialization lifecycle

Serialization converts an object graph into a byte representation. In Java, Serializable marks eligible classes; object streams write/read the representation.

Object exists in memory only.
try (ObjectOutputStream out = new ObjectOutputStream( new FileOutputStream("object.ser"))) { out.writeObject(student); }
Security note: do not deserialize untrusted data casually. Java native serialization can create security risks; use safer, explicitly designed data formats for many modern systems.

Experiment H — JFileChooser

JFileChooser lets a desktop Java app ask the user to select a file or directory. Simulate the decision flow.

Open file

Select a sample file:

No file selected.

Waiting for selection.
JFileChooser chooser = new JFileChooser(); int result = chooser.showOpenDialog(null); if (result == JFileChooser.APPROVE_OPTION) { File selected = chooser.getSelectedFile(); }

Real-world design challenge

A desktop inventory tool must save item records, load them on startup, and let a user choose an export destination.

Module 03 · Desktop interfaces

Swing GUI Components

Graphical user interface components turn program logic into controls people can understand and operate. Good UI design makes tasks discoverable, consistent, and efficient.

JSlider

Continuous values

Select a numeric value within a range. Useful for volume, brightness, zoom, or threshold controls.

JPopupMenu

Context actions

Offer relevant actions near the selected item, often on right-click. Keep essential actions discoverable elsewhere too.

JDesktopPane + JInternalFrame

Window workspace

Support multiple internal windows inside a main window—an MDI-style workspace for specialized desktop tools.

JTabbedPane

Organize sections

Separate related content, such as Home, Settings, and Help, without opening a new top-level window for every section.

BoxLayout

Linear alignment

Arrange components vertically with Y_AXIS or horizontally with X_AXIS.

Usability

Design for the user

Match the control to the task, provide feedback, support keyboard use, and avoid hiding critical actions in context menus.

Experiment I — JSlider simulator

Drag the slider to change a simulated system volume. This mimics the interaction; Java Swing code is shown below.

50%
Balanced output
JSlider slider = new JSlider(0, 100, 50); slider.addChangeListener(e -> { int value = slider.getValue(); // update volume display });

Experiment J — JPopupMenu simulator

Right-click the item below (or use the button for touch devices) to open contextual actions.

Project Explorer
📄 project.java

Right-click this workspace to open a simulated context menu.

No action selected.
JPopupMenu popup = new JPopupMenu(); popup.add(new JMenuItem("Refresh")); popup.add(new JMenuItem("Settings")); // component.setComponentPopupMenu(popup);

Experiment K — JTabbedPane

Click each tab. Tabs organize related views in one container.

Overview

Project status, recent activity, and key actions appear here.

JTabbedPane tabs = new JTabbedPane(); tabs.addTab("Home", homePanel); tabs.addTab("Settings", settingsPanel); tabs.addTab("Help", helpPanel);

Experiment L — MDI workspace

Open, minimize, maximize, or close simulated internal windows. This illustrates the role of JDesktopPane and JInternalFrame.

Workspace ready. Create a window.
JDesktopPane desktop = new JDesktopPane(); JInternalFrame frame = new JInternalFrame( "Inventory", true, true, true, true); desktop.add(frame); frame.setVisible(true);

Constructor flags are: resizable, closable, maximizable, iconifiable—in that order.

Experiment M — BoxLayout

Switch between vertical and horizontal arrangement. The browser demo illustrates the layout concept.

Save
Edit
Export
panel.setLayout(new BoxLayout( panel, BoxLayout.Y_AXIS)); panel.add(new JButton("Save")); panel.add(new JButton("Edit"));

Which component fits?

Choose a user requirement and match it to a Swing component.

Your match will appear here.
Accuracy note: the lecture introduces Swing APIs. In current industry work, Java Swing remains relevant in existing desktop/enterprise tools, while many new user-facing products may choose web, JavaFX, or other UI frameworks depending on requirements. The right choice depends on deployment, maintenance, accessibility, and team constraints.
Retrieval practice

Knowledge check

Answer each question, then check feedback. The goal is to explain why an approach fits—not just memorize a definition.

0 / 8 answered

About browser inspection tools

This page cannot reliably prevent browser Developer Tools, View Source, or inspection of downloaded HTML and JavaScript. Browser-side code is delivered to the visitor's device, so determined users can inspect or modify it. Avoid putting secrets, credentials, or sensitive data in this file. For protected data or graded assessments, use server-side validation and authorization.