Answer in one word:(one mark for each) I. Which integral type in Java has the exact range from - 2147483648 (-231) to 2147483647 (231-1). II. The software for developing and running Java programs. III. It is similar to machine instructions but is architecture neutral and can run on any platform that has a Java Virtual Machine (JVM).
[3 marks]Write a program that reads an integer and adds all the digits in the integer. For example, if an integer is 932, the sum of all its digits is 14. Hint: Use the % operator to extract digits, and use the / operator to remove the extracted digit. For instance, 932 % 10 = 2 and 932 / 10 = 93.
[4 marks]Analyze following code pieces (assume they are properly enclosed in class and main function) and write the output/error (No justification is required): (one mark for each) I. int num = 5; int x = 1; for (int i = 1; i <= num; i++) { x *= i; } System.out.println("x is " + x); II. int[] nums = {1, 5, 3, 9, 7}; int m= 1; int s= 0; for (int i = 0; i < nums.length; i++) { if (nums[i] > m) { s = m; m = nums[i]; } else if (nums[i] > s && nums[i] != m) { s = nums[i]; } } System.out.println("s is: " + s); P A G III. int i=1,j=0,k=0; if (i > k) { if (j > k) System.out.println("i and j are greater than k"); } else System.out.println("i is less than or equal to k"); IV. int x = 3, y = 3; switch (x + 3) { case 6: y = 1; default: y += 1; } System.out.println("y is " + y); V. class HelloWorld { public static void main(String[] args) { int[] numbers = new int[1]; numbers[0]=0; m(numbers); System.out.println("numbers[0] is" + numbers[0]); } public static void m(int[] y) { y[0] = 3; } } VI. StringBuffer s1 = new StringBuffer("Complete"); s1.setCharAt(1,'i'); s1.setCharAt(7,'d'); System.out.println(s1); VII. int Integer = 24; char String ='I'; System.out.print(Integer); System.out.print(String);
[7 marks]Describe the relationship between an object and its defining class.
[3 marks]Write java statements for following class: public class Counter { int c; } i. Declare a parameterized constructor to initialize variable c. ii. Declare instance method to increment c and return updated value of c.
[4 marks]Justify following: i. In general, constructors should be public. ii. Why main is declared as static. iii. Why we do not declare destructors in java. iv. There is no pointer in java.
[7 marks]Differentiate between following: i. this keyword vs super keyword ii. abstract class vs interface
[7 marks]Give definition of method overloading. P A G
[3 marks]i. Analyze following code pieces and write the output/error and briefly justify output: public class Test { public static void main(String[] args) { new Person().printPerson(); new Student().printPerson(); } } class Student extends Person { @Override public String getInfo() { return "Student"; } } class Person { public String getInfo() { return "Person"; } public void printPerson() { System.out.println(getInfo()); } } ii. Given the following source code, which comment line can be uncommented without introducing errors? abstract class MyClass { abstract void f(); final void g() {} //final void h() {} // comment (1) } final class MyOtherClass extends MyClass { public static void main(String[] args) { MyClass mc = new MyOtherClass(); } void f() {} void h() {} //void g() {} // comment (2) }
[4 marks]Discuss public, private, protected and default access modifiers with examples.
[7 marks]What is the final keyword? Give different uses of the final keyword.
[3 marks]Declare an interface called Function that has a method named evaluate that takes an int parameter and returns an int value. Create a class called Half that implements the Function interface. The implementation of the method evaluate() should return the value obtained by dividing the int argument by 2.
[4 marks]How do keyword throw differ from throws in Exception handling?
[3 marks]Differentiate between a byte oriented and a character- oriented stream.
[4 marks]Explain binary I/Oclasses. Demonstrate java file I/Owith any I/Oclass to read a text file.
[7 marks]Compare JavaFX with Swing and AWT.
[3 marks]i. List any four UI controls in JavaFX. ii. List any two Panes for Containing and Organizing Nodes
[4 marks]Write a program to demonstrate GUI application development using JavaFX.
[7 marks]What are the differences between ArrayList and LinkedList? Which list should you use to insert and delete elements at the beginning of a list?
[3 marks]What is Java Collection Framework? List four collection classes?
[4 marks]Give the name of class or interface that provides following facility (Do not elaborate)(one mark for each) i. Dynamic array to store the duplicate element of different data types. It maintains the insertion order. ii. Implements the last-in-first-out data structure. iii. Implements the first-in-first-out data structure. iv. Implements the first-in-first-out data structure and it holds the elements or objects which are to be processed by their priorities. v. It represents the unordered set of elements which doesn't allow us to store the duplicate items. vi. It is a red-black tree-based implementation. It provides an efficient means of storing key-value pairs in sorted order. vii. It allows us to store key and value pair, where keys should be unique.
[7 marks]Explain thread life cycle.
[3 marks]What is the package? Explain steps to create a package with example.
[4 marks]Declare a class called Employee having employee_Id and employee_Name as members. Extend class Employee to have a subclass called SalariedEmployee having designation and monthly_salary as members. Define following: - Required constructors - Methods to insert, update and display all details of employees. - Method main for creating an array for storing these details given as command line arguments and showing usage of above methods. P A G
What is an Exception? Explain Exception handling in JAVA with the help of example. P A G
[7 marks]