Assignment 2 Debi
Assignment 2 Debi
CODE:
package Assignment2;
interface Keyboard{
void typing();
}
OUTPUT:
CODE:
package Assignment2;
interface Vehicle{
void name();
}
class Traveller{
public void travellerVehicleName(Vehicle vehicle){
vehicle.name();
}
}
public class Q2 {
public static void main(String[] args) {
Traveller t=new Traveller();
Car c=new Car();
t.travellerVehicleName(c);
}
}
OUTPUT:
CODE:
package Assignment2;
public class Q3 {
public static void main(String[] args) {
try{
int result=10/0;
}catch (ArithmeticException e){
System.out.println("This message for Arithmetic Exception: "+e.getMessage());
}
try{
String str=null;
System.out.println(str.length());
}catch(NullPointerException e){
System.out.println("This message is for NullPointerException: "+e.getMessage());
}
try{
String number="hello";
int parseInteger=Integer.parseInt(number);
}catch(NumberFormatException e){
System.out.println("This message is for NumberFormatException:
"+e.getMessage());
}
try{
int[] arr={10,20,30};
System.out.println(arr[5]);
}catch(ArrayIndexOutOfBoundsException e){
System.out.println("This message is for ArrayIndexOutOfBoundsException:
"+e.getMessage());
}
}
}
OUTPUT:
CODE:
package Assignment2;
import java.util.*;
public class Q4 {
public static void main(String[] args) {
List<Integer> l=new ArrayList<>();
l.add(1);
l.add(2);
l.add(3);
for(int n:l){
System.out.println("List: "+n);
}
OUTPUT:
5. Write a simple Spring Application, which will print "Hello World!" or any other
message based on the configuration done in Spring Beans Configuration file.
CODE:
Message.java
package com.assignments;
Bean.xml
</beans>
App.java
package com.assignments;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import com.assignments.Message;
OUTPUT: