Friday, June 15, 2018

Java SE 8 Date and Time API

Time is a scalar quantity, so it would only need a number to express a time value.
Since you want to relate time to calendars, which are made for humans, things get more complicated.

Java date and time classes' history:

  • the java.util.Date class was introduced in Java 1.0
  • the java.util.Calendar class was introduced in Java 1.1
  • third-party date and time libraries, such as Joda-Time, were used by developer to overcome Java standard API's issues
  • the java.time API was introduced in Java 1.8 to fix the flaws in the previous versions of the platforms

1 The Time Line

The unit of time is the second, which is derived from the Earth's rotation around its axis.

Universal Time

  • Earth rotation is not uniform: in 1967, a more precise definition of second was derived from the property of atoms of caesium-133 and atomic clocks were introduced to keep the official time.
  • Since rotation rate of Earth varies with climate events, official time keepers synchronize absolute time with solar mean time
    • official time keepers add or remove a second to keep the Universal Time close to the mean solar time
  • In UTC, a day has 24 * 60 * 60 = 86400 seconds.
    • the number of seconds in a minute is usually 60, but with an occasional leap second it may be 61.

Universal Time and Computer Systems

  • Computer system keeps 86400 seconds per day and do not respect leap seconds.
  • when a leap second is officially introduced, computer systems slow down or speed up before the leap second.

Java Date and Time API specification for the time scale:

  • A day has 86,400 seconds
  • Time scale matches the official time at noon each day

The Time Line in Java and the Instant class

  • the Instant class represents a point in the time line
  • The static method returns the current instant
  • time is measured on time scale with origin set at midnigth of January 1, 1970 at Greenwich meridian
  • from that origin, time is measured in 86,400 seconds per day
  • Instant.MIN and Instant.MAX are one billion behind and ahead the origin

The Duration class represents the amount of time between two instants

  • the static method Duration.between gives the difference between two instants


 Instant start =;
 Instant stop =;
 Duration timeElapsed = Duration.between(start, stop);
 long millis = timeElapsed.toMillis(); 

Wednesday, May 23, 2018

UTC Date Time System and ISO Representation

1 UTC Date Time System

1.1 UTC Time standard definition

Coordinated Universal Time (UTC) is the time standard by which the world regulates clocks and time.

The UTC is defined by an International Telecommunications Union recommendation and is based on International Atomic Time.

  • the standard adopt leap seconds to adjust UTC Time and compensate for the slowing of Earth's rotation.
  • Greenwich Mean Time (GMT) was formerly used as the international time standard, then UTC superseded GMT.
1.2 How UTC Time works

UTC divides time into days, hours, minutes and seconds.

UTC days
  • are identified using the Gregorian calendar.
  • contain 24 hours and each hour contains 60 minutes.
  • almost all UTC days contain exactly 86,400 SI seconds.
UTC minutes:
  • usually a minute contains 60 seconds, but with an occasional leap second, it may be 61 or 59.
  • because of leap seconds, the minute and all larger time units are of variable duration.
UTC seconds:
  • is the smaller time units of constant duration.
1.3 UTC Time Zones

Time zones are regions of the earth where the local time is defined as differing the UTC Time by an integer number of hours

  • but some countries have established time zones that differ by a number of half-hours or quarter-hours from UTC.
  • this difference or offset is positive or negative:
    • the westernmost time zone is twelve hours behind UTC and is UTC-12
    • the easternmost time zone is fourteen hours ahead of UTC and is UTC+14

Civil Time

Civil Time indicates the time designated by authorities or local time indicated by clocks.

  • civil time is generally standard time in a time zone at a fixed offset from Coordinated Universal Time (UTC), adjusted by daylight saving time during part of the year.

The Civil Time in a particular time zone can be determined from the UTC Time by adding or subtracting the number of hours and minutes specified by the UTC offset.

1.4 Daylight Saving Time

UTC does not observe daylight saving time and does not change with seasons

Local Time or Civil Time may change if a time zone jurisdiction observes Daylight Saving Time (summer time).


  • local time on the east coast of the United States is five hours behind UTC during winter, but four hours behind UTC during summer.
1.5 Who uses UTC

UTC is used by Computer systems and the Internet

  • in the internet and World Wide Web standards
  • the Network Time Protocol synchronizes the clocks of computers over the internet, using the UTC system
  • email systems and other messaging systems time-stamp messages using UTC
  • database records that include a time stamp use UTC

UTC is also the time standard used in aviation, weather forecasts, maps, amateur radio operators

Friday, April 6, 2018

Introduction to GIT


  1. Getting a Git Repository
  2. Recording Changes to the Repository
  3. Viewing the Commit History
  4. Working with Remotes

1 Getting a Git Repository

This guide contains the basic commands required to work with Git.

How to get a Git repository

You can get a Git repository in two ways:

  • turn a local directory into a Git repository
  • get a copy of an existing repository
Initializing a Repository in an Existing Directory

You have a project directory, not under version control, you want to control with Git

  • go to the directory of the project
  • type git init

