|
1 |
| -// Packages determine the folder structure of your projects. |
| 1 | +// Java Fundamentals 02 - Packages |
| 2 | + |
| 3 | +// Packages determine the folder structure of your projects. By convention they are all lowercase. |
2 | 4 | // They are used to organize your source code and create scope to avoid name collisions.
|
3 | 5 | // If you use a package, it should be the first statement of your source file.
|
4 |
| -// To keep names unique, package names usually start with the domain name inverted |
5 |
| -// ex.: fledger.com -> com.fledger |
6 |
| -// after the domain name you determine the package hierarchy to organize your code |
| 6 | +// To keep names unique, package names usually start with the web domain name inverted |
| 7 | +// ex.: fledger.com -> "com.fledger" |
| 8 | +// following the inverted domain name, you name package hierarchy to organize your code |
7 | 9 | // The folder structure should reflect the package structure, from the root of source code.
|
8 |
| -// ex.: com.fledger.javafundamentals => src/com/fledger/javafundamentals (if src is the root of source code) |
| 10 | +// ex.: "com.fledger.javafundamentals" -> src/com/fledger/javafundamentals (if src is the root of source code) |
9 | 11 | package com.fledger.javafundamentals;
|
10 | 12 |
|
11 | 13 | // Imports let you use code from other classes or packages
|
12 | 14 |
|
13 |
| -// The following statement lets you use the class Date from the package java.util: |
| 15 | +// The following statement lets you use the class Date from the package "java.util": |
14 | 16 | import java.util.Date;
|
15 | 17 |
|
16 |
| -// The following statement lets you use any class from the java.text package (including DateFormat): |
| 18 | +// The following statement lets you use any class from the "java.text" package (including "DateFormat"): |
17 | 19 | import java.text.*;
|
18 | 20 |
|
19 |
| -// The fully qualified name of this class is com.fledger.javafundamentals.JF02_Packages |
| 21 | +// The fully qualified name of this class is "com.fledger.javafundamentals.JF02_Packages" |
20 | 22 | public class JF02_Packages {
|
21 | 23 |
|
22 | 24 | // You already know what an entry point is:
|
23 | 25 | public static void main(String[] args) {
|
24 |
| - // Creates an object now from the class Date (contains date and time). It is initialized to the current time. |
| 26 | + // This creates an object called "now" from the class "Date" (that contains date and time). |
| 27 | + // It is initialized to the current time. |
25 | 28 | Date now = new Date();
|
26 |
| - // Creates an object to format a Date with the long time format. |
| 29 | + // This creates an object to format a "Date" with the long time format. |
27 | 30 | DateFormat dateFormat = DateFormat.getTimeInstance(DateFormat.LONG);
|
28 |
| - // Writes the current time using the long time format. |
| 31 | + // This writes the current time using the long time format. |
29 | 32 | System.out.println("Now it is " + dateFormat.format(now));
|
30 | 33 | }
|
31 | 34 |
|
32 | 35 | /*
|
33 | 36 | To compile and run this program:
|
34 | 37 | 1. From the command line, on the source root folder, execute the command:
|
35 | 38 | javac com/fledger/javafundamentals/JF02_Packages.java
|
36 |
| - Obs.: it will create JF02_Packages.class in that folder (javafundamentals) |
37 |
| - 2. From the command line, execute the command |
| 39 | + Obs.: it will create a "JF02_Packages.class" file in that folder (javafundamentals) |
| 40 | + 2. From the command line, execute the command (still from the source folder) |
38 | 41 | java com.fledger.javafundamentals.JF02_Packages
|
39 |
| - Notice that you compile (javac) a file (with .java extension) |
40 |
| - and run (java) a class (with fully qualified name) |
41 |
| - Result: you should see "Now it is " and the current time, long format, on the screen. |
42 |
| - By the way, it is about time for you to use an IDE. I recommend Eclipse or IntelliJ Idea Community! |
| 42 | + Notice that you compile (javac) a file (with .java extension), |
| 43 | + and you run (java) a class (using its fully qualified name) |
| 44 | + Result: you should see "Now it is " followed by the current time on the screen. |
| 45 | + By the way, it is about time for you to use an IDE. I recommend Eclipse or IntelliJ Idea CE, both free! |
43 | 46 | */
|
44 | 47 | }
|
| 48 | + |
| 49 | +// previous file: src/JF01_TheBasics.java -> https://goo.gl/rJN5Aj |
| 50 | +// next file: src/com/fledger/javafundamentals/JF03_xxx.java -> |
0 commit comments