How-to articles, tricks, and solutions about JAVA
To check if a string contains only digits in Java, you can use the matches() method of the String class in combination with the regular expression "\\d+".
"No X11 DISPLAY variable" is an error message that you might see when trying to run a Java program that uses the X Window System to display a graphical user interface (GUI).
To print quotes in Java, you need to use the escape character \ to indicate that the quote is part of the string and not the end of the string.
To import Maven dependencies in IntelliJ IDEA, you can follow these steps:
To determine the day of the week for a specific date in Java, you can use the get() method of the Calendar class.
To get a specific item from an ArrayList in Java, you can use the get() method of the ArrayList class.
If javac is not working in the Windows command prompt, there could be several reasons for this.
To set the width and height of an ImageView programmatically, you can use the setLayoutParams() method and pass it a LayoutParams object.
To get the string value from a HashMap depending on the key name in Java, you can use the get() method of the Map interface.
To convert a Java 8 Stream to an array, you can use the toArray() method of the Stream interface.
To get the file name from a String containing the absolute file path in Java, you can use the following methods:
There is no SortedList class in the Java standard library because the List interface already provides a way to store elements in a specific order.
Mockito is a Java mocking framework that allows you to create mock objects for testing.
In Java, you can convert a Collection (such as Set, Queue, etc.) to a List using the following methods:
In Java, an int is a primitive data type and cannot be null.
To download a file with Android and show the progress in a ProgressDialog, you can use the following steps:
In Java, you can safely cast a long value to an int by checking to see if the long value is within the range of the int data type.
In Java, you can use the javax.crypto package to perform 256-bit AES (Advanced Encryption Standard) encryption.
If you are seeing an error in Eclipse that says "cannot be resolved to a type," it usually means that Eclipse is unable to find the class or interface that you are trying to use in your code.
To use context in a fragment, you will need to provide enough information within the fragment itself for the reader to understand the context.
To initialize all elements of an array to zero in Java, you can use the Arrays.fill method from the java.util package.
To specify the JDK version that Gradle should use, you can include the org.gradle.java.home property in the gradle.properties file in the root project directory.
To read and write a string from and to a file in Android, you can use the FileInputStream and FileOutputStream classes along with the InputStreamReader and OutputStreamWriter classes.
The LazyInitializationException in Hibernate is thrown when an object that has been loaded with a "lazy" fetch type is accessed outside of a valid session.
In Eclipse, you can use the following keyboard shortcuts to comment and uncomment lines of code: