Object Oriented Programming Articles

Page 167 of 588

Differences between org.simple.json and org.json libraries in Java?

Manisha Chand
Manisha Chand
Updated on 20-May-2025 3K+ Views

In Java, org.simple.json and org.json are two libraries that help in reading, writing, and manipulating JSON. But still, they are different. In this article, we are going to learn about these differences. Difference between JSON.simple vs JSON Let's see the below differences and they are - Features JSON.simple JSON ...

Read More

Why String literal is stored in String Constant Pool in Java?

Shriansh Kumar
Shriansh Kumar
Updated on 19-May-2025 2K+ Views

In Java, the string literals (or, string objects) are stored in a separate memory area called string constant pool to improve the performance of string operations and optimize the memory while using them. Let's understand how. Creating String Objects in Java There are two ways to create a String object in Java: Using the new operator Using String literal Example The example given below shows how to create a string object: public class Example { public static void main(String[] args) { ...

Read More

When to use @JsonValue annotation using Jackson in Java?\\n

Manisha Chand
Manisha Chand
Updated on 19-May-2025 6K+ Views

In Java, Jackson is a library that is used to convert JSON to Java objects and vice versa. Jackson Annotations are used during serialization and deserialization. We use these to denote or specify annotations before a particular field or method (that is declared in Java). Using an annotation before a field, we can denote whether it is a variable, is a JsonProperty, should be ignored, or what condition should be applied to it. So basically, Annotations make JSON output clearer as we required. In this Article, we will learn about ...

Read More

How to convert a JSON to Java Object using the Jackson library in Java?

Manisha Chand
Manisha Chand
Updated on 19-May-2025 42K+ Views

Jackson is a Java library that is used to convert JSON to Java objects and vice versa. Conversion of JSON to a Java object is called deserialization, and Java object to JSON is known as serialization. Both of these tasks can be done by using the Jackson library. In this article, we are going to learn how to convert JSON to Java objects using the Jackson library. Jackson Library: Convert a JSON to a Java Object The ObjectMapper class belongs to the Jackson library. This class is responsible for the serialization and deserialization of Java objects. The ObjectMapper class is used ...

Read More

How to get the first element of the List in Java?

Vivek Verma
Vivek Verma
Updated on 19-May-2025 22K+ Views

A list stores a sequence of elements of a similar type. Like an array, the elements in a List are stored at specific indices, starting from index 0. The 0th index indicates the "first element", the 1st indicates the "second" element, and so on. In Java, a list is represented by the interface named List (with the same name) that extends the Collection interface. To create a List object, we can instantiate any class that implements the List interface, such as ArrayList, Stack, Vector, etc (Since we cannot instantiate an interface). We can get the first element of the List in ...

Read More

How to find an element in a List with Java?

Vivek Verma
Vivek Verma
Updated on 16-May-2025 24K+ Views

In Java, a List is an interface that extends the Collection interface and represents a sequence of elements. Since the List is an interface. To create a List object, we need to instantiate a class that implements the List interface, such as ArrayList.  The List provides various methods that help to check or find the element in it. We will discuss those methods in the coming section with suitable examples. Below is a list of various ways to find an element in the Java List: Using the get() Method Using ...

Read More

What are the different steps involved to execute a Java program?

Shriansh Kumar
Shriansh Kumar
Updated on 16-May-2025 3K+ Views

Java is an object-oriented programming language that provides various features like platform independence, security, garbage collection, etc. Unlike other programming languages, programs written in Java go through a specific sequence of steps during the compilation and execution process. Java follows the same process no matter where and how you compile and execute Java programs, whether using an IDE or the Command Prompt. In this article, we will discuss and understand the steps Java follows to execute programs. Compilation and Execution Process of Java Program Java program execution follows 5 major steps, which are as follows: Step 1: Edit or ...

Read More

What are the differences between ClassNotFoundException and NoClassDefFoundError in Java?\\n

Shriansh Kumar
Shriansh Kumar
Updated on 16-May-2025 5K+ Views

In Java, both ClassNotFoundException and NoClassDefFoundError are issues that occur when the JVM or ClassLoader is not able to find the appropriate class at the time of loading (run-time). The ClassNotFoundException is a checked exception, and NoClassDefFoundError is an Error that comes under unchecked. There are different types of ClassLoaders, each responsible for loading classes from different sources such as directories, JAR files, or network locations. If a required class is missing due to an incorrect classpath or a missing JAR file, the ClassLoader might fail to load it. This situation leads to one of these two issues. The ClassNotFoundException in ...

Read More

Can we write any code after throw statement in Java?

Shriansh Kumar
Shriansh Kumar
Updated on 16-May-2025 2K+ Views

No, we can not place any code after throw statement, it leads to compile time error. The compiler will show this error as unreachable statement. In Java, the throw statement immediately terminates the current flow of execution, therefore, the code immediate to a throw statement will not be executed. The control is then transferred to the next catch block or the caller method. The throw Keyword in Java The throw keyword is used to throw an exception manually. Whenever it is required to stop the execution of the functionality based on the user-defined logical error condition, we will use this ...

Read More

Is it possible to create a class without a name in Java?

Shriansh Kumar
Shriansh Kumar
Updated on 16-May-2025 1K+ Views

Yes, we can create a class without a name in Java using the anonymous class. It is a type of inner class which does not have a name and whose instance is created at the time of the creation of the class itself. You can create this class in a single statement using the new keyword. Creating multiple instances of this class is not allowed. You can use anonymous classes in case where you need to override methods of a class or an interface for a one-time use, and you don't want to create a separate named class for it. ...

Read More
Showing 1661–1670 of 5,878 articles
« Prev 1 165 166 167 168 169 588 Next »
Advertisements