How to initialize an Array in Java in 4 simple ways

This article discusses about array initialization in Java, showing multiple ways to initialize an array, some of them you probably don’t know! Basic Array Initialization in Java Firstly, some background. Java classifies types as primitive types, user-defined types, and array types. An array type is a region of memory that stores values in equal-size and … Read more

Troubleshooting OutOfMemoryError: Direct buffer memory

The java.nio.DirectByteBuffer class is special implementation of java.nio.ByteBuffer that has no byte[] laying underneath. The main feature of DirectByteBuffer is that JVM will try to natively work on allocated memory without any additional buffering so operations performed on it may be faster then those performed on ByteBuffers with arrays lying underneath. We can allocate such … Read more

Simple strategies to test your Java applications with LDAP

LDAP is commonly used in Security realms as a source of authentication and authorization information. This tutorial will teach you two simple strategies for starting an LDAP Server in minutes in order to secure your Enterprise applications. Option 1: Use an Embedded LDAP Server The first example is using an embedded ApacheDS LDAP server with … Read more

How to find out which JAXB implementation is used in your code

When using WildFly or JBoss EAP, the JAXB implementation is defined by the following specification in module.xml: <module name=”javax.xml.bind.api” xmlns=”urn:jboss:module:1.7″> <dependencies> <module name=”javax.activation.api” export=”true”/> <module name=”javax.xml.stream.api”/> <module name=”com.sun.xml.bind” services=”import”/> <module name=”javax.api”/> </dependencies> <resources> <resource-root path=”jboss-jaxb-api_2.3_spec-1.0.1.Final-redhat-1.jar”/> </resources> </module>  In order to check the actual JAXB implementation, you can just create a new Instance of JAXBContext and … Read more

Solving java.lang.OutOfMemoryError: Metaspace error

The java.lang.OutOfMemoryError: Metaspace indicates that the amount of native memory allocated for Java class metadata is exausted. Let’s how this issue can be solved in standalone applications and cloud applications. In Java 8 and later, the maximum amount of memory allocated for Java classes (MaxMetaspaceSize) is by default unlimited, so in most cases there is … Read more

How to solve java.lang.OutOfMemoryError: GC overhead limit exceeded

The error “java.lang.OutOfMemoryError: GC overhead limit exceeded” is fairly common for old JDK (mostly JDK 1.6 and JDK 1.7) . Let’see how to solve it. According to the JDK Troubleshooting guide, the “java.lang.OutOfMemoryError: GC overhead” limit exceeded indicates that the garbage collector is running all the time and Java program is making very slow progress. … Read more

Simplest way to read a File in a String with Java 8

Do you need a quick hack to read a text file into a Java String? With Java 8 this is a piece of cake! See this example: import java.io.IOException; import java.nio.file.Files; import java.nio.file.Paths; public static void main(String[] args) throws IOException { String text = new String(Files.readAllBytes(Paths.get(“myfile.txt”))); } }

Speed up your Java coding with Lombok

We all know that one of the most annoying things in Java is the thing we need to place lots of boiler plate code when building our applications. Think for example of adding Constructors with all fields, getter and setter methods, Logger static methods, not to mention the boilerplate code to use common patterns in … Read more

Getting started with Java-based Machine Learning Libraries

There are over 70 Java-based open source machine learning projects listed on the MLOSS.org website, and probably many more unlisted projects live at university servers, GitHub, or Bitbucket. In this article, we will review the major libraries and platforms, the kind of problems they can solve, the algorithms they support, and the kind of data they can work with. … Read more

Top 5 solutions for Java Http Clients

In this tutorial we will check some of the best solutions if you want to implement an Http Client. You can run the Http Client on the top of WildFly application server or as part of any Java process. First of all, it is worth mentioning that WildFly ships with an embedded Web Server but … Read more