Skip to main content

Posts

Showing posts from 2017

Mock Test: CSE310

PROGRAMMING IN JAVA (CSE310) Time Allowed: 02:00 Hrs                                                                                                    Max. Marks: 50            PART B Q2 a) Write a program to create a class named find_Average which contains a static method named getAverage which accepts a two-dimensional array of size M X N and returns an array of size M containing the largest element in corresponding row of input array.                                                                                                               [10 Marks] Example: Input:   {{1, 6, 3, 8},                                                                             {6, 5, 7, 2},                                        {3, 5, 1, 5}                                   } Output: [8, 7, 5] OR b) (i) What is the difference between LocalDate and LocalDateTime class? What is the use of parse method in these classes? Write code snippet to create a LocalDate object wit

Mocke Test: Exception Handling

1. Differentiate between throw and throws keywords in java using an appropriate program.   2. What is the difference between checked and unchecked exception? What are the different ways of handling checked exceptions in Java? 3. What is the significance of using finally block in exception handling? How it is different from the catch block? Explain the importance of finally with the help of a suitable program. 4.  Write a Program in which prompt the user to enter a String. If the size of String is odd, then throw a User-defined exception InvalidStringException and display "String is Not Accepted". Re-throw the caught exception from catch block to print "Thanks for using this Program". 5. Write a program to define a class named Car with an attribute fuel, and constants mileage and max_fuel. Provide the following methods:        public int addFuel(int ltr) throws FuelTankFullException     public void travel(int km) throws NotSufficientFu

Practice Set: After MTE

1. Write a program to define a class Employee with attributes name, employee_id and salary and also provide a parameterized constructor to initialize all the attributes. Create an appropriate collection to store the Employee objects such that the non-duplicate objects are stored in descending order of their salary. Use Iterator to display the names and salary of all the employees. 2. WAP to create a class Student with attributes name and cgpa. Add at least 5 Student objects in an appropriate collection such that they are sorted in descending order on the basis of their cgpa. Display the names of all the students who are eligible for Verizon placement drive.   (Eligibility: cgpa >=7.5 ) 3. Write a program which prompts the user to enter N integers and store them in an arraylist. Now implement a method which accepts an arraylist containing duplicate values and returns a Collection having unique elements only.                         public Collection removeDupli

Brainstorming: Exception Handling

1. What is the output of this program? class MyException extends Exception {    MyException()      {     super("Exception Occured");      }    public String toString()      {     return "Problem";      } } class Output {    public static void main(String args[])      {     try {         throw new MyException();         }         catch(MyException e)         {         System.out.print(e);         }      } } A) Exception Occured B) MyException: Exception Occured C) Problem D) None of These 2. Identify the incorrect statement among the following. A) throw is used to explicitly throw a user defined exception. B) throws is used to specify that the method can throw exception c) Throwable is an abstract class which is parent of Exception. D) None of the above. 3. What will be the Output of the following Program? public class Test {    public static void main(String[] args)      {     int[] array = new int[2];     for (int i=0; i<2; i++)       {        try{         arra

MTE Practice Set

1. What will be the output of the following code snippet? int x=5, y=1; if(x++>5)    {     if(y<2) System.out.println("Hi");     else   System.out.println("Bye");    } else System.out.println("Oh"); A. Hi    B. Bye    C. Oh    D. Compilation Error Ans: C 2. What will be the output of the following code snippet?    if(!true) System.out.print("Hi ");       if(true) System.out.print("Hello ");       else System.out.println("Bye"); A. Hi Bye   B. Hello   C. Bye    D. Compilation Error         Ans: B 3. Which of the following is INCORRECT header for the main method in java? A. public static void main(String [] arg) B. static public void main(String arg []) C. public static void main(String...arg) D. None of These Ans: D 4. Which of the following is NOT a feature of Java? A. secure    B. platform-dependent    C. robust    D. multi-threaded Ans: B 5. Which of the following Java Edition is dedicated for Web-application developm