1. Preparation of workstation
3. Java language syntax

2. exercise: Preparation of Java development project

Review Introduction to Java


Review notes about practical exercise


Practical tasks

Import project

  1. Download file
  2. Open Eclipse:
    1. select menu: File— Import...
    2. General— Existing projects into workspace, Next
    3. Check Select archive file
    4. Select downloaded file
    5. Finish

Rename project

  1. Generate your own unique project name with following command:

    head -c 32 /dev/urandom|sha256sum|xxd -r -p|base64|cut -b -4|tr "+/=" "abc"
  2. Right click on JTM and select Refactor—Rename
  3. Rename project in form: YwZm (where YwZm is actual output from previously entered command)
  4. Open your project folder e.g. /home/student/workspace/YwZm.
  5. Open file pom.xml and change line <artifactId>JTM</artifactId> to: <artifactId>YwZm</artifactId>
Generated code e.g. YwZm will be used as unique identifier for your project and knowledge checks!

Rebuild project

  1. Open terminal and create M2_REPO variable for Eclipse:

    cd ~
    mvn -Declipse.workspace=/home/student/workspace/ eclipse:configure-workspace
  2. Go to your project and enerate project meta-info for Eclipse, e.g.:

    cd workspace/YwZm
    mvn eclipse:eclipse
  3. Refresh project explorer in Eclipse


help Check that project name in Eclipse is e.g. YwZm
help Check that your project is located in folder e.g. /student/workspace/YwZm/
help Check that file /home/student/workspace/YwZm/.project has line: <name>YwZm</name>
help Select Window — Preferences, search for Java — Build Path — Class Variables and check M2_REPO has value /home/student/.m2/repository

Implement TODO

  1. Use code generation to create class Hello ( file) with public static void main(String[] args) method in it.
    1. In the Project Explorer view, select package:
    2. Right click on the package and select: New — Class
    3. For field Name enter: Hello
    4. In group Which method stubs would you like to create? select public static void main(String[] args)
    5. Press Finish
  2. Add code into main method, which prints "Hello world!" into system console, for example:

    System.out.println("Hello world!");
  3. Run as JUnit test to test proper implementation of this class.
    1. Right click on
    2. Select Run As — JUnit Test
    3. Check that JUnit view shows green status bar
    4. To to doube-check system configuration, run also Junit in jtm.activity01 package.

Learn to compile and execute classes

In Eclipse

  1. Select class and activate menu Run — Run as... — Java application

In command line

  1. Open terminal and enter commands:

    cd ~/workspace/YwZm/
    java -version
    javac -cp target/classes src/main/java/jtm/activity02/
    java -cp target/classes jtm.activity02.Hello

Run Unit test

  1. Select menu Run— Run as— Java Application
  2. Select menu Run— Run as— JUnit Test
  3. Check that unit test passes

Optional: Export project

You can move your project between different computers using Import/Export safely.

1. Preparation of workstation
3. Java language syntax
Izveidojis Valdis Vītoliņš 2017-01-03 10:07
Pēdējais mainījis Valdis Vītoliņš 2017-09-01 19:41
Xwiki Powered
Creative Commons Attribution 3.0 Unported License