Motivation
On today's exercise you will get familiar with the organization of the subject and obtain your assignment - a game that will represent a component of web application GameStudio. At the same time, you will practice the Java basics on simple programming exercises, and work with the development environment IntelliJ IDEA, that you already used on the subject Object-oriented programming.
Objectives
- Get familiar with the organization of the subject Component-oriented programming.
- Get familiar with the integrated development environment IntelliJ Idea .
- Practice effective work with the development environment.
- Refresh the Java basics and debugging by solving simple programming tasks.
Instructions
Step 1
Get familiar with the organisation of the subject Component-based programming and conditions for granting the credit.
Step 2
Task 2.1
Install or update the development environment IntelliJ IDEA Ultimate edition.
You can apply for the Ultimate edition licence for free for study purposes through the online form on the JetBrains webpage, where you need to register with your university email.
Task 2.2
Practice the basics of working in the development environment IntelliJ IDEA.
Create new project in the development environment IntelliJ Idea by clicking on the Create New Project button (Fig. 1).
Select Java as the project type, current version of the JDK, and click on the Next button (Fig. 2).
It is possible to create the project from a template or as an empty project. For this time, don't select any template and click Next (Fig. 3).
Enter the name of the project (Project name), for example Exercise
, and location of the project (Project location). Click on Finish (Fig. 4). The basic files of the project will be created in the directory of project location.
Step 3
Task 3.1
Create new Java class in the project.
In the left panel, expand the project structure, right-click the src
directory, and from the context menu select New -> Java class (Fig. 5).
Enter the name of the file (e.g. HelloWorld
), select file type Class, and click on OK (Fig. 6).
Comment
The dialog window for creating new file or package can be opened also from the main menu at the top of the window - File -> New -> Java class.
Step 4
Notice the project environment layout.
Task 4.1
Create the method main()
in the HelloWorld class by writing down the shortcut psvm
and pressing the Tab
key on your keyboard.
Step 5
Remember useful keyboard shortcuts which will make your work in the development environment easier.
Task 5.1
Write a code which will print "Hello world! into the console"
When writing source code, IntelliJ Idea automatically displays context suggestions (Fig. 8), similarly to other development environments.
Comment
The keyboard shortcut for invoking the context suggestions is Ctrl+space.
Task 5.2
Run the created program from the class that contains the main()
method.
Run the program either by using the green arrow on the left margin of the source editor, or by right-click on the name of the class in the project panel and selecting Run 'HelloWorld.main()' from the context menu (Fig. 9).
Task 5.3
Rename the main class by using the refactoring functionality.
Use the keyboard shortcut Shift+F6
or "Refactor" -> "Rename..." in the context menu.
Comment
By refactoring you can automatically rename class names, method names, fields, local variables or parameters names. The refactoring process will change the name everywhere it's used, also in other classes or packages.
Task 5.4
Place the caret to the title of the method println()
and press the keyboard shortcut Ctrl+Q to display the Javadoc documentation.
Step 6
Task 6.1
Add the file PrintTriangle.java into your project and find and correct mistakes in the program according to instructions in the source file.
Step 7
Task 7.1
Add the file NumberToText.java into your project and find and correct mistakes in the program. It should work as a generator of string representation of given numbers.
For testing the NumberToText.java
program, enter the input argument of this program (tested input number) in the run configuration setting of the project. You can create the configuration by selecting Edit configurations in the dropdown menu next to the button for running the project (Fig. 10)
In the dialog window, enter the input argument value into the Program arguments field (Fig. 11), according to the instructions from the source code. You can change the input value also later to test various numbers.
After this step you can run the project simply through the button on the top panel, using the latest run configuration which is automatically selected (Fig. 12).
Task 7.2
If you succeeded to correct all mistakes, modify the program to support higher numbers - over 10-thousand, over 100-thousand.
Additional Tasks
Task A.1
Get familiar with the game assigned to you and its logic (see the list of games), so that you could start designing its architecture and functionality next week.
Additional links
- The list of games for assignments
- Assignments list
- You can apply for school licence for JetBrains products on https://www.jetbrains.com/shop/eform/students. In the registration form use your school email address. Then you can use the full Ultimate version of the IntelliJ Idea environment on your computer. Take care to comply with the terms of licence - the school licence is intended for study purposes only.
- Java Standard Edition tutorial to refresh your knowledge: https://docs.oracle.com/javase/tutorial/