- Install Ubuntu: Ubuntu can be installed by PowerShell.
- Use the (wsl -- install ) designation, (The Windows Subsystem for Linux),to install a Linux distribution (Such as, Ubuntu).
- When Ubuntu installation is complete. Create a "Username" and a "password".
- In Ubuntu check if java is installed and which version of java is downloaded. Use designation (java -version) to examine if the java program already exist and which version is available on the computer.
- If java do not exist: Use distro/package manager: Use designation (sudo apt-get update) "Then you need to enter password for Ubuntu, to make the download completed".
- Next designation to type in is:
(sudo apt install openjdk-19-jdk-headless)
. You can install more types of java versions by enter designation(sudo update-alternatives --config java)
. - Then chose which version you want, auto or manual will of the versions will pop up as a choice! Please enter the auto version.
- The use designation (clear) to delete the recent text on the screen. Making the Ubuntu environment more present to work in "without distractions".
- Commando
ls
is used for list all the "maps" and "katalogs" in the folder we are in. - Commando
pwd
point out where we stand! In which folder. - Commando
cd
"change directory" - Commando
cd
with a/
: -->cd /
where/
means the root, so with command basically takes you to the c-drive in windows. "As far out as possible". - Then in Ubuntu the standard directory/search-way will change, this will upper (yourUsername@Laptop-G8HVHR4T:/$). This is the standard directory "yourUsername@Laptop-G8HVHR4T:~$".
- Afterward type in ls then you will receive all the folders in your root catalog.
- Give commando
cd
once again to make the search-way get back to standar "Not root search". Standard = "yourUsername@Laptop-G8HVHR4T:~$
". mkdir
= "Make directory
".- Give commando
mkdir java_program_1
then enter. If nothing happens then the mkdir its completed. - Give command
ls
! - The
ls
result should be java_program_1! - Congrats you have now created a map!
- Give commando
cd java_program_1/
to jump into the file! - The
cd java_program_1/
result would be~/java_program_1$
- NOW ARE YOU READY TO RUN A JAVA PROGRAM IN LINUX!
- The latest result
~/java_program_1$
Give commandonanao
! nano is a text editing program. After nano a filename or chose a filename if it exists.~/java_program_1$ nano HelloWorld.java
. - Then you have created a platform to write your java program and run it. It will pop up a window.
- When you write the java code it needs to be exact, to be abel to run.
- For example write
"Hello world"
. - Afterward you have different options on the lower part of the screen. Chose option
^X for exit
. Klick and hold -->Ctrl + X
! - Then klick enter for YES! Then the file name will upper and just click enter to continue.
- Use commando
nano cat HelloWorld.java
then press enter! - What will upper on the screen is the full code printed.
- If you want to change the name of the file you can use command
mv HelloWorld.java HelloWorld_1
. - You have now changed the file name.
- When you stand in file
java_program_1$
writejavac HelloWorld.java
.
- To run the program type in
java HelloWorld
- The result will be out printed on the screen.
To begin with, I would like to introduce the different classes:
Class Description:
-
What the main methods function is:
-
In main a new object of class
Main
calledrunner
was created and the methodemainMenu
is called.
-
mainMenu
(The mainMenu methode is a private methode.The very idea is to use a menu of 11 options to coordinate out in witch methode the user chose to call. The mainMenu is depended and later on called the underlying method menuSelection (what the user don't see on the console itself)) -
menuSelection
(Menu selection is the underlying method for mainMenu, and coordinate to different methods to call for the function that has been chosen) in the mainMenu().
Class Description:
-
UserList
has three class variablesString dbName = "users.txt";
Description:dbName
is the Class variable which contains storage of the actual text file that we created.UserDatabase db;
Description:db
is used in three methods:db
is used inuserList()
where the bridge to the database and retrieval of the text file for userList(). "Where you store the users that's already added"db
is used inCollection
in the methodretrieveUserList()
db
is used instoreUserList()
to store the actual list that has been created and collect from local Variable hashMapusers
HashMap<Integer, User> users;
Description:HashMap<Integer, User> users;
Is used in every single method inUserList
except fromsorterawhere()
the hashMap already is stored in the parameter from methodsortByE_Name()
main description of the class UserList
:
Is the intermediary to the
User()
class --> "constructor and toString" and the receiver and returner of the main class methods themselves. Storage, editing and sorting are properties thatUserList()
possesses.
UserList methods:
Description of addUser()
:
addUser()
is adding the import from main class, using a get id fromUser()
and puts it in a HashMap.
Description of removeUser()
:
removeUser()
is receiving an id from main class which. The given id will be removed from the HashMap.
Description of getUserById()
:
getUserById()
is receiving an id from main class, and returns the object and all the values/elements of the object.
Description of searchUsersByE_Name()
:
searchUsersByE_Name()
is receiving the last name from main class, and search and return every object with same last name. "Includes big and small letters"!
Description of searchUsersByAge()
:
searchUsersByAge()
is receiving a given age from main class and returns all the objects with the same age.
Description of userList()
;
userList()
is just for storage the objects with a given id.
Description of retrieveUserList()
:
retrieveUserList()
is receiving the full list of objects.
Description of storeUserList()
:
storeUserList()
is saving the current objects in the list.
Description of sortera()
:
sortera()
have the function of picking up
Class Description:
UserDatabase()
have the function of an dataBase but without theSQL
function. Instead of SQL i used and created a text file for the saving function, instead of starting to save again after each new run of the program. As well as we store the users we can retrieve the existing users that have been saved in the text file.
Class Description:
Class User
is where we store constructor,getters and setters and in the end the toString.
- 1. Keep configurable data at high levels.:
- Prefer polymorphism to if/else or switch/case.:
- Separate multi-threading code.:
- Prevent over-configurability.:
- Use dependency injection.:
- Follow Law of Demeter. A class should know only its direct dependencies.: