Uchechukwu Onyekwuluje's Knowledge & Brain Dumps

Setting up Java Development Environment

Before you start developing code in Java, you need to setup your development environment with the necessary development tools required to build, compile, test and execute your java code.

Base Requirements

Setup

This setup is geared towards linux systems and assumes a basic level of systems administration.

HelloWorld

Any programming tutorial will not be complete without the famous “HelloWorld”. We will generate one with some added features and functionality.

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>com.javaconcepts.app</groupId>
  <artifactId>javaconcepts</artifactId>
  <packaging>jar</packaging>
  <version>1.0-SNAPSHOT</version>

  <properties>
    <maven.compiler.source>1.7</maven.compiler.source>
    <maven.compiler.target>1.7</maven.compiler.target>
  </properties>

  <name>javaconcepts</name>
  <url>http://maven.apache.org</url>
  <dependencies>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>3.8.1</version>
      <scope>test</scope>
    </dependency>
  </dependencies>

  <build>
    <plugins>
        <plugin>
            <artifactId>maven-assembly-plugin</artifactId>
            <configuration>
                <archive>
                    <manifest>
                        <mainClass>com.javaconcepts.app.App</mainClass>
                    </manifest>
                </archive>
                <descriptorRefs>
                    <descriptorRef>jar-with-dependencies</descriptorRef>
                </descriptorRefs>
            </configuration>
        </plugin>
    </plugins>
  </build>

</project>
package com.javaconcepts.app;

public class App 
{
    public static void main(String[] args)
    {
        App2 newapp = new App2();
        System.out.println("Hello World!");
        System.out.println("Welcome to my first App");
        newapp.displayName();        
    }
}

and create a second one src/main/java/com/javaconcepts/app/App2.java with code below:

package com.javaconcepts.app;

public class App2 
{
    public void displayName()
    {
        System.out.println("Welcome to my second class");
    }
}

Remarks

I tried to address a few things here.