Checked Exception: are the exceptions that are checked at compile time. If some code within a method throws a checked exception, then the method must either handle the exception or it must specify the exception using throws keyword.
FileNotFoundException
IOException
ClassNotFoundException
SQLException
DataAccessException
InvocationTargetException
MalformedURLException
Unchecked Exception: Unchecked are the exceptions that are not checked at compiled time.
package com.test.arrays;
public class ThreeElementsSum
{
public static void main(String args[])
{
int sum = ThreeElementsSum.sum3(new int[] {1,2,3});
System.out.println(sum);
}
public static int sum3(int[] nums)
{
return nums[0] + nums[1] + nums[2];
}
}
package com.test.strings;
public class abba
{
public static void main(String args[])
{
System.out.println(abba.makeAbba("Hi","Bye"));
System.out.println(abba.makeAbba("Programs","Buzz"));
}
public static String makeAbba(String a, String b)
{
return(a+b+b+a);
}
}
Modify and return the given map as follows: if the key "a" has a value, set the key "b" to have that value, and set the key "a" to have the value "". Basically "b" is a bully, taking the value and replacing it with the empty string.
Check below code:
package com.test.collections;
import java.util.HashMap;
import java.util.Map;
public class MapBully
{
public static void main(String args[])
{
MapBully mb = new MapBully();
HashMap<String, String> hm = new HashMap<String, String>();
hm.put("a","candy");
hm.put("b","dirt");
System.out.println(mb.mapBully(hm));
}
public Map<String, String> mapBully(HashMap<String, String> map)
{
if(map.containsKey("a"))
{
map.put("b", map.get("a"));
map.put("a", "");
}
return map;
}
}