0 of 30 questions completed
Questions:
You have already completed the quiz before. Hence you can not start it again.
Quiz is loading…
You must sign in or sign up to start the quiz.
You must first complete the following:
0 of 30 questions answered correctly
Your time:
Time has elapsed
You have reached 0 of 0 point(s), (0)
Earned Point(s): 0 of 0, (0)
0 Essay(s) Pending (Possible Point(s): 0)
Which Set class should be most popular in a multi-threading environment, considering performance constraint?
The Comparator interface contains the method?
Which of these is the most popularly used class as a key in a HashMap?
Which Map is synchronized?
What Iterator will throw a Concurrent Modification Exception?
What will be the output of the following Java program?
class string_class { public static void main(String args[]) { String obj = "hello"; String obj1 = "world"; String obj2 = "hello"; System.out.println(obj.equals(obj1) + " " + obj.equals(obj2)); } }
Which concept of Java is achieved by combining methods and attribute into a class?
What will be the output of the following Java code?
class multidimention_array { public static void main(String args[]) { int arr[][] = new int[3][]; arr[0] = new int[1]; arr[1] = new int[2]; arr[2] = new int[3]; int sum = 0; for (int i = 0; i < 3; ++i) for (int j = 0; j < i + 1; ++j) arr[i][j] = j + 1; for (int i = 0; i < 3; ++i) for (int j = 0; j < i + 1; ++j) sum + = arr[i][j]; System.out.print(sum); } }
Which of these method returns an instance of DateFormat that can format time information?
What will be the output of the following Java program?
class access { static int x; void increment() { x++; } } class static_use { public static void main(String args[]) { access obj1 = new access(); access obj2 = new access(); obj1.x = 0; obj1.increment(); obj2.increment(); System.out.println(obj1.x + " " + obj2.x); } }
What will be the output of the following Java program?
class exception_handling { public static void main(String args[]) { try { int i, sum; sum = 10; for (i = -1; i < 3 ;++i) sum = (sum / i); } catch(ArithmeticException e) { System.out.print("0"); } System.out.print(sum); } }
Which class provides system independent server-side implementation?
What will be the output of the following Java code?
import java.util.*; public class genericstack <E> { Stack <E> stk = new Stack <E>(); public void push(E obj) { stk.push(obj); } public E pop() { E obj = stk.pop(); return obj; } } class Output { public static void main(String args[]) { genericstack <String> gs = new genericstack<String>(); gs.push("Hello"); System.out.print(gs.pop() + " "); genericstack <Integer> gs = new genericstack<Integer>(); gs.push(36); System.out.println(gs.pop()); } }
Assign value to a enum type
JAVA CODE:
public enum Directions{ EAST, WEST, NORTH, SOUTH } public class EnumDemo { public static void main(String args[]){ Directions dir = Directions.NORTH; if(dir == Directions.EAST) { System.out.println("Direction: East"); } else if(dir == Directions.WEST) { System.out.println("Direction: West"); } else if(dir == Directions.NORTH) { System.out.println("Direction: North"); } else { System.out.println("Direction: South"); } } }
Serialization of Object
JAVA CODE:
import java.io.FileOutputStream; import java.io.ObjectOutputStream; import java.io.IOException; public class SendClass { public static void main(String args[]) { Student obj = new Student(101, 25, "Chaitanya", "Agra", 6); try{ FileOutputStream fos = new FileOutputStream("Student.ser"); ObjectOutputStream oos = new ObjectOutputStream(fos); oos.writeObject(obj); oos.close(); fos.close(); System.out.println("Serialzation Done!!"); }catch(IOException ioe){ System.out.println(ioe); } } }
What will be the output of the following Java code.
JAVA CODE:
class average { public static void main(String args[]) { double num[] = {5.5, 10.1, 11, 12.8, 56.9, 2.5}; double result; result = 0; for (int i = 0; i < 6; ++i) result = result + num[i]; System.out.print(result/6); } }
What will be the output of the following Java code?
JAVA CODE:
class area { int width; int length; int area; void area(int width, int length) { this.width = width; this.length = length; } } class Output { public static void main(String args[]) { area obj = new area(); obj.area(5 , 6); System.out.println(obj.length + " " + obj.width); } }
How to copy the file from one location to other?
What will be the output of the following Java program?
package pkg; class display { int x; void show() { if (x > 1) System.out.print(x + " "); } } class packages { public static void main(String args[]) { display[] arr=new display[3]; for(int i=0;i<3;i++) arr[i]=new display(); arr[0].x = 0; arr[1].x = 1; arr[2].x = 2; for (int i = 0; i < 3; ++i) arr[i].show(); } }
For example, if we consider an application for a fresh juice shop, it would be possible to restrict the glass size to small, medium, and large. This would make sure that it would not allow anyone to order any size other than small, medium, or large.
JAVA CODE:
class FreshJuice { enum FreshJuiceSize { SMALL, MEDIUM, LARGE } FreshJuiceSize size; } public class FreshJuiceTest { public static void main(String args[]) { FreshJuice juice = new FreshJuice(); juice.size = FreshJuice.FreshJuiceSize.MEDIUM ; System.out.println("Size: " + juice.size); } }
This example explains how to access instance variables and methods of a class.
public class Puppy{ int puppyAge; public Puppy(String name) { // This constructor has one parameter, name. System.out.println("Name chosen is :" + name ); } public void setAge( int age ) { puppyAge = age; } public int getAge( ) { System.out.println("Puppy's age is :" + puppyAge ); return puppyAge; } public static void main(String []args) { /* Object creation */ Puppy myPuppy = new Puppy( "tommy" ); /* Call class method to set puppy's age */ myPuppy.setAge( 2 ); /* Call another class method to get puppy's age */ myPuppy.getAge( ); /* You can access instance variable as follows as well */ System.out.println("Variable Value :" + myPuppy.puppyAge ); } }
What will be the output of the following code
Import java.util.EnumMap; Import java.util.map; Public class EnumMapExample{ Public enum days { Monday; }public static void main(string args[]) { Map <days,string>days EnumMap=new daysEnumMap<Days.class); daysEnumMap.put(days.Monday,”Day1”); daysEnumMap.put(days.tuesday,”Day2”); system.out.println(“daysEnumMap.get(days.Monday):”+daysEnummap.get(days.Monday)); system.out.println(“daysEnumMap.containskey(Days.Monday):”+ daysEnummap.containskey(days.Tuesday)); }
JAVA CODE:
Import java.util.list; Import java.util.concurrent.copyOnWriteArrayList; Public class copyOnWriteArrayList { Public static void main (string args[]) { List<string> copyOnWriteArrayList=new copyonWritearraylist<string>(); copyOnWriteArrayList.add(“ind”); copyOnWriteArrayList.add(“usa”); copyOnWriteArrayList.add(“null”); for (string string:copyonwritearraylist) {system.out.print(string+””); copyonwritearraylist.add(“newEle3”); } }
What will be the output of the following Java code?
class A { int i; void display() { System.out.println(i); } } class B extends A { int j; void display() { System.out.println(j); } } class method_overriding { public static void main(String args[]) { B obj = new B(); obj.i=1; obj.j=2; obj.display(); } }
Which of the following are incorrect form of StringBuffer class constructor?
What will be the output of given code:
import java.util.Arrays; import java.util.comparator; class Sorting implements Comparator<Integer> { public int compare(Integer o1, Integer 02) { return 02.compareTo(01); } } public class abc{ public static void main (String...a) { Integer intArray[]={1,2,3}; Arrays.sort(intArray,new Sorting()); for(int i: intArray) { system.out.print(i+""); } } }
import java.util.Arrays; import java.util.Comparator; public class ComparatorTest { public static void main(String args[]) { String[] ar={"c","d","b","a","e"}; Innerclass in=new Innerclass(); Array.parallelSort(ar,in); for(String str : ar) System.out.println(str +""); System.out.println(Arrays.binarySearch(ar, "b")) } Static class Innerclass implements Comparator<String> { public int compare(String S1,String S2) { return s2.compareTo(S1); } } }
What will be the output of the following code?
import java.util.HashMap; import java.util.Map; public class HashMapTest { public static void main(String args[]) { Map<Integer,string hashMap=new HashMap<Integer, String>(); hashMap.put(11,"animesh"); hashMap.put(2,"ayushi"); hashMap.put(7,"renuka"); hashMap.put(9,"shivashish"); system.out.println(hashMap.size()); system.out.println(hashMap); } }
What will be the output of the following Java program?
interface calculate { void cal(int item); } class displayA implements calculate { int x; public void cal(int item) { x = item * item; } } class displayB implements calculate { int x; public void cal(int item) { x = item / item; } } class interfaces { public static void main(String args[]) { displayA arr1 = new displayA; displayB arr2 = new displayB; arr1.x = 0; arr2.x = 0; arr1.cal(2); arr2.cal(2); System.out.print(arr1.x + " " + arr2.x); } }