How-to articles, tricks, and solutions about JAVA

How to sort an ArrayList in Java

To sort an ArrayList in Java, you can use the Collections.sort method.

Java Byte Array to String to Byte Array

To convert a byte array to a string and back to a byte array in Java, you can use the getBytes method of the String class and the getBytes method of the Charset class.

stale element reference: element is not attached to the page document

The "stale element reference" error in Selenium WebDriver occurs when an element that was previously found on the webpage is no longer attached to the DOM (Document Object Model) and is therefore no longer accessible through the browser.

How to set time zone of a java.util.Date?

To set the time zone of a java.util.Date object in Java, you can use the Calendar class.

Main differences between SOAP and RESTful web services in Java

SOAP (Simple Object Access Protocol) and REST (Representational State Transfer) are two different styles of web services that can be used to expose the functionality of a web-based system over the internet.

Declaring an unsigned int in Java

Java does not have an unsigned int data type.

How to check type of variable in Java?

To check the type of a variable in Java, you can use the instanceof operator.

How do you import classes in JSP?

To import classes in a JSP (JavaServer Page) file, you can use the <%@ page import="package.class" %> directive.

How can I get the current stack trace in Java?

To get the current stack trace in Java, you can use the getStackTrace method of the Thread class or the getStackTrace method of the Throwable class.

Add leading zeroes to number in Java?

To add leading zeroes to a number in Java, you can use the format method of the String class, along with a format string that specifies the desired length and padding character.

Differences between Oracle JDK and OpenJDK

The Oracle JDK (Java Development Kit) and the OpenJDK are two implementations of the Java SE (Standard Edition) platform.

How to decompile DEX into Java source code?

To decompile DEX (Dalvik Executable) files into Java source code, you can use a DEX decompiler such as JD-GUI or DEX2JAR.

Eclipse reported "Failed to load JNI shared library"

If you see the error "Failed to load JNI shared library" when starting Eclipse, it means that the Java Native Interface (JNI) library required by Eclipse cannot be found or loaded.

How to remove all white spaces in java

To remove all white spaces from a string in Java, you can use the replaceAll method of the String class, along with a regular expression that matches any white space character (including spaces, tabs, and line breaks):

Extending from two classes

In Java, a class can only extend from one superclass (i.e., it can only have one direct parent class).

When is the @JsonProperty property used and what is it used for?

The @JsonProperty annotation is used to specify the property name in a JSON object when serializing or deserializing a Java object using the Jackson library.

add an element to int [] array in java

To add an element to an array in Java, you can use one of the following methods:

How can I upload files to a server using JSP/Servlet?

To upload files to a server using JSP/Servlet, you can use the following steps:

How to convert String object to Boolean Object?

To convert a String object to a Boolean object in Java, you can use the Boolean.valueOf method:

Class has been compiled by a more recent version of the Java Environment

If you get the error "class has been compiled by a more recent version of the Java Environment", it means that you are trying to run a class file that was compiled with a newer version of Java than the one you have installed.

What exactly is Apache Camel?

Apache Camel is an open-source integration framework that provides a uniform interface for integrating various applications and protocols.

A quick and easy way to join array elements with a separator (the opposite of split) in Java

To join array elements with a separator in Java, you can use the join method from the String class.

Java code for getting current time

To get the current time in Java, you can use the Instant class from the java.time package.

Ignoring new fields on JSON objects using Jackson

If you want to ignore new fields on JSON objects when using Jackson, you can use the @JsonIgnoreProperties annotation on your Java object.