Welcome to part 2 of this review of the Pluralsight course Java Fundamentals: The Java Language by Jim Wilson
Jim has over 30 years of software engineering experience, with the past 15 years heavily focused on creating mobile device and location-based solutions. He has co-founded multiple software-related startups and has served in a consulting role at several more.
After nearly a decade as a Microsoft Device Application Development MVP, Jim now focuses on developing Android and iOS device applications. Jim’s passion is mentoring software developers. He blogs at hedgehogjim.wordpress.com.
Java Fundamentals: Creating a Simple App
Demo: Creating Your First IntelliJ Project
We create our first Java project using IntelliJ IDEA.
Jim shows us how to:
- Create a new Java project
- Associate the JDK version that we want to use
- Use the command line app project template
- Write the code to print “Hello World” in the main method
- Compile and run our Hello World program
Demo: Running from the Command Line
We look at how we can run our program without needing to use a developer tool such as IntelliJ.
In the first part we learned that end users need to install the JRE.
On a windows computer we can find the JRE directory inside C:/Program Files/Java/
We see there’s a program called java.exe and this program is what runs our program.
For windows users, Jim shows how to add this as a path.
Inside the control panel, we go to advanced system settings and then click the “Environment Variables…” button. We then click New if there isn’t already a Path user variable, or edit it if there is one already there.
Now to run our program we go to our out/production/HelloWorld directory (assuming IntelliJ is our IDE)
Jim shows a really simple but useful Windows trick that I never knew you could do before: type cmd in the File Explorer address bar and it opens the command prompt at the same directory that you were on in the File explorer.
To run our hello world program we type:
java Main
Statement Structure and Whitespace
Like many other languages, Java programs are made up of statements and statements end with semicolons.
Jim explains that Java allows us a lot of flexibility with whitespace and this allows us to format our code in whichever we we feel works best for us.
Comments
Jim says comments allow us to:
- Add human-readable notes to source code
- “Hide” source code without deleting
This second use of comments is the very poor practice that inspired this blog. For more information on using comments effectively see the Comments module of Cory House’s Clean Code course.
There are three types of comments in Java:
- Line comments using //
- Block comments uses /* … */
- JavaDoc comments /** … */
Demo: Comments
Jim demonstrates how to use each of the three types of comments.
We see that we cannot nest block comments.
Introducing Packages
Packages provide organization within a Java program.
- They follow a standard naming convention
- They affect our source code file structure
The package naming conventions are:
- All lowercase
- Use reversed domain names to assure global uniqueness
- Add further qualifiers to assure uniqueness within a company/group
Jim explains why these are good conventions.
Our package names affect the source file structure:
Java itself requires no correlation between package names and source code file structure.
However, most IDE’s do require a sub-folder for each part of the package name.
We see what file structure we would have for the package com.pluralsight.example
Demo: Packages
Jim creates a new project called “Organized” with the base package “com.pluralsight.getorganized”
We see how it affects the file structure, and how we run this program from the command line.
Creating and Running a NetBeans Project
We’ve been using IntelliJ in earlier demos, but you might prefer NetBeans IDE over IntelliJ.
Jim shows how to accomplish the same things in this IDE.
Fundamentally, all of the IDEs work in similar ways. However NetBeans uses a different file structure to IntelliJ.
Instead of having an output folder we have a build folder, and instead of a production folder we have a classes folder.