Software

Although the IJP assignments do not require any special features of a particular version of Java, the necessary library files have been built for Java 10 and are not compatible with other versions. So you must use this specific version of Java.

Java 10 is available on the DICE system, but may not be the default. You will need to set the appropriate version:

module add java/10.0.2

If this says "module not found", then you might (first) need to:

source /etc/profile.d/modules.sh

You can check the current version with:

java -version

Full details are available on the computing help page.

You also need to make sure that Eclipse is configured to use the correct version:

  • Right click on JRE System Library in the Package Explorer window on the left and select properties.
  • Click on the Installed JREs button.
  • Click on the Add... button.
  • Select Standard VM
  • Click on the Directory... button by JRE home.
  • Navigate to the directory /usr/lib/jvm/
  • Select the (latest) java1.10.XXX-sun-XXX file and click OK
  • Click finish in the Add JRE window.
  • Click OK.
  • Now under JRE System Library you can select the JVM that you have just added.

The Java JDK is available from here. Download and install the version recommended for your OS.

You must use Eclipse Photon for Java 10. You do not need the "Enterprise" (EE) edition.

Eclipse Photon is the default on the DICE systems.

Download and install Eclipse Photon from here. Be careful if you have a previous version of Eclipse already installed. It's possible that you may want to remove this first - or at least check carefully that you are not running the old version by mistake.

SceneBuilder is the JavaFx application for creating graphical interfaces. Version 10 is required to run with Java version 10.

SceneBuilder 10 is available on the DICE systems. - Open the Terminal from Applications>System Tools - Enter the command: scenebuilder

Download and install version 10 of SceneBuilder for your platform from GluonHQ.

Bluej is installed on all of the DICE machines. If you are using the standard window manager, you can find it under the "Application/Other" menu. Or you can launch it from the command line as "bluej.sh".

If you want to install BlueJ on your own machine, it is available from here.

Assignment 1

The assignment1 zip file includes a library which you must add to your project:

  • Select the project in the package explorer.
  • Right click and select "Properties".
  • Choose "Java Build Path" from the right hand menu.
  • Choose "Libraries" from the tabs in the centre.
  • Choose "Add External jar" from the menu on the right.
  • Select the assignment1 jar file.

The assignment1 zip file includes a demonstration main program to allow you to check that everything is working:

  • Drag the MyApplication.java file onto the src folder in the Eclipse "package explorer".
  • If a dialog appears, select "Copy file on import to Eclipse".

The assignment1 zip file includes a demonstration properties file which allows you to change the implementations used for the various classes:

  • Drag the "my.properties" file onto the src folder in the Eclipse "package explorer".
  • If a dialog appears, select "Copy file on import to Eclipse".

The application for assignment1 includes a lot of sources files. These are grouped into "packages". If you add (for example) a Controller, you must put it into the "ijp.controller" package.

  • Select the project in the package explorer.
  • Right click and select "New Package".
  • Name the package "ijp.controller" (or whatever you require).
  • Drag the source file onto the package icon which appears in the Package Explorer.
  • If a dialog appears, select "Copy file on import to Eclipse".

To enable JUnit testing, you may need to add the JUNit library to Eclipse:

  • Right-click on the project folder and select "Properties".
  • Select "Java Build Path".
  • Select the "Libraries" tab.
  • Click "Add Library".
  • Select "JUnit" and click "Next".

This is a warning you that you are using JavaFx which may not be available on all Java installations (so is a potential portability problem). Two possible solutions are:

