Ok, here is the explanation of what you need to do. (or at least how i did, i will show you my method)
Create a Directory on your Desktop which you can call LearningJava, in this Directory there will be other 2 Directoryes WorkSpace and WorkSpaceRow.
You will use the WorkSpace Directory for all the projects and files of the book and you will use WorkSpaceRow just for try random things, this way you can distinguish 2 workspaces.
Now you want to make a try, so just work in your WorkSpaceRow, which will have another Directory called Chapter1.
This is the structure:
C:\Users\yourUsername\Desktop\LearningJava
Now in LearningJava you will found:
LearningJava
|
|____WorkSpace
| |
| |_______Chapter1
| | <----------- Here will be the Projects and files of the Book
| |_______Chapter2
| |
|
|
|
|____WordSpaceRow
| |
| |_____Chapter1 <----------- Here you can do your files to try it and have in other location than the files of the book example
| | |_______packagea
| | |
| | |_______packageb
| | |
| | |
| | |
| | |
| | |
Now for write the code
you should use Notepad++, So the first thing to do it`s searching Notepad++ in google, download and install it.
When you done, just open Notepad++
I assume you Created all the Directoryes how i told you.
Now you should write ClassA.java in Notepad++ and then you go on the top menu, Save as -> ClassA.java(you need to write the name of the file with .java extention), then below the Name which you type you need to click and then choose Save as All Types(and not text file), save this file in the packagea directory.
After this step, you can see your ClassA.java file in the Directory which is on Desktop->LearningJava->WorkSpaceRow->Chapter1->packagea (so here you can just click click and go to see your file)
Notice: C:\temp of the Book, it`s equivalent of your C:\Users\yourUsername\Desktop\LearningJava\WorkSpaceRow\Chapter1
Now that you had write your Class and save it in your Chapter1/packagea, you need to compile it.
For compile it you need to open the cmd
cmd = Command Prompt
so you go on the left corner of your Desktop and type in the SearchBar cmd, then you hit enter
Now, you just open your Command Prompt, which is a console, so you can go everywhere in your pc by typing and not by clicking.
When you open your cmd, usually you will be in
C:\Users\yourUsername -> where yourUsername it`s just your username which is not equal to mine.
Now you can access every directory in your computer. If you wat to "doubleClick on a directory" enter in a directory you just type cd theDirectoryName.
I told you that you are now in C:\Users\yourUsername if you want to see all the files and directoryes(which is usefull to understand where you can go from where you are rigthnow) you just need to type dir and hit enter. (just try it)
After you write dir and hit enter you will see, that you can see your Desktop directory. Now let`s move there.
You type: cd Desktop and hit enter
now you will see, your path changed from C:\Users\yourUsername to C:\Users\yourUsername\Desktop, so now you need to go in the directory where is your file that you want to compile
To do this you can go directly typing from where you are the remaining path: in this case just type cd LearningJava\WorkSpaceRow\Chapter1
Now you can compile the ClassA.java which is in the packagea package.
You just type: javac packagea/ClassA.java
Now you can also go visually(click click) in the desktop, learningjava, workspacerow,chapter1, packagea directory, and you will see that after you compile you will have another file called ClassA.class(which is the bytecode, which is runnable by JavaVirtualMachine which is launched by java command)
After this you can compile your ClassB.java by typing javac packageb/ClassB.java
Now you just compiled the files individually, now just delete the ClassB.class and ClassA.class files, and try again but this time you can compile in just 1 single command like that
javac packagea/ClassA.java packageb/ClassB.java (this is waht the book says to do)
Now that you had compiled the files to run the files you should tyupe this:
java packagea.ClassA (if you want to run the ClassA program)
java packageb.ClassB (if you want to run the ClassB program)
Notice, if you want to run a class, it must have the main metod. In your case(i have also the book but maybe a different one, i have for java 11) maybe in your example ClassA don`t have any main method, but it is used when ClassB is launched, in this case, don`t try to run ClassA.
You just need to run ClassB.
So just type java packageb.ClassB
Now, if you have a .java file but it`s in no package you just run this command:
java ClassB (to run ClassB if it`s not in a package)
Basically the package it`s nothing else than a directory. But when you want to run a program, you need to be in the Directory which contain the package, and NOT run the command from the package location.