Java:
Starting a new project

How to:

Let’s get to it. We’ll create a simple Java project using the command line and compile and run a classic “Hello, World!” program.

First, make a directory for your project and navigate into it:

mkdir MyJavaProject
cd MyJavaProject

Now, create your Java file:

echo 'public class HelloWorld { public static void main(String[] args) { System.out.println("Hello, World!"); }}' > HelloWorld.java

Time to compile:

javac HelloWorld.java

Run your masterpiece:

java HelloWorld

Voilà! The console should output:

Hello, World!

Deep Dive:

Once upon a time, Java projects were managed manually, a bit like juggling files in a circus. Nowadays, we have tools like Maven and Gradle to automate the mundane stuff.

Maven, for example, defined the standard project layout which most Java developers are familiar with today. It also handles dependencies so you don’t have to manually download jars and battle classpath nightmares.

Gradle stepped into the scene later, offering more flexibility and using a Groovy-based DSL (Domain Specific Language) for scripting. It’s like Maven, but with more freedom for custom scripts without extra plugins.

Alternatives? Sure, there’s Ant with Ivy, but it’s a bit old school, like listening to music on a cassette tape. You’ve got to love the nostalgia, but it might not be for everybody in this age of streaming services.

When you start a new Java project, think of how big and complex it’ll get. For learning or tiny projects, manual management works fine. But if you’re planning to build something substantial or work in a team, a build tool is the way to go.

See Also:

To get a leg up on using build tools, check out the following:

And for those of you who want to dive deeper into the JDK’s new features, the Java Platform, Standard Edition Oracle Documentation is a treasure trove.