Java
Here is a little playground for Java development.
Some Java insight
The java language developed by Oracle is:
- Portable, robust and dynamic
- Platform independent
- Runs on the JVM (Java Virtual Machine) which is system dependant
With the JVM, you can write .java files, that get compiled into Java byte codes into .class file. The .class files can be executed on the Java Virtual Machine.
Environment set up
OS: Windows 7+
I first learned with the NetBeans Bundle: here which had the Oracle Jave SDK and the IDE.
Get and Install the SDK
SDK for Software Development Kit also called JDK - Java Development Kit.
You can get the Oracle Java SDK here. Choose the one for your system, here for windows.
There's the Oracle JDK (Commercial, Stable with proprietary code from Oracle) and the Open JDK (Open source, maintained by Oracle).
The JDK includes, it can be called inside a command prompt:
- The Java compiler javac - javac
- The Java Archiving Tool - jar
- the Java Debugging Tool - jdb
When installing the JDK, don't forget to add the JAVA_HOME (path to the JDK and JRE - Java Runtime Environment) as an environment variable.
Environment variables in windows are accessed via the start up menu (windows key) then:
- right click on computer > properties > advance system settings
- Click on the environment variable button
I have added setPathJava.bat script to update the JAVA_HOME. The path variable is only changed for the current cmd session. (Need to update the key registry to make it definitive).
Get an IDE
IDE for Integrated Development Environments.
I'll be trying IntelliJ: Community version by Jet Brain which has pro feature.
IF you click on the link you should be able to download it (community version is free).
Maven
What is maven
Maven is a framework developped by Apache that add standards in Java projects. By having the same hierarchy it helps keep a consistent project, manage dependencies and falicitate the build. It is a good way to share information and JAR across multiple projects.
"Maven, a Yiddish word meaning accumulator of knowledge"
Installation
Here are the steps to install Maven on Windows:
- Make sure you've intalled java and set
JAVA_HOME - Download maven at maven.apache.org
- Unzip it in C:\Program Files\Apache\maven
- Add this location to the
M3_HOMEandMAVEN_HOMEenvironment variable - Add
%M3_HOME%\binto thePATHenvironment variable⚠️ no space between the variable path separator;and%M3_HOME%\bin
Maven commands
First make sure maven is installed by running:
mvn -version
Maven can now be used to build the project:
mvn compileto run the test, compile the project, install the dependencies, create the library package.mvn packageto create the library package (such as a JAR file for example)mvn testto use the maven "surefire" plugin to run unit test in thesrc/test/javefolder with a matching*Testnamemvn installto add your project's JAR file to your local repository (like acompilebut making it ready as a dependency to be referenced by another projectmvn clean installto copy the libraries if the first one fails.
Getting started
Here is a getting started from the Apache Maven website:
The pom.xml file
When using Maven a pom.xml file is created to manage the dependencies of the project. Here is a basic example of what it could look like:
<?xml version="1.0" encoding="UTF-8"?>
<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/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>groupId</groupId>
<artifactId>Java_hero</artifactId>
<packaging>jar</packaging>
<version>1.0-SNAPSHOT</version>
<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>22.0</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.6</version>
</dependency>
</dependencies>
</project>
Here are some details on all of the shown tags:
<modelVersion>: POM model version (always 4.0.0).<groupId>: Group or organization that the project belongs to. Often expressed as an inverted domain name.<artifactId>: Name to be given to the project’s library artifact (for example, the name of its JAR or WAR file).<version>: Version of the project that is being built.<packaging>: How the project should be packaged (Optional tag). Defaults to "jar" for JAR file packaging. Use "war" for WAR file packaging.<dependencies>: Dependencies to be installed or loaded with the project<build>: Define what will be built and how.
Gradle
Gradle is an open source build automation system that builds upon the concepts of Apache Ant and Apache Maven and introduces a Groovy-based domain-specific language (DSL) instead of the XML form used by Apache Maven for declaring the project configuration
Installation
How to use
IntelliJ
IntelliJ is an IDE developed by JetBrain, the community version is free and comes with a lot of pro features (that might be overkill in some cases).
Getting started with IntelliJ
First you have to create a Java project: File > New > Project. When a screen pops up, you need to specify the link to your project SDK.
- You should find the path to the SDK here :
C:\Program Files (x86)\Javawith a name such asjdk1.8.1_02 - Or you can use the installed JDK of IntelliJ (Clicking the down arrow and selecting it)
Then you can start your project, creating a class and doing some coding.
To compile the code, you will need to hit the build button (top right) or ctrl + F9.
To Run it, will have to edit configurations (next to the build button). Click on the arrow and select Edit Configurations.
A window appear, on the left side there's a dropdown menu (called Defaults). Click on it and select Application. On the right panel, add a name and the main class you've just created. Press ok to validate.
Now that you have that set up you should see a green arrow next to that field (next to the build button). If you click on it, it will run your project and you'll see on the bottom a split screen with the output (like Netbeans, yeah!).
Maven on IntelliJ
So to use Maven with IntelliJ, you first need to right click on a project and select Add framework support ....
A new page will show up and you can select Maven, it will automatically reformat your code structure to adapt to Maven. A pom.xml will be created.
<build> tag in the <project> tag :
<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</build>The above solution worked great on IntelliJ. You can also can try this solution from Apache Maven.
Setting up dependencies, add external libraries
You can add external libraries to your Java project. Here are two ways of doing in with IntelliJ.
with JAR
You can download the JAR file of the external library and add it to your project. For that you can do go on File > Project Structure (or [ALT] + [ctrl] + [shift] + [S]).
Once there you can click on the green plus and add the .jar file. (Save the Jar in your place for libraries such as lib/directory).
Now you should be all set, you can now import the library:
//Importing a library
import main.java.com.library;with Maven
To add an external library to your project, just copy and past the <dependency> into <dependencies> inside <project> of your pom.xml
Here for example for the Guava library from Google:
<project>
<!-- information about your project -->
<dependencies>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>22.0</version>
</dependency>
<dependencies>
</project>

Formed in 2009, the Archive Team (not to be confused with the archive.org Archive-It Team) is a rogue archivist collective dedicated to saving copies of rapidly dying or deleted websites for the sake of history and digital heritage. The group is 100% composed of volunteers and interested parties, and has expanded into a large amount of related projects for saving online and digital history.
