Posts

Showing posts from March, 2020

Jackson – Convert JSON array string to List

Hello everyone, Today we will learn how to convert JSON array String to List JSON array string [ { "name" : "knowledgefactory1" , "salaray" : 1000 }, { "name" : "knowledgefactory2" , "salaray" : 1200 } ] Create an object to map the above JSON fields. package com.knf; public class Employee { String name; Double salaray; public String getName() { return name; } public void setName( String name) { this .name = name; } public Double getSalaray() { return salaray; } public void setSalaray( Double salaray) { this .salaray = salaray; } @ Override public String toString() { return "Employee [name=" + name + ", salaray=" + salaray + "]" ; } } Convert the JSON array string to a List package com.knf; import com.fasterxml.jackson.core.typ

Java Program to find Largest Number in an Array

Hello everyone, Today we will learn how to find the largest number in an array in java by sorting the array and returning the largest number.  Let's see the full example to find the largest number in the java array. Example 1: package com.knf; public class LargestInArrayExample1 { public static void main( String args[]) { int a[] = { 2 , 1 , 2 , 5 , 6 , 3 , 2 , 9 }; int b[] = { 144 , 666 , 99 , 677 , 433 , 422 , 255 }; System.out.println( "Largest: " + getLargest(a)); System.out.println( "Largest: " + getLargest(b)); } public static int getLargest( int [] a) { int temp; for ( int i = 0 ; i < a.length; i++) { for ( int j = i + 1 ; j < a.length; j++) { if (a[i] > a[j]) { temp = a[i]; a[i] = a[j]; a[j] = temp; } } } return a[a.length - 1 ];

Java - Generics

In any nontrivial software project, bugs are simply a fact of life. Careful planning, programming, and testing can help reduce their pervasiveness, but somehow, somewhere, they'll always find a way to creep into your code. This becomes especially apparent as new features are introduced and your code base grows in size and complexity. Fortunately, some bugs are easier to detect than others. Compile-time bugs, for example, can be detected early on; you can use the compiler's error messages to figure out what the problem is and fix it, right then and there. Runtime bugs, however, can be much more problematic; they don't always surface immediately, and when they do, it may be at a point in the program that is far removed from the actual cause of the problem. Generics add stability to your code by making more of your bugs detectable at compile time. Generic Methods You can write a single generic method declaration that can be called with arguments of different types. Based