The git init command create a .git subdirectory that contains the files required by the Git repository.

Cloning an Existing Repository

To get a copy of an existing Git repository use the clone command

  • you can clone a project's repository you want to contribute to.

For example, you can clone the Oracle's First Cup Java Tutorial with the following command:

  • $ git clone
  • it is said that the command pulls down or check out a working copy of the latest version

To clone the Oracle's First Cup Java Tutorial in a target directory of your choice use the command:

  • $ git clone firstCupJavaTutorial

Saturday, March 17, 2018

Introduzione a Git

1. Introduzione

Git e' un sistema di version control ( Lo scopo di Git e' quello di tener traccia di tutti i cambiamenti effettuati all'interno di un progetto software in modo da assicurare sempre una versione di backup delle versioni precedenti. In questo modo, se qualcosa va storto, e' possibile invertire le modifiche e ripristinare il precedente stato funzionante del software.
A differenza degli altri sistemi di versionamento, quasi tutte le operazioni in Git non hanno bisogno di una connessione internet, perché sono operazioni che avvengono su disco locale. Git salva lo storico completo del progetto direttamente su disco locale e recuperare una vecchia versione di un file dalla history é una operazione istantanea. Anche le commit avvengono sul database locale
Git vs GitHub

Git e GitHub sono due cose diverse: GitHub e' un servizio online basato su Git, ma non e' indispensabile per usare Git e creare un repository. GitHub permette di hostare online un repository creato con Git e condividerlo con altri sviluppatori.
L'hosting pubblico su GitHub e' gratuito, l'hosting privato e' a pagamento. Per questo motivo gli sviluppatori usano altri servizi online per condividere repository Git, come e
Le aree di lavoro di Git

Git e' composto da quattro aree di lavoro:

Il luogo dove lo sviluppatore crea e modifica il codice del progetto e' rappresentato dalla working directory di Git, che contiene i file che andranno a costituire il repository Git.

Friday, February 23, 2018

Enterprise Beans

Enterprise beans run in the EJB container:

  • the EJB container is a runtime environment within a Java application server
  • the EJB container provides system-level services to enterprise beans such as transactions and security


  1. What Is an Enterprise Bean?
  2. What Is a Session Bean?
  3. What Is a Message-Driven Bean?

1 What Is an Enterprise Bean?

An enterprise bean is a server-side component that contains the application's business logic

  • for example, in an auction application, the AuctionManager enterprise bean implements the business logic in the methods named createAuction, placeBid, closeAuction.
1.1 Benefits of Enterprise Beans

Enterprise beans simplify the development of large applications:

  • the EJB container, not the developer, is responsible for system level services such as transaction management and security authorization
  • the beans not the clients contain the business logic, the clients only contain the presentation. As a consequence, application clients are thinner
  • enterprise beans are portable, they are portable accross any compliant Java EE server and developers can build new applications from existing beans
1.2 When to Use Enterprise Beans

You should consider using enterprise beans if your application has any of the following requirements:

  • the application must be scalable to support more users and you need to distribute application's components to multiple machines
  • transactions must ensure data consistency
  • application will be accessed by a variety of clients
1.3 Types of Enterprise Beans

There are two types of enterprise beans, which fulfill different purposes:

  • Session: a session bean performs a task for a client
  • Message-driven: a message-driven bean acts as a listener for messages

Tuesday, January 16, 2018

Introduction to Java Platform, Enterprise Edition

Companies need distributed, transactional and portable applications: enterprise java applications fulfill the business logic for the enterprise.

Java platform provides APIs to developers and shortens developement time

The Java Community Process (JCP) writes Java Specification Requests (JSRs) to define the Java EE technologies

The Java EE 7 platform simplifies the programming model:

  • Developers can use annotations in Java source files, instead of optional XML deployment descriptors. The Java EE server reads annotations and configures components at deployment and runtime
  • With dependency Injection, required resources can be injected in component, instead of using JNDI lookup code. Dependency injection can be used in any container type: EJB container, web container and application client container. The container is aware of annotations and inject references to other component/resource

1 Java EE Application Model

Java EE applications implement enterprise services for customers, access data from different sources and distribute applications to a variety of clients

The business functions of Java enterprise applications are in the middle tier: the middle tier is usually on a dedicated server hardware.

The Java application model architecture implements the customer's services as multitier applications

The Java model partitions the work in two parts:

  • business logic and presentation implemented by developers
  • standard services provided by Java EE platform

Friday, October 20, 2017

Java EE Component Model

1 Component-Based Development

The Java EE platform supports component-based development
  • component-based development is based on the principle of loose coupling
  • loosely coupled systems are easy to test and maintain

2 Java EE Components

A Java EE component is a group of classes and interfaces that implements a single functionality

  • a component is assembled into a Java EE application, with its related classes and files
The java EE specifications define different types of components:
  • Application clients and applets are components that run on the client.
  • Java Servlet, JavaServer Faces, and JavaServer Pages (JSP) technology components are web components that run on the server.
  • EJBs components (enterprise beans) and Entity classes are business components that run on the server.