C++ Program to Check Leap Year

Nishu Kumari
Updated on 13-May-2025 17:07:56

14K+ Views

A leap year contains one additional day, i.e february 29, to keep the calendar year synchronized with the earth's orbit around the sun. We will write a C++ program that checks whether a given year is a leap year or not. A year that is divisible by 4 is known as a leap year. However, years divisible by 100 are not leap years while those divisible by 400 are. Here is a list of some leap years and non-leap years: ... Read More

C++ Program to Generate Multiplication Table

Nishu Kumari
Updated on 13-May-2025 17:06:55

5K+ Views

In this article, we will show you how to write a C++ program to generate the multiplication table of a number. A multiplication table shows how a number is multiplied by 1 to 10 and helps define the multiplication operation for that number. Each row displays the result of multiplying the number by values from 1 to 10. For example, the multiplication table of 4 looks like this: 4 * 1 = 4 4 * 2 = 8 4 * 3 = 12 4 * 4 = 16 4 * 5 ... Read More

C++ Program to Display Factors of a Number

Nishu Kumari
Updated on 13-May-2025 17:04:52

12K+ Views

A factor is a number that divides a given number completely without leaving a remainder. In this article, we'll show you how to display all the factors of a number using different methods in C++. For example, the factors of 12 are 1, 2, 3, 4, 6, and 12. In this article, we will look at two ways to find and display the factors of a number: Basic Iterative Approach Optimized Square Root Approach Factors of a Number Using Iterative (Basic) Approach In this approach, we use loop to go ... Read More

Check Whether a Number is Prime in C++

Nishu Kumari
Updated on 13-May-2025 16:59:42

4K+ Views

A prime number is a whole number greater than one and the only factors of a prime number should be one and itself. For example, 2, 3, 5, 7, and 11 are prime numbers. Our task is to write a C++ program that checks if a given number is prime or not. We will cover different approaches to solve this problem. We'll cover the following methods for checking whether a number is prime or not: Using a Simple Loop Using the Square Root Method Using ... Read More

C++ Program to Convert Decimal Number to Binary

Nishu Kumari
Updated on 13-May-2025 16:58:31

5K+ Views

In a computer system, the binary number is expressed in the binary numeral system while the decimal number is in the decimal numeral system. The binary number is in base 2 while the decimal number is in base 10. Examples of decimal numbers and their corresponding binary numbers are as follows: Decimal Number ... Read More

Serialize Null Field Using Gson Library in Java

Aishwarya Naglot
Updated on 13-May-2025 16:41:06

8K+ Views

Gson is a library in the Java that is mainly used for converting Java objects to JSON and vice versa. By default, the Gson object does not serialize the fields with null values to JSON. If a field in a Java object is null, Gson excludes it.Serializing a Null Field Using Gson We can force Gson to serialize null values via the GsonBuilder class. We need to call the serializeNulls() method on the GsonBuilder instance before creating the Gson object. Once serializeNulls() has been called, the Gson instance created by the GsonBuilder can include null fields in the serialized JSON. ... Read More

Deserialize JSON into an Existing Object in Java

Aishwarya Naglot
Updated on 13-May-2025 16:33:52

3K+ Views

Deserialization is the process of converting a JSON string into a Java object. In this example, we will learn how to deserialize a JSON string into an existing object in Java. There are libraries available in Java that can help us to deserialize a JSON string into an existing object. Some of the popular libraries are: Using Gson Using Jackson Using Flexjson Let's learn how to use each of these libraries to deserialize a JSON string into an existing object in Java. Deserializing JSON Object Using ... Read More

Serialize Array of Objects Using Flexjson in Java

Aishwarya Naglot
Updated on 13-May-2025 16:28:51

452 Views

Serialization is the process where we convert an object into a format that can be easily stored or transmitted and later reconstructed. The given task is to serialize an array of objects using Flexjson in Java. Serializing an Array of Objects Using Flexjson Flexjson is a lightweight Java library for serializing and deserializing java beans, maps, arrays, and collections in JSON format. We can also deserialize a JSON string to an existing object using the deserializeInto() method of the JSONDeserializer class, this method deserializes the given input into the existing object target. The values in the JSON input can overwrite ... Read More

Differences Between fromJson and toJson Methods of Gson in Java

Aishwarya Naglot
Updated on 13-May-2025 16:23:07

5K+ Views

Gson is a Java library which is developed by Google and used to convert Java objects into JSON and vice versa. It is mostly used in applications where data can be exchanged in JSON format. There are two useful methods in Gson that we are going to discuss in this article. These methods are fromJson() and toJson(). The fromJson() Method The fromJson() method is used to convert a JSON string into a Java object. It takes two parameters: the JSON string and the class type of the object you want to create. Here is the syntax of the fromJson() method: ... Read More

Serialize a Map Using the Flexjson Library in Java

Aishwarya Naglot
Updated on 13-May-2025 15:54:20

382 Views

Serializing a Map in Java is the process of converting a Map object into a format that can be easily stored or transmitted, such as JSON or XML. We will use the Flexjson library to serialize a map in Java. We can serialize a Map using the serialize() method of the JSONSerializer class, which performs a shallow serialization of the target instance. Example of Serializing a Map We will take a map and see the output after serialization. Map map = new HashMap(); map.put("name", "Ansh"); map.put("age", "23"); map.put("city", "Mumbai"); map.put("country", "India"); After serialization, the map will look like this: {"name":"Ansh", ... Read More

Advertisements