0 of 35 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 35 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)
java.util.Collections is a:
Which allows the storage of a null key and null values?
What guarantees type-safety in a collection?
The root interface of Java collection framework hierarchy is –
Which of those is synchronized?
Array List implements that of the following?
nextIndex() and previousIndex() are methods of which interface?
Vector extends that of these?
In Iterator, nextElement() method of Enumeration has been changed to:
From Java five onwards, that one among these is suggested to replace Hashtable?
Which doesn’t permit to store a null value?
What describes an algorithm performs in best, average, or worse case scenarios?
State the search time complexity of an ordered array
Which list class should be most popular in a multi-threading environment, considering performance constraint?
What is the significance of using instanceOf operator and getClass() in equals method?
Can two threads on same ConcurrentHashMap object access it concurrently?
Which interface should be implemented for sorting on basis of many criteria’s?
A EnumSet
Java code:find the average of numbers using array
public class JavaExample { public static void main(String[] args) { double[] arr = {19, 12.89, 16.5, 200, 13.7}; double total = 0; for(int i=0; i<arr.length; i++){ total = total + arr[i]; } /* arr.length returns the number of elements * present in the array */ double average = total / arr.length; /* This is used for displaying the formatted output * if you give %.4f then the output would have 4 digits * after decimal point. */ System.out.format("The average is: %.3f", average); } }
What is the output of the above code?
Let’s say a man deposits 2000 INR in a bank account at an interest rate of 6% per annum for 3 years, calculate the simple interest at the end of 3 years.
JAVA CODE:
import java.util.Scanner; public class JavaExample { public static void main(String args[]) { float p, r, t, sinterest; Scanner scan = new Scanner(System.in); System.out.print("Enter the Principal : "); p = scan.nextFloat(); System.out.print("Enter the Rate of interest : "); r = scan.nextFloat(); System.out.print("Enter the Time period : "); t = scan.nextFloat(); scan.close(); sinterest = (p * r * t) / 100 System.out.print("Simple Interest is: " +sinterest); } }
What is the output of the above code?
What is the output of the code?
public class JavaExample { public static void main(String []args) { String str[] = { "Ajeet", "Steve", "Rick", "Becky", "Mohan"}; String temp; System.out.println("Strings in sorted order:"); for (int j = 0; j < str.length; j++) { for (int i = j + 1; i < str.length; i++) { // comparing adjacent strings if (str[i].compareTo(str[j]) < 0) { temp = str[j]; str[j] = str[i]; str[i] = temp; } } System.out.println(str[j]); } } }
JAVA CODE:
public class Example { public void reverseWordInMyString(String str) { /* The split() method of String class splits * a string in several strings based on the * delimiter passed as an argument to it */ String[] words = str.split(" "); String reversedString = ""; for (int i = 0; i < words.length; i++) { String word = words[i]; String reverseWord = ""; for (int j = word.length()-1; j >= 0; j--) { /* The charAt() function returns the character * at the given position in a string */ reverseWord = reverseWord + word.charAt(j); } reversedString = reversedString + reverseWord + " "; } System.out.println(str); System.out.println(reversedString); } public static void main(String[] args) { Example obj = new Example(); obj.reverseWordInMyString("Welcome to ASIAN TECH HUB"); obj.reverseWordInMyString("This is an easy Java Program"); } }
public class JavaExample { public static void main(String[] args) { int rows = 2, columns = 4; // Declaring the two matrices as multi-dimensional arrays int[][] MatrixA = { {1, 1, 1, 1}, {2, 3, 5, 2} }; int[][] MatrixB = { {2, 3, 4, 5}, {2, 2, 4, -4} }; /* Declaring a matrix sum, that will be the sum of MatrixA * and MatrixB, the sum matrix will have the same rows and * columns as the given matrices. */ int[][] sum = new int[rows][columns]; for(int i = 0; i < rows; i++) { for (int j = 0; j < columns; j++) { sum[i][j] = MatrixA[i][j] + MatrixB[i][j]; } } // Displaying the sum matrix System.out.println("Sum of the given matrices is: "); for(int i = 0; i < rows; i++) { for (int j = 0; j < columns; j++) { System.out.print(sum[i][j] + " "); } System.out.println(); } } }
What is the output of the above code?
public class JavaExample{ public static void main(String args[]){ String str1 = "true"; String str2 = "FALSE"; String str3 = "Something"; boolean bool1=Boolean.parseBoolean(str1); boolean bool2=Boolean.parseBoolean(str2); boolean bool3=Boolean.parseBoolean(str3); System.out.println(bool1); System.out.println(bool2); System.out.println(bool3); } }
What should be the execution order, if a class has a method, static block, instance block, and constructor, as shown below?
JAVA CODE:
public class First_C { public void myMethod() { System.out.println("Method"); } { System.out.println(" Instance Block"); } public void First_C() { System.out.println("Constructor "); } static { System.out.println("static block"); } public static void main(String[] args) { First_C c = new First_C(); c.First_C(); c.myMethod(); } }
What will be the output of the following program?
JAVA CODE:
public class MyFirst { public static void main(String[] args) { MyFirst obj = new MyFirst(n); } static int a = 10; static int n; int b = 5; int c; public MyFirst(int m) { System.out.println(a + ", " + b + ", " + c + ", " + n + ", " + m); } // Instance Block { b = 30; n = 20; } // Static Block static { a = 60; } }
what will be the output of the following code.
JAVA CODE:
Import java.util.map; Import java.util.treemap; Public class treemaptest { Public static void main(string args[]) { Map<Integer,string>m=new treemap<integer,string>(); m.put(11,”audi”); m.put(null,null); m.put(11,”bmw”); m.put(null,”fer”); system.out.println(m.size()); system.out.println(m) } }
what will be the output of the following code.
JAVA CODE:
Import java.util.iterator; Import java.util.map; Import java.util.concurrent.concurrentskiplistmap; Public class concurrentskipmaptest{ Public static void main (string args[]) { Map<intiger,string>concurrentskiplistmap=new concurrentskiplistmap<integer,string>(); Concurrentskiplistmap.put(11,”audi”); Iterator<integer>keyiterator=concurrentskiplistmap.keyset().iterator(); While (keyiterator.hasnext()); Concurrentskiplistmap.put(13,”bmw”); } } }
What will be the output of the following program?
JAVA CODE:
public class Test2 { public static void main(String[] args) { StringBuffer s1 = new StringBuffer("Complete"); s1.setCharAt(1,'i'); s1.setCharAt(7,'d'); System.out.println(s1); } }
What is the result of the following program?
JAVA CODE:
public static synchronized void main(String[] args) throws InterruptedException { Thread f = new Thread(); f.start(); System.out.print("A"); f.wait(1000); System.out.print("B"); }
What will be the output of the below code?
public class ContinueExample { public static void main(String args[]){ for (int j=0; j<=6; j++) { if (j==4) { continue; } System.out.print(j+""); } } }
JAVA CODE:
public class Demo { public static void main(String[] args) { char ch = 'P'; int asciiCode = ch; // type casting char as int int asciiValue = (int)ch; System.out.println("ASCII value of "+ch+" is: " + asciiCode); System.out.println("ASCII value of "+ch+" is: " + asciiValue); } }
JAVA CODE:
package com.beginnersbook.string; public class BooleanToString { public static void main(String[] args) { /* Method 1: using valueOf() method * of String class. */ boolean boovar = true; String str = String.valueOf(boovar); System.out.println("String is: "+str); /* Method 2: using toString() method * of Boolean class */ boolean boovar2 = false; String str2 = Boolean.toString(boovar2); System.out.println("String2 is: "+str2); } }
JAVA CODE:
public class JavaExample{ public static void main(String args[]){ //double value double dnum = 89.891; //creating instance of StringBuffer StringBuffer sb = new StringBuffer(); //appending the double value to StringBuffer instance sb.append(dnum); //converting StringBuffer to String String str = sb.toString(); System.out.println("My String is: "+str); } }
If the average of marks is >= 80 then prints Grade ‘A’ If the average is <80 and >=60 then prints Grade ‘B’ If the average is <60 and >=40 then prints Grade ‘C’ else prints Grade ‘D’
EXAMPLE: a number is the sum of previous two numbers. Starting with 0 and 1 the sequence goes 0, 1, 1, 2, 3, 5, 8, 13, 21.
JAVA CODE:
public class JavaExample { public static void main(String[] args) { int count = 7, num1 = 0, num2 = 1; System.out.print("Fibonacci Series of "+count+" numbers:"); for (int i = 1; i <= count; ++i) { System.out.print(num1+" "); /* On each iteration, we are assigning second number * to the first number and assigning the sum of last two * numbers to the second number */ int sumOfPrevTwo = num1 + num2; num1 = num2; num2 = sumOfPrevTwo; } } }