Читать книгу OCP Oracle Certified Professional Java SE 17 Developer Study Guide - Jeanne Boyarsky - Страница 79

Compiling and Running Code with Packages

Оглавление

You'll learn Java much more easily by using the command line to compile and test your examples. Once you know the Java syntax well, you can switch to an IDE. But for the exam, your goal is to know details about the language and not have the IDE hide them for you.

Follow this example to make sure you know how to use the command line. If you have any problems following this procedure, post a question in the Beginning Java forum at CodeRanch. Describe what you tried and what the error said.

www.coderanch.com/forums/f-33/java

The first step is to create the two files from the previous section. Table 1.1 shows the expected fully qualified filenames and the command to get into the directory for the next steps.

TABLE 1.1 Setup procedure by operating system

Step Windows Mac/Linux
Create first class. C:\temp\packagea\ClassA.java /tmp/packagea/ClassA.java
Create second class. C:\temp\packageb\ClassB.java /tmp/packageb/ClassB.java
Go to directory. cd C:\temp cd /tmp

Now it is time to compile the code. Luckily, this is the same regardless of the operating system. To compile, type the following command:

javac packagea/ClassA.java packageb/ClassB.java

If this command doesn't work, you'll get an error message. Check your files carefully for typos against the provided files. If the command does work, two new files will be created: packagea/ClassA.class and packageb/ClassB.class.

OCP Oracle Certified Professional Java SE 17 Developer Study Guide

Подняться наверх