0% found this document useful (0 votes)
16 views9 pages

Java 04

This module focuses on creating library archives and using external libraries in Java. It includes exercises on implementing packages, creating JAR files, and utilizing libraries like JCommander and JCDP for command line processing and colored output. General rules for coding and project structure are provided to ensure proper organization and adherence to standards.

Uploaded by

ahmed4aghlimi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
16 views9 pages

Java 04

This module focuses on creating library archives and using external libraries in Java. It includes exercises on implementing packages, creating JAR files, and utilizing libraries like JCommander and JCDP for command line processing and colored output. General rules for coding and project structure are provided to ensure proper organization and adherence to standards.

Uploaded by

ahmed4aghlimi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Java - Module 04

Packages and JAR files

Summary:
In this module you will learn to create library archives and use external libraries.

Version: 1.00
Contents
I General Rules 2

II Exercise 00: Packages 3

III Exercise 01: First JAR 5

IV Exercise 02: JCommander & JCDP 7

1
Chapter I

General Rules

• Use this page as the only reference. Do not listen to any rumors and speculations
about how to prepare your solution.
• You mus use the latest LTS version of Java. Make sure that compiler and interpreter
of this version are installed on your machine.
• You must use both JVM and GraalVM to run your code.
• You can use IDE to write and debug the source code (we recommend IntelliJ Idea).
• The code is read more often than written. Read carefully the document where code
formatting rules are given. When performing each exercise, make sure you follow
the generally accepted Oracle standards
• Pay attention to the permissions of your files and directories.
• To be assessed, your solution must be in your GIT repository.
• You should not leave in your directory any other file than those explicitly specified
by the exercise instructions. It is recommended that you modify your .gitignore to
avoid accidents.
• When you need to get precise output in your programs, it is forbidden to display a
precalculated output instead of performing the exercise correctly.
• Have a question? Ask your neighbor on the right. Otherwise, try with your neighbor
on the left.
• Your reference manual: mates / Internet / Google. And one more thing. There’s an
answer to any question you may have on Stackoverflow. Learn how to ask questions
correctly.
• Read the examples carefully. They may require things that are not otherwise
specified in the subject.
• Use "System.out" for output
• And may the Force be with you!
• Never leave that till tomorrow which you can do today ;)

2
Chapter II

Exercise 00: Packages

Exercise 00

Packages
Turn-in directory : ex00/
Files to turn in : ImagesToChar-folder (exclude target)
Allowed functions : All

Code can be organized on different levels. Packages are one of the code organization
methods where classes are located in individual folders.

Now your task is to implement functionality that prints a two-colored image in the
console.

An example of a black-and-white BMP image (this format is mandatory for the


solution):

Image size is 16*16 pixels. You can find it in the project page.

Your application shall accept input parameters corresponding to characters that should
be displayed in place of white and black pixels. Another main function startup parameter
is the full path to the image on your disk.

If "." character is used for white color and "0" for black, the image in the console may
look as follows:

3
Java - Module 04 Packages and JAR files

Application logic must be distributed between different packages and have the
following structure:

ImagesToChar - project folder


src - source files
java - files of Java source code
fr.42.printer - a series of main packages
app - a package that contains classes for startup
logic - a package that contains the logic for converting an image
into an array of characters
target - compiled .class files
fr.42.printer ...
README.txt

README.txt file must contain instructions for compiling and starting


your source code from the console (non-IDE). Instruction is written
for the state where the console is opened in the project’s root
folder.

4
Chapter III

Exercise 01: First JAR

Exercise 01

First JAR
Turn-in directory : ex01/
Files to turn in : ImagesToChar-folder (exclude target)
Allowed functions : All

Now you need to create a distribution package of the application—a JAR archive. It
is important that the image be contained in that archive (a command-line parameter for
the full path to the file is not required in this task).

The following project structure shall be adhered to:

ImagesToChar - project folder


src - source files
java - files of Java source code
fr.42.printer ..
resources - a folder with resource files
image.bmp - the displayed image
manifest.txt - a file containing the description of the initial point
for archive startup
target - compiled .class files and archive
fr.42.printer ..
resources
images-to-chars-printer.jar
README.txt

Archive and all compiled files shall be put in target folder during
assembly (without a manual file transfer; you may apply cp command to
the resource folder).

5
Java - Module 04 Packages and JAR files

README.txt file should also contain information on the archive


assembly and startup.

6
Chapter IV

Exercise 02: JCommander & JCDP

Exercise 02

JCommander & JCDP


Turn-in directory : ex02/
Files to turn in : ImagesToChar (exclude lib and target)
Allowed functions : All

Now you should use external libraries:

• JCommander for the command line.

• JCDP or JColor for using colored output

Archives with these libraries shall be downloaded and included in the previous task’s
project.

Now application startup parameters shall be processed with JCommander tools. The
image should be displayed using the "colored" output option of JCDP library.

Required project structure:

ImagesToChar - project folder


lib - external library folder
jcommander-*.**.jar
JCDP-*.*.*.jar or JCOLOR-*.*.*.jar
src - source files
target - compiled .class files and archive
fr.42.printer
com/beust ... - .class files of JCommander library
com/diogonunes ... - .class files of JCDP library
resources
images-to-chars-printer.jar
README.txt

7
Java - Module 04 Packages and JAR files

README.txt file shall also contain the information about including


external libraries in the final assembly.

Example of program operation:


$> java -jar images-to-chars-printer.jar --white=RED --black=GREEN
...
$>

the execution of the program should produce an output like this:

You might also like