JAVA


  A simple tutorial on writing Java native program

Java provides Java Native Interface(JNI) to enable developers to write programs which can utilize the underlying native libraries of the operating system. The benefits of writing native code are that they normally provide better performance compared to Java codes. Sometimes if you want to utilize some system specific functions you may also want to use JNI. One main drawback of writing native code is that your application may not be platform independent anymore. This is not what Java is designed for.Today we will show you a small tutorial on how to write a Java program calling native code....

5,414 0       SAMPLE JAVA NATIVE INTERFACE JNI NATIVE CODE


  Java Cipher encryption/decryption example

In Java, Cipher is the API for doing data encryption/decryption. Many cryptographic algorithms such as AES, DES, RC4 etc can be specified when creating Cipher instance. The Cipher instance calls the underlying algorithm specific implementation to do the actual encryption/decryption. Before doing the encryption/decryption, a key needs to be created and it will be used to do the encryption/decryption. A sample program for performing all these is :import java.security.Key;import javax.crypto.Cipher;import javax.crypto.KeyGenerator;public class CipherSample { public static void main(String[] ...

30,288 1       JAVA EXAMPLE JAVA SECURITY CIPHER SAMPLE


  ByteBuffer in Java

ByteBuffer is introduced in java.nio since Java 1.4. It provides a way of representing raw structured data such as from a file or from network. It enables fast access of underlying data compared to traditional ways like byte[]Prior to Java 1.4, if you want to represent a structured raw data, you need to create a byte[] and then having a set of checks to delimit the byte array to get the expected tokens.There are three ways to create a ByteBuffer:Wrapping an exiting array by calling ByteBuffer.wrap();Creating an empty buffer with capacity by calling ByteBuffer.allocate();Creating an direct empt...

3,241 0       JAVA BYTEBUFFER ALLOCATION


  Generate certificate from cert file in Java

A certificate is often used to prove the identity of a server. The certificate will contain information such as the subject and issuer of the certificate. It will also contain the validation date of the certificate. A certificate is often exported to an external cert file which is transferred over the internet. We will often see its use in SSL communication which provides secure communication between two entities.In this post, we will show how to read the data from an external certificate file and generate a X509 certificate object with the data. This object can then be used to conduct other o...

23,087 2       JAVA EXAMPLE X509 PKCS12 CERTIFICATEFACTORY


  Java Development : Overcomes Challenges of Security, Flexibility, and Performance

While launching any web application, a development company faces a challenge that is choosing the programming language for developing it. Though, there are many options available for companies to deliver app solution to businesses, such as .net, C++, Python, PHP, Ruby, and their derivatives; still many believe that java can be a good choice for development of apps. A java development company can make amazing app solutions by leveraging their development team’s skills and expertise. But the company also faces other challenges that will be discussed further in the post. Fig- Showing m...

7,211 0       JAVA DEVELOPMENT SERVICES


  Arrays.equals() vs MessageDigest.isEqual()

Both Arrays.equals() and MessageDigest.isEqual() are used to compare the equality of two arrays. They can be interchangeably in many cases. However, they do have some differences which lead to different use cases in real applications.One difference is that the arrays passed to MessageDigest.isEqual() cannot be null while it's ok for Arrays.equals().The one major difference between these two methods is that Arrays.equals() is not time-constant while MessageDigest.isEqual() is time-constant. This means that when comparing two arrays, the arrays are compared byte by byte, Arrays.equals() will ret...

19,587 0       JAVA SECURITY ARRAYS.EQUAL() MESSAGEDIGEST.ISEQUAL()


  Recursive class initialization in Java

When a Java class is referenced and initialized, it has to go through the loading and linking first. Once the loading and linking complete successfully. The class will be initialized. The static variables and constant variables will be initialized during this process. Once the class is initialized, it is ready for use.If when class A is initialized and it is referencing a class B, the class B will also get initialized. But what will happen if class B is referencing class A as well? This is called recursive class initialization. Will there be a deadlock if this case happens? No, JVM will take c...

12,852 0       JAVA JVM CLASS INITIALIZATION STATIC FINAL


  Add compiler argument to build Maven project

Maven is a software project to manage a project's build, reporting and documentation from a central piece of information. It's now widely used t build and deploy projects. It can help automatically maintain the dependencies of projects. There is a central project configuration file named pom.xml. Here you can configure the project you want to build. In this post, we will show you how to add compiler argument when using javac to compile Java source code. Sometimes we need to pass compiler arguments when we compile source code, for example, we may want to specify the -source and -targe...

25,702 1       MAVEN COMPILER ARGUMENT COMPILER OPTION JAVA 8