How-to articles, tricks, and solutions about JAVA

Returning Arrays in Java

To return an array in Java, you can simply specify the array type as the return type of the method.

Can I add jars to Maven 2 build classpath without installing them?

Yes, you can add jars to the Maven build classpath without installing them.

Accept server's self-signed ssl certificate in Java client

To accept a server's self-signed SSL certificate in a Java client, you can create a custom javax.net.ssl.X509TrustManager and use it to override the default trust manager.

Java: Get month Integer from Date

To get the month integer from a java.util.Date object in Java, you can use the getMonth() method of the java.util.Calendar class.

Parsing JSON Object in Java

To parse a JSON object in Java, you can use the org.json library.

Hibernate throws MultipleBagFetchException - cannot simultaneously fetch multiple bags

If you are using Hibernate and you see the error "MultipleBagFetchException: cannot simultaneously fetch multiple bags", it means that you are trying to fetch multiple collections of an entity using a single Hibernate query.

What are all the different ways to create an object in Java?

In Java, you can create an object in the following ways:

Does java.util.List.isEmpty() check if the list itself is null?

No, the isEmpty() method of the java.util.List interface does not check if the list itself is null.

How to calculate the running time of my program?

To calculate the running time of a program in Java, you can use the System.currentTimeMillis() method to get the current time in milliseconds before and after the program runs.

accessing a variable from another class

To access a variable from another class in Java, you can use the following steps:

How to perform mouseover function in Selenium WebDriver using Java?

To perform a mouseover (hover) action in Selenium WebDriver using Java, you can use the Actions class.

Java 11 package javax.xml.bind does not exist

If you are seeing the error "package javax.xml.bind does not exist" in your Java 11 project, it means that the Java XML Bind (JAXB) API is not included in the classpath.

Initializing multiple variables to the same value in Java

In Java, you can initialize multiple variables to the same value in a single statement by separating the variables with a comma.

Can an int be null in Java?

No, an int data type in Java cannot be null.

No Persistence provider for EntityManager named

If you are seeing the error "No Persistence provider for EntityManager named [persistence-unit-name]" in your Java application, it means that the persistence provider (e.g.

How to switch to the new browser window, which opens after click on the button?

To switch to a new browser window in Selenium, you can use the switchTo() method with the WindowHandle of the new window.

How to put a Scanner input into an array... for example a couple of numbers

To put input from a Scanner into an array in Java, you can use a loop to read the input and store it in the array.

A KeyValuePair in Java

In Java, a KeyValuePair is a data structure that represents a pair of keys and values, similar to a Map.

intellij incorrectly saying no beans of type found for autowired repository

If IntelliJ is saying "No beans of type 'X' found for autowiring" for a repository that you are trying to autowire, it means that the Spring application context does not contain a bean of the specified type.

Add context path to Spring Boot application

To add a context path to a Spring Boot application, you can use the server.context-path property in the application's application.properties file.

Reading Properties file in Java

To read a properties file in Java, you can use the Properties class from the java.util package.

Parsing JSON string in Java

To parse a JSON string in Java, you can use the JSONObject class from the org.json package.

Java Error: "Your security settings have blocked a local application from running"

If you are getting the error "Your security settings have blocked a local application from running" when trying to run a Java application, it means that your security settings are preventing the application from running.

How to select a dropdown value in Selenium WebDriver using Java

To select a dropdown value in Selenium WebDriver using Java, you can use the selectByValue or selectByVisibleText methods of the Select class.