
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Found 7442 Articles for Java

2K+ Views
The stripStart() method of the org.apache.commons.lang.StringUtils class accepts two strings and removes the set of characters represented by the second string from the string of the first string.To remove leading zeros from a string using apache communal library −Add the following dependency to your pom.xml file org.apache.commons commons-lang3 3.9 Get the string.Pass the obtained string as first parameter and a string holding 0 as second parameter to the stripStart() method of the StringUtils class.ExampleThe following Java program reads an integer value from the user into a String and removes the leading zeroes from it using the stripStart() ... Read More

8K+ Views
The replaceAll() method of the String class accepts two strings representing a regular expression and a replacement String and replaces the matched values with given String.Following is the regular expression to match the leading zeros of a string −The ^0+(?!$)";To remove the leading zeros from a string pass this as first parameter and “” as second parameter.ExampleThe following Java program reads an integer value from the user into a String and removes the leading zeroes from it using the Regular expressions. Live Demoimport java.util.Scanner; public class LeadingZeroesRE { public static String removeLeadingZeroes(String str) { String strPattern ... Read More

1K+ Views
The Flexjson library is a lightweight Java library for serializing and de-serializing java beans, maps, arrays, and collections in a JSON format. A JSONSerializer is the main class for performing serialization of Java objects to JSON and by default performs a shallow serialization. We can wrap a JSON object using the rootName() method of JSONSerializer class, this method wraps the resulting JSON in a javascript object that contains a single field named rootName.Syntaxpublic JSONSerializer rootName(String rootName)Exampleimport flexjson.JSONSerializer; public class JSONRootNameTest { public static void main(String[] args) { JSONSerializer serializer = new JSONSerializer().rootName("My_Employee").prettyPrint(true); Employee emp = new Employee("Adithya", "Jai", 28, ... Read More

2K+ Views
The Collections class of java.util package methods that exclusively work on collections these methods provide various additional operations which involves polymorphic algorithms.This class provides different variants of the synchronizedCollection() method as shown below −Sr.NoMethods & Description1static Collection synchronizedCollection(Collection c)This method accepts any collection object and, returns a synchronized (thread-safe) collection backed by the specified collection.2static List synchronizedList(List list)This method accepts an object of the List interfacereturns a synchronized (thread-safe) list backed by the specified list.3static Map synchronizedMap(Map m)This method accepts an object of the Map interface and, returns a synchronized (thread-safe) map backed by the specified map.4static ... Read More

2K+ Views
No, you cannot change the method signature while overriding. Changing the method signature becomes method overloading, not overriding. Now, let's understand why - Method Signature In Java, a method signature consists of - Method name: It is used to call the method. Parameter list: It includes the number, type, and order of parameters. Note: The method signature does not include return type, ... Read More

4K+ Views
Whenever we try to load a class, ClassNotFoundException occurs when the application tries to load a class at runtime using methods like Class.forName() or ClassLoader.loadClass(), but the JVM cannot locate the class in the classpath. The following are the reasons of ClassNotFoundException occurence and they are - Incorrect Class Name Incorrect Package Structure ... Read More

13K+ Views
In Java, both constants and final variables are used to define variables that cannot be changed after initialization. But they have some differences. In this article, we will learn how they are different. Final Variable A final variable in Java means you cannot reassign it after it has been initialized. Whether it is a local variable, instance variable, or static variable, once it's assigned, the value cannot be changed. If you try to do so, a compile-time error will be generated. public class FinalExample { public static void main(String args[]) { ... Read More

3K+ Views
No, you cannot make the elements of an array immutable.But the unmodifiableList() method of the java.util.Collections class accepts an object of the List interface (object of implementing its class) and returns an unmodifiable form of the given object. The user has only read-only access to the obtained list.And the asList() method of the ArrayList class accepts an array and returns a List object.Therefore, to convert an array immutable −Obtain the desired array.Convert it into a list object using the asList() method.Pass the obtained list as a parameter to the unmodifiableList() method.Example Live Demoimport java.util.Arrays; import java.util.Collections; import java.util.List; public class UnmodifiableExample ... Read More

4K+ Views
A JSONArray is a class provided by the org.json package that represents a collection of JSON values. These values can be of any type, such as strings, numbers, booleans, or even nested objects or arrays. If you do not know what JSON is, then you can read the JSON tutorial. Converting JSON Array to String ArrayWe can convert a JSONArray to String Array by using a simple loop as shown in the example below - import org.json.*; import java.util.*; public class JsonArraytoStringArrayTest { public static void main(String[] args) { ... Read More

11K+ Views
JSON is used in Java applications in APIs, file storage, and data communication between systems. Sometimes, we need to convert a list into a JSON array. In this article, we will learn how to convert a list to JSON array using the Jackson library. Jackson Library It is a library that is used in Java to work with JSON data. It provides APIs to serialize Java objects into JSON and deserialize JSON back into Java objects. If you want to read more about the Jackson library, you can refer Jackson library. There are mainly three components of Jackson - ... Read More