BCS Java Date Difference

There are may solution to Java challenges. Today our challenge surrounds calculating elapsed years, months, days, hours, minuets and seconds between two dates.

The primary workhorse for this task is JodaTime utility. Click on the Releases option and the Downloads sub option to download jars and utilities. Simply add the downloaded jar to tour Java project and you are ready for action.

package dtt;
 
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
 
import org.joda.time.Interval;
import org.joda.time.Period;
 
public class ft {
 
	public static void main(1.5.0/docs/api/java/lang/String.html">String[] args) {
 
		1.5.0/docs/api/java/text/SimpleDateFormat.html">SimpleDateFormat simpleDateFormat = new 1.5.0/docs/api/java/text/SimpleDateFormat.html">SimpleDateFormat("dd/M/yyyy hh:mm:ss");
 
		try {
 
			5+0%2Fdocs%2Fapi+Date">Date date1 = simpleDateFormat.parse("10/10/2016 11:30:10");
			5+0%2Fdocs%2Fapi+Date">Date date2 = simpleDateFormat.parse("13/11/2017 20:35:55");
 
			// obj.printDifference(date1, date2);
			printDifference(date1, date2);
 
		} catch (1.5.0/docs/api/java/text/ParseException.html">ParseException e) {
			e.printStackTrace();
		}
	}
 
	public static void printDifference(5+0%2Fdocs%2Fapi+Date">Date startDate, 5+0%2Fdocs%2Fapi+Date">Date endDate) {
 
		Interval interval = new Interval(startDate.getTime(), endDate.getTime());
		Period period = interval.toPeriod();
 
		1.5.0/docs/api/java/lang/System.html">System.out.println("  Start Date : " + startDate.toString());
		1.5.0/docs/api/java/lang/System.html">System.out.println("    End Date : " + endDate.toString());
		1.5.0/docs/api/java/lang/System.html">System.out.printf("Elapsed Time : " + "%d years, %d months, %d days, %d hours, %d minutes, %d seconds%n", period.getYears(),
				period.getMonths(), period.getDays(), period.getHours(), period.getMinutes(), period.getSeconds());
	}
}

The execution of the program is listed below.

Mr. Arch Brooks, Software Engineer, Brooks Computing Systems, LLC authored this article.

BCS Install Oracle JDK On Linux Mint

OpenJDK does not support JavaFX while Oracle JDK does contain support for FX.  Installation of Oracle JDK on Mint is required.

To proceed with installation of Oracle JDK issue the following command.

sudo apt-get update && apt-get remove openjdk*

Traverse to the location where JDK is stored.

cd ~/Downloads

Unzip the JDK with the following command.

tar -zxvf jdk-8u131-linux-x64.tar.gz

Create a permanent directory for the JDK.

sudo mkdir -p /opt/java

Next send the JDK to its permanent location by issuing the following command.

sudo mv jdk1.8.0_131 /opt/java

Install the JDK bu issuing the following command.

sudo update-alternatives --install "/usr/bin/java" "java" "/opt/java/jdk1.8.0_131/bin/java" 1

Set JDK Alternatives as follows.

sudo update-alternatives --set java /opt/java/jdk1.8.0_131/bin/java

Finally check the the version information.

$ java -version

You have successfully installed the Oracle JDK on Linux Mint.

Mr. Arch Brooks, Software Engineer, Brooks Computing Systems, LLC authored this article.

BCS Mint And Java FX

The OpenJDK series is not suitable for development of JavaFX applications. The OpenJDK does not possess the run time environment required for JavaFX. To alleviate this problem you must first remove OpenJDK and install the JDK provided by Oracle.

Here is an example of how to install the Oracle JDK in Mint.

Typically you will have opened Eclipse in an effort to develop applications and the Eclipse ini file is pointing to the OpenJDK as the Java Virtual Machine (JVM). To correct this problem edit the Eclipse.ini file listed below.

