avatar

Andres Jaimes

How to install Java and Maven on FreeBSD

FreeBSD is a powerful and reliable operating system that is widely used by developers and system administrators. If you are a Java developer, you will need to install both Java and Maven on your FreeBSD system to build and run your Java applications. In this post, we will walk you through the steps to install Java and Maven on FreeBSD. Java We will start by switching to the root account, and installing java.

Why you should not initialize a random generator with a static number

The following examples use random generated numbers initialized with a static seed. Never do it like this. Run the following examples multiple times to understand why it is important to have a good seed. PHP version: #!/usr/bin/php <?php srand(2); echo rand(0,10)."\n"; echo rand(0,5)."\n"; echo rand(0,4)."\n"; echo rand(0,6)."\n"; Java version: import java.util.*; /** * @see https://docs.oracle.com/javase/7/docs/api/java/util/Random.html */ public class RandomDemo { public static void main( String args[] ){ Random r = new Random(2); System.

Recommended libraries for Java

This article lists a curated list of Java libraries that I have used over the years for different projects. They are all well documented, and for most of them, plenty of examples can be found on the web. Apache Commons Email Commons Email Commons Email aims to provide a API for sending email. It is built on top of the Java Mail API, which it aims to simplify. User Guide Apache Commons StringUtils <dependency> <groupId>org.

PlayFramework – Java

So far I have really liked this concept. The only con is that some times is difficult to find full examples that use the latest version. Installing sbt We need sbt for compiling and running Play applications. brew install sbt@1 Executing a first application Check the tutorials page to see how to create a first project. Pretty much: sbt new playframework/play-java-seed.g8 sbt run And then visit localhost:9000 Play 2.

How to run a custom update using Java JPA

From time to time it is necessary to execute a query without using Java’s JPA infrastructure. In order to do it, we have to define a NamedQuery to execute. In this example, I will run an update against the database. @Entity @NamedQueries ({ @NamedQuery ( name = "SomeEntity.TestQuery", query = "update SomeEntity se set se.myField = '' where se.id = 0" ) }) public class SomeEntity implements Serializable { // .

Quick lessons on working with Java’s BigDecimal

Today I bring an example of the different results you can expect when using Java’s BigDecimal class. From instantiation to applying different arithmetic operations, it is important to understand how they affect the resulting instances. The following program shows different scenarios and results applied to BigDecimal’s. package test; import java.math.BigDecimal; import java.math.RoundingMode; public class Test { public static void main(String[] args) { BigDecimal a = new BigDecimal("1.204165"); System.out.println("a (from string): " + a); // 1.

Read all tables and columns from a database using Java

This Java example finds all the tables and their corresponding columns from a database. The code iterates over the entities and columns found and shows them on the console. Minor changes are necessary to process the found values in a different way. Connection conn; DatabaseMetaData dmd; ResultSet rs1, rs2; ResultSetMetaData rsmd; Statement s; try { conn = getConnection(); dmd = conn.getMetaData(); rs1 = dmd.getTables("database_name", null, "%", null); s = conn.createStatement(); while (rs1.

Solution: Netbeans 8 not working on Ubuntu 15.10

Netbeans is one of my beloved day to day applications. Yesterday, when I installed Ubuntu 15.10 (Wily Werewolf) on my computer, Netbeans started to hang on the startup screen, specifically at the Loading Modules phase. It took me hours looking for solutions on the internet; and reinstalling different versions of the Java Development Framework didn’t seem to help. Finally I found the following fix at an Ubuntu forum, which turned out to be very simple to apply.

The Rationale behind the Creation of a Model-View-Controller Framework: Fantastic

Important: This is a work in progress document. The Model-View-Controller is a software pattern frequently used for web development. As its name states, it is composed by three components: A Model or domain representation of a problem. It receives commands, processes them and modifies its state according to the input provided. A View whose main task is to retrieve information from the model and turn it into a useful representation for the user.

Create a connection to MySQL in Java

This time we are going to create a basic connection to MySQL in Java and pull some data from it. // Compile it: // javac Mysql.java // // Try it: // java -classpath mysql-connector-java-5.1.27-bin.jar:. MySQL import java.sql.Connection; import java.sql.DriverManager; import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Statement; import java.util.Properties; public class MySQL { public Connection getConnection() throws SQLException { Connection conn = null; Properties p = new Properties(); p.put("user", "username"); p.put("password", "superpassword"); String cs = "jdbc:mysql://localhost/demo"; conn = DriverManager.