-Right click on your project in the package explorer -Select Build Path > Configure Build Path... -Go to the Libraries tab -Expand the JRE System Library by clicking the arrow to its left -Select access rules -Select Edit -Select Add -Change Resolution to Accessible -Enter javafx/** into the Rule Pattern box -Press OK twice to close the Access Rules Windows -Apply and Close the Properties Window

Assignment 2

There is a limit on the maximum file size for assignment submissions which you can easily exceed if you submit huge image files. Most images can be reduced considerably for screen use. I use:

jpegoptim -m80 --all-progressive --strip-all

convert -resize WIDTHxHEIGHT

The getClass().getResource() method's documentation explains which rules are used to look up the requested resources on the disk. In short, if the class from which this method is invoked is in the default package, and the file is there too, a String containing just the name of the file will be enough.

If the image is in a different package, the path is relative to the src (bin) folder and should begin with a "/". For example, we can have the following structure of packages:

|--mypackage
|-----mypackage.controller
|-----mypackage.view

|-------- DisplayImages.java

|-----mypackage.model
|-----mypackage.resources
|---------Image1.jpg
|---------Image2.jpg

If we want to load the files from the package mypackage.resources from the class DisplayImages, we can use:

URL url1 = this.getClass().getResource("/mypackage/resources/Image1.jpg");
URL url2 = this.getClass().getResource("/mypackage/resources/Image1.jpg");
Image image1 = new Image(url1.toString());
Image image2 = new Image(url2.toString());

(In the case of an Image, we can omit the construction of the URL object and pass a String directly to the Image constructor.)

The default behaviour is the same in both cases (more details on where the Image's constructor looks for files while constructing an URL can be found here).

So, in short, if the image is in the same folder as your class object, which invokes the loading method (remember you're actually running the classes from the bin directory, not from src), then the filename alone is sufficient. Otherwise, the path is relative to the root of your packages (bin/src) and needs a leading "/".

(Natalia)

Other Tools

See the Computing support page on remote working.

HTML Javadoc can be created easily from the "Project/Generate Javadoc .." menu in Eclipse. Make sure that no errors are reported during the generation.

If your Java installation does not have English as the default language, then the Javadoc headings etc. will not be in English. Please use DICE to generate this if necessary so that your submission is in English.

  1. Right click on your project folder in 'Package Explorer' and select properties.
  2. Select Java Build Path.
  3. Select Libraries.
  4. Select Add Library.
  5. Select JUnit then click on next.
  6. Under JUnit version select JUnit 5.
  7. Click on finish.

Assignment worksheets must be submitted in PDF format. Most applications and operating systems now have some native way of creating PDF. There are also a lot of PDF conversion services, many of which have a free option (Google "online pdf service").

Many applications provide an Export option (eg. OpenOffice on DICE), or a special driver in the print menu (e.g. the browsers in DICE) which can be used to generate PDF files.

Many applications provide an Export option. Otherwise, the Print menu has a "Save as PDF" option which will work with all applications.

Recent versions of Windows can create PDF directly from Office applications using "Save As".

To submit an assignment, you must create a zip archive which unpacks to a single directory with the same name as the assignment - e.g. IJPAssignmentN (where N is the assignment number). Create a directory with this name and place all of the files/directories that you intend to submit into this directory. You can then create a zip archive as follows:

zip -r IJPAssignmentN IJPAssignmentN

Right click on the directory and select Compress ... from the menu.

In Explorer, highlight the directory, right mouse click, and choose Send to compressed zip file from the menu.

If you want to distribute your application so that someone else can run it (e.g for assessment), you should package it into a jar file. Your application should run just by double-clicking on this jar file.

  • Select the project
  • Choose Export/RunnableJarFile
  • Make sure the "launch configuration" is set to your current main program
  • Select the output file
  • Select "Package required libraries into generated jar file"

Further Resources

Go to piazza.com and search for IJP. You can sign up on the page and ask questions on any topic on the course. If you ask during office hours you are likely to receive an answer within a few hours.

-If you need an answer for a problem please set your post type to "Question", otherwise set it to "Post". -Different sections of the piazza can be accessed from the menu near the top left of your window. -If you are introducing yourself please use the "introductions" section. -To chat with other members of the class please use the "social" section. -The "announcements" section is only for instructors to give out class-wide guidance. -Please only use the remaining sections for problems that require answers or focused discussion on the relevant topic.

  • Sun/Oracle's Java API documentation is a crucial resource to have at hand when programming. You should bookmark the page and will need to learn how to read and navigate it. Refer to the API documentation whenever you need to look up something about the Java standard library classes.
  • Sun/Oracle's Java tutorials are another excellent resource to refer to, to complement the BlueJ book.
  • Java PubHouse is an interesting Podcast on various Java topics. Good for listening to in the gym, or while you are driving!

  • The BlueJ book has an appendix on the Style Guide which has a good, concise description of the conventions for writing Java code.
  • The Art of Readable Code is an O'Reilly book on "Simple and Practical Techniques for Writing Better Code".