Skip to content

Commit 6d17f54

Browse files
committed
Two first programs: 01 The Basics and 02 Packages
1 parent d9a4f72 commit 6d17f54

File tree

5 files changed

+230
-9
lines changed

5 files changed

+230
-9
lines changed

.idea/uiDesigner.xml

Lines changed: 124 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

README.md

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,17 @@
1-
# JavaFundamentals
1+
# JavaFundamentals
2+
3+
This project intends to quickly show you or remind you the Java syntax and usage for many common constructs and standard Java libraries.
4+
5+
There are explanations as comments inside the code.
6+
7+
Source files are named in a way you can quickly locate the subject you are searching for.
8+
9+
They are also numbered, so they show up in order inside your folder and you can locate them in the Table of contents.
10+
11+
The very first file, JF01_TheBasics, is in the source root (`src`) folder. The others are under
12+
`com/fledger/javafundamentals`.
13+
14+
Table of contents:
15+
16+
1. `JF01_TheBasics`: comments, statements, class, and entry point
17+
2. `JF02_Packages`: packages and imports

src/JF01_TheBasics.java

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
// The Basics - Comments, classes, and entry points
2+
3+
// This is a comment line. Everything after the // is ignored by the Java compiler (until the end of the line).
4+
5+
/*
6+
This is a comment block. Everything between "whack asterisk" and "asterisk whack"is ignored...
7+
even if it spans multiple lines...
8+
or if it is on the line of the comment delimiter. */
9+
10+
/**
11+
* This is a Javadoc comment. It is a special type of block comment.
12+
* It starts with "whack asterisk asterisk" and is used to generate documentation automatically.
13+
* from your Java source code. Javadoc is the name of the tool that generates the documentation.
14+
* Read more @ https://en.wikipedia.org/wiki/Javadoc
15+
*/
16+
17+
// This is a class. Usually classes are written one class per file, on a file with the same name
18+
// as the class plus the extension ".java".
19+
public class JF01_TheBasics {
20+
21+
// This a program entry point. If a method (function of a class) has this exact signature:
22+
// public static void main(String[] args)
23+
// it can be where your program starts running, the entry point.
24+
public static void main(String[] args) {
25+
26+
// This is a statement and it prints the string "Hello Java Fundamentals" on the console (System.out).
27+
System.out.println("Hello Java Fundamentals!");
28+
29+
// Statements end with a semicolon. Spaces (or tabs, or new line characters) do not matter for the compiler.
30+
31+
}
32+
33+
/*
34+
To compile and run this program:
35+
1. Download and install the Java JDK: http://www.oracle.com/technetwork/java/javase/downloads/index.html
36+
recommendation: start out with the latest Java 8 JDK (Java 1.8)
37+
2. From the command line, on the directory where this file is, execute the command: javac "JF01_TheBasics.java
38+
Obs.: if you list the contents of the folder you should see the file JF01_TheBasics.class (the compiled class)
39+
3. From the command line, execute the command "java JF01_TheBasics""
40+
Result: you should see the string "Hello Java Fundamentals!" on the screen.
41+
*/
42+
}
43+
44+
// Next Source code: JF02_Packages.java
45+
// This file will be under com/fledger/javafundamentals
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
// Packages determine the folder structure of your projects.
2+
// They are used to organize your source code and create scope to avoid name collisions.
3+
// 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
7+
// 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)
9+
package com.fledger.javafundamentals;
10+
11+
// Imports let you use code from other classes or packages
12+
13+
// The following statement lets you use the class Date from the package java.util:
14+
import java.util.Date;
15+
16+
// The following statement lets you use any class from the java.text package (including DateFormat):
17+
import java.text.*;
18+
19+
// The fully qualified name of this class is com.fledger.javafundamentals.JF02_Packages
20+
public class JF02_Packages {
21+
22+
// You already know what an entry point is:
23+
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.
25+
Date now = new Date();
26+
// Creates an object to format a Date with the long time format.
27+
DateFormat dateFormat = DateFormat.getTimeInstance(DateFormat.LONG);
28+
// Writes the current time using the long time format.
29+
System.out.println("Now it is " + dateFormat.format(now));
30+
}
31+
32+
/*
33+
To compile and run this program:
34+
1. From the command line, on the source root folder, execute the command:
35+
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
38+
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!
43+
*/
44+
}

src/com/fledger/javafundamentals/Main.java

Lines changed: 0 additions & 8 deletions
This file was deleted.

0 commit comments

Comments
 (0)