Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
Articles on Trending Technologies
Technical articles with clear explanations and examples
C++ Balanced expression with replacement
A balanced expression of parentheses is an expression that contains pairs of all sort of parentheses together in a correct order.this means that for every opening parentheses there is a closing parentheses in proper order of parentheses i.e. { }.let's take a few examples to understand the concept better −Expression − {([][]{})({}[]{})}Output − balancedExplanation − we can see that for every opening parentheses there is a closing parentheses. all the parentheses lying between an opening parentheses and closing parentheses in Pairs.Output − not balanceExplanation − there are some unordered pairs of parentheses which makes the the expression unbalanced.In this problem ...
Read MoreHow to implement custom serializer using @JsonSerialize annotation in Java?
The @JsonSerialize annotation is used to declare custom serializer during the serialization of a field. We can implement a custom serializer by extending the StdSeralizer class. and need to override the serialize() method of StdSerializer class.Syntax@Target(value={ANNOTATION_TYPE, METHOD, FIELD, TYPE, PARAMETER}) @Retention(value=RUNTIME) public @interface JsonSerializeIn the below program, we can implement a custom serializer using @JsonSerialize annotationExampleimport java.io.*; import com.fasterxml.jackson.core.*; import com.fasterxml.jackson.databind.*; import com.fasterxml.jackson.databind.annotation.*; import com.fasterxml.jackson.databind.ser.std.*; public class JsonSerializeAnnotationTest { public static void main (String[] args) throws JsonProcessingException, IOException { Employee emp = new Employee(115, "Adithya", new String[] {"Java", "Python", "Scala"}); ObjectMapper mapper = new ...
Read MoreHow to convert a JSON string to a bean using JSON-lib API in Java?
The JSON-lib API is a java library to serialize and de-serialize java beans, maps, arrays, and collections in the JSON format. We need to convert a JSON string to a bean by converting a string to JSON object first then convert this to a java bean.Syntaxpublic static Object toBean(JSONObject jsonObject, Class beanClass)In the below program, we can convert a JSON string to a bean.Exampleimport net.sf.json.JSONObject; import net.sf.json.JSONSerializer; public class ConvertJSONStringToBeanTest { public static void main(String[] args) { String jsonStr = "{\"firstName\": \"Adithya\", \"lastName\": \"Sai\", \"age\": 30, \"technology\": \"Java\"}"; JSONObject jsonObj = (JSONObject)JSONSerializer.toJSON(jsonStr); // convert String ...
Read MoreHow can we use @Since annotation using Gson in Java?
The @Since annotation can use with the setVersion() method of the GsonBuilder class. This annotation can apply to a field in java class and accepts float as an argument. This argument represents the version number in which the field has serialized. The same can apply to the deserialization process.Syntax@Documented @Retention(value=RUNTIME) @Target(value={FIELD, TYPE}) public @interface SinceExampleimport com.google.gson.annotations.Since; import com.google.gson.Gson; import com.google.gson.GsonBuilder; public class GsonSinceAnnotationTest { public static void main(String[] args) { Employee emp = new Employee(); emp.setEmployeeName("Raja Ramesh"); emp.setEmployeeId(125); emp.setEmployeeTechnology("Java"); emp.setEmploeeAddress("Hyderabad"); System.out.println("Since version ...
Read MoreHow to combine duplicate values into one with corresponding value separated by hyphens in MySQL?
To combine, use GROUP_CONCAT() function to combine some attributes in two rows into one. As a separator, use hyphens.Let us first create a table −mysql> create table DemoTable1386 -> ( -> Title varchar(255), -> Name varchar(60) -> ); Query OK, 0 rows affected (0.67 sec)Insert some records in the table using insert command −mysql> insert into DemoTable1386 values('Introduction to MySQL', 'Paul DuBois'); Query OK, 1 row affected (0.10 sec) mysql> insert into DemoTable1386 values('Java in Depth', 'Khalid Mughal'); Query OK, 1 row affected (0.48 sec) mysql> insert into DemoTable1386 values('Introduction to MySQL', 'Russell Dyer'); Query OK, ...
Read MoreJava Program to Find the closest pair from two sorted arrays
To find the closest pair from two sorted array, the Java code is as follows −Example Live Demopublic class Demo { void closest_pair(int my_arr_1[], int my_arr_2[], int arr_1_len, int arr_2_len, int sum){ int diff = Integer.MAX_VALUE; int result_l = 0, result_r = 0; int l = 0, r = arr_2_len-1; while (l=0){ if (Math.abs(my_arr_1[l] + my_arr_2[r] - sum) < diff){ result_l = l; result_r = r; ...
Read MoreImplement numbering in MySQL GROUP_CONCAT
Let us first create a table −mysql> create table DemoTable1627 -> ( -> FirstName varchar(20), -> LastName varchar(20) -> ); Query OK, 0 rows affected (0.59 sec)Insert some records in the table using insert command.mysql> insert into DemoTable1627 values('John', 'Smith'); Query OK, 1 row affected (0.11 sec) mysql> insert into DemoTable1627 values('John', 'Doe'); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable1627 values('Adam', 'Smith'); Query OK, 1 row affected (0.18 sec) mysql> insert into DemoTable1627 values('Carol', 'Taylor'); Query OK, 1 row affected (0.08 sec)Display all records from the table using ...
Read MoreJava Program to find reminder of array multiplication divided by n
To find reminder of array multiplication divided by n, the Java code is as follows −Example Live Demoimport java.util.*; import java.lang.*; public class Demo{ public static int remainder(int my_arr[], int arr_len, int val){ int mul_val = 1; for (int i = 0; i < arr_len; i++) mul_val = (mul_val * (my_arr[i] % val)) % val; return mul_val % val; } public static void main(String argc[]){ int[] my_arr = new int []{ 35, 100, 69, 99, 27, 88, 12, 25 }; ...
Read MoreJava program to expand a String if range is given?
To expand a String if range is given, the Java code is as follows −Example Live Demopublic class Demo { public static void expand_range(String word) { StringBuilder my_sb = new StringBuilder(); String[] str_arr = word.split(", "); for (int i = 0; i < str_arr.length; i++){ String[] split_str = str_arr[i].split("-"); if (split_str.length == 2){ int low = Integer.parseInt(split_str[0]); int high = Integer.parseInt(split_str[split_str.length - 1]); while (low
Read MoreJava Program to Count trailing zeroes in factorial of a number
To count trailing zeroes in factorial of a number, the Java code is as follows −Example Live Demoimport java.io.*; public class Demo{ static int trailing_zero(int num){ int count = 0; for (int i = 5; num / i >= 1; i *= 5){ count += num / i; } return count; } public static void main (String[] args){ int num = 1000000; System.out.println("The number of trailing zeroes in " + num +" factorial is " + ...
Read More