-startup
plugins/org.eclipse.equinox.launcher_1.3.201.v20161025-1711.jar
--launcher.library
/home/archman/.p2/pool/plugins/org.eclipse.equinox.launcher.gtk.linux.x86_64_1.1.401.v20161122-1740
-product
org.eclipse.epp.package.rcp.product
--launcher.defaultAction
openFile
-showsplash
org.eclipse.platform
--launcher.appendVmargs
-vm
/opt/java/jdk1.8.0_131/jre/bin
-vmargs
-Dosgi.requiredJavaVersion=1.8
-XX:+UseG1GC
-XX:+UseStringDeduplication
-Dosgi.requiredJavaVersion=1.8
-Xms256m
-Xmx1024m
-Declipse.p2.max.threads=10
-Doomph.update.url=http://download.eclipse.org/oomph/updates/milestone/latest
-Doomph.redirection.index.redirection=index:/->http://git.eclipse.org/c/oomph/org.eclipse.oomph.git/plain/setups/

Make sure the “/opt/java/jdk1.8.0_131/jre/bin” the first line after the -vm switch identifies the correct location of the desired JVM.

You should be able to develop JavaFX applications with this configuration under Linux Mint.

Mr. Arch Brooks, CEO / Software Engineer, Brooks Computing Systems, LLC.  authored this article.

BCS JavaFX Scene Builder

The Scene Builder allows the user to create Java FX scenes in an automated fashion.  To add java object to the Scene Builder click on the option control next to the Library control identifier and the following drop down will appear.

When you click on the option the following dialog will appear.

Click on the Add Library FXML from file system.

The scene builder is available from Eclipse in both the Windows and Ubuntu versions. It appears as a pop up option when it is successfully configured.

Mr. Arch Brooks, Software Engineer, Brooks Computing Systems, LLC authored this article.

BCS Fix FX File Specification

In order to use strings to represent file specs in Java and c++ the back slash indicated the beginning of the escape sequence.  The double back slash indicates no escape sequence and the single back slash is interpreted.
This application takes care of file specification to be used in Java and c++ and places the results on the clipboard for subsequent use.

A 32-bit executable program may be down loaded by clicking here.
A 64-bit executable program may be down loaded by clicking here.
The component documentation can be found by clicking here.
The source code may be found by clicking here.

Mr. Arch Brooks, Software Engineer, Brooks Computing Systems, LLC authored this article.

BCS How To Launch A Java Archive (No Bat File)

To enable the launching of a java archive (jar) file traverse to the executable java archive’s location using windows explorer.  Right click on the jar file then select the Send To Desktop option.

Once the shortcut is created rename it to a name of your liking.  At this point you may also change its icon if so desire.

To launch the jar double click the icon or right click and choose the open option.

This technique will function for all the java tasks you care to launch from the windows desktop.

Mr. Arch Brooks, Software Engineer, Brooks Computing Systems, LLC authored this article.

BCS Java FX Project Source Code Generator

When programming Java FX I noticed the project offered would lend itself to producing monolithic spaghetti code.  I took the initiative to design a project that more closely adhered to MVC paradigm.  A template and templating system was used for the creation of subsequent projects.  Then key phrases were changed to create a new project.  Compartmentalizing the components in this manner allows the user to select packages to be implemented for the design and production of expert systems.

Having authored source code generating programs since 1974 I decided to author a code generator for Java FX projects.  The project source code generator is written in Java FX.  First the end user must select a sub directory in which the project will reside.  The last sub directory in the file specification becomes the family id or program name for the resulting project.  Every bit of the code required to make the Java FX application function in the Eclipse (Neon.2) IDE is dynamically generated.  This approach allows the programmer the ability to design the application as opposed to preparing for the design of the application.

A 32 bit executable program may be downloaded by clicking here.
A 64 bit executable program may be downloaded by clicking here.
The component documentation can be found by clicking here.
The source code may be found by clicking here.

Mr. Arch Brooks, Software Engineer, Brooks Computing Systems, LLC authored this article.