Lab 1
[valid 2025-2026]
Introduction to Java Programming
1. Compulsory (1p)
Write a Java application that implements the following operations:
2. Homework (2p)
- A grayscale image can be represented using a 2D matrix, each cell containing a value between 0=black and 255=white.
Consider that width=height=n.
- Create the image of a dark rectangle, on a white background.
- Create the image of a white circle, on a dark background.
- Implement a method that builds a string representation of the matrix, at your own choice. Display on the screen the generated matrix.
Use Unicode characters to create a "pretty" representation of the matrix.
- For larger values of n, display the running time of the application in nanoseconds or milliseconds (do not display the matrix!).
For what value of n you get an
OutOfMemoryError?
Adjust the JVM Heap Space using the VM options, such as -Xms4G -Xmx4G.
- Launch the application from the command line, for example:
java Matrix2D 100 circle.
3. Advanced (2p)
- Write an algorithm that, given a matrix containing a geometric shape, determines the bounding box of the shape.
- Assume the shape may be irregular, and determine its boundary.
Notes
- The lab assignments are intentionally not very precise. Students are encouraged to customize their implementations as they wish, and creativity is appreciated.
- Create a new project for each laboratory. In a project, create at least one package. Create classes as necessary, do not use the same class for unrelated tasks.
Each class must contain the name(s) of the author(s) as a comment.
- Please consult the API documentation to learn more information about the classes and methods used!
- Write code faster using keyboard shortcuts.
Resources
Objectives
- Get used with an integrated development environment (IDE): Netbeans.
- Get used with the Java language syntax.
- Create and run a simple application.
- Understand the following concepts: compiler, interpreter, byte-code, Java Virtual Machine (JVM), portability.
- Use the Unicode alphabet and Java special characters.
- Work with primitive data types and strings (String,
StringBuilder).
- Work with one- and multi-dimensional arrays.
- Parse command line arguments.
- Perform conversions between strings and numbers.
- Split a string into tokens.
- Generate random numbers.
- Create multiple methods in the main class of the application.