300+ [LATEST] Java.lang Interview Questions and Answers

Q1. What Is The Output Of This Program? 1. Class Output { 2. Public Static Void Main(string Args[]) { 3. Byte A[] = { 65, 66, 67, 68, 69, 70 }; 4.

System.arraycopy() is a method of class System which is used to copy a string into another string.

Output:

$ javac Output.java
$ java Output
ABCDEF ABCDEF

Q2. What Is The Output Of This Program? 1. Class Output { 2. Public Static Void Main(string Args[]) { 3. Byte A[] = { 65, 66, 67, 68, 69, 70 }; 4.

Since last parameter of System.arraycopy(a,1,b,3,0) is 0 nothing is copied from array a to array b, hence b remains as it is.

Q3. Which Of Interface Contains All The Methods Used For Handling Thread Related Operations In Java?

Runnable interface defines all the methods for handling thread operations in Java.

Q4. What Is The Output Of This Program? 1. Class A { 2. Int X; 3. Int Y; 4. Void Display() { 5. System.out.print(x + ” ” +

clone() method of object class is used to generate duplicate copy of the object on which it is called. Copy of obj1 is generated and stored in obj2.

Output:

$ javac Output.java
$ java Output
1 2 1 2

Q5. Which Classes Is Not Included In Java.lang?

Array class is a member of java.util.

Q6. Which Class Is Used To Make A Thread?

Thread class is used to make threads in java, Thread encapsulates a thread of execution. To create a new thread the program will either extend Thread or implement the Runnable interface.

Q7. What Is The Output Of This Program? 1. Class Newthread Implements Runnable { 2. Thread T; 3. Newthread() { 4. T = New Thread(this,”new Thread”);

Thread t has been made with default priority value 5 but in run method the priority has been explicitly changed to MAX_PRIORITY of class thread, that is 10 by code ‘t.setPriority(Thread.MAX_PRIORITY);’ using the setPriority function of thread t.

Output:

$ javac multithreaded_programing.java
$ java multithreaded_programing
Thread[New Thread,10,main]

Q8. Which Method Return A Smallest Whole Number Greater Than Or Equal To Variable X?

double ciel(double X) returns the smallest whole number greater than or equal to variable X.

Q9. What Is The Output Of This Program? 1. Class Output { 2. Public Static Void Main(string Args[]) { 3. Double X = 2.0; 4. Double Y =

Math.pow(x, y) methods returns value of y to the power x, i:e x ^ y, 2.0 ^ 3.0 = 8.0.

Output:

$ javac Output.java
$ java Output
8.0

Q10. What Is The Output Of This Program?

Character.isDigit(a[0]) checks for a[0], whether it is a digit or not, since a[0] i:e ‘a’ is a character false is returned. a[3] is a whitespace hence Character.isWhitespace(a[3]) returns a true. a[2] is an upper case letter i:e ‘A’ hence Character.isUpperCase(a[2]) returns true.

Output:

$ javac Output.java
$ java Output
false true true

Q11. What Is The Output Of This Program? 1. Class Output { 2. Public Static Void Main(string Args[]) { 3. Integer I = New Integer(257); 4.

Output:

$ javac Output.java
$ java Output
257.0

Q12. What Is The Output Of This Program? 1. Class Output { 2. Public Static Void Main(string Args[]) { 3. Byte A[] = { 65, 66, 67, 68, 69, 70 }; 4.

Output:

$ javac Output.java
$ java Output
ABCDEF GCDEFL

Q13. What Is The Output Of This Program? 1. Class Output { 2. Public Static Void Main(string Args[]) { 3. Int X = 3.14; 4. Int Y = (i

Output:

$ javac Output.java
$ java Output
3

Q14. Will This Program Generate Same Output Is Executed Again? 1. Class Output { 2. Public Static Void Main(string Args[]) { 3. Int Y = Double Z = Math.rand

There is no relation between random numbers generated previously in Java.

Q15. What Is The Output Of This Program? 1. Class Isnan_output { 2. Public Static Void Main(string Args[]) { 3. Double D = New Double(1 / 0.); 4.

isisNaN() method returns true is the value being tested is a number. 1/@is infinitely large in magnitude, which cant not be defined as a number hence false is stored in x.

Output:

$ javac isNaN_output.java
$ java isNaN_output
false

Q16. What Is The Output Of This Program? 1. Class Output { 2. Public Static Void Main(string Args[]) { 3. Double X = 3.14; 4. Int Y = (i

3.14 in degree 179.908@We usually take it to be 18@Buts here we have type casted it to integer data type hence 179.

Output:

$ javac Output.java
$ java Output
179

Q17. Which Methods Is Used To Check For Infinitely Large And Small Values?

isinfinite() method returns true is the value being tested is infinitely large or small in magnitude.

Q18. What Is The Output Of This Program? 1. Class Binary { 2. Public Static Void Main(string Args[]) { 3. Int Num = 17; 4. System.out.p

output:

$ javac binary.java
$ java binary
10001

Q19. What Is The Output Of This Program? 1. Class Output { 2. Public Static Void Main(string Args[]) { 3. Integer I = New Integer(257); 4.

i.byteValue() method returns the value of wrapper i as a byte value. i is 257, range of byte is 256 therefore i value exceeds byte range by 1 hence 1 is returned and stored in x.

Output:

$ javac Output.java
$ java Output
1

Q20. What Is The Output Of This Program? 1. Class Newthread Implements Runnable { 2. Thread T; 3. Newthread() { 4. T = New Thread(this,”my Thread”);

Thread t has been made by using Runnable interface, hence it is necessary to use inherited abstract method run() method to specify instructions to be implemented on the thread, since no run() method is used it gives a compilation error.

Output:

$ javac multithreaded_programing.java
The type newthread must implement the inherited abstract method Runnable.run()

Q21. What Is The Output Of This Program? 1. Class A { 2. Int X; 3. Int Y; 4. Void Display() { 5. System.out.print(x + ” ” + Y);

clone() method of object class is used to generate duplicate copy of the object on which it is called. Copy of obj1 is generated and stored in obj2.

Output:

$ javac Output.java
$ java Output
1 2 1 2

Q22. What Is The Output Of This Program? 1. Class Output { 2. Public Static Void Main(string Args[]) { 3. Double X = 3.14; 4. Int Y =

ciel(double X) returns the smallest whole number greater than or equal to variable x.

Output:

$ javac Output.java
$ java Output
4

Q23. What Is The Output Of This Program? 1. Class Newthread Implements Runnable { 2. Thread T1,t2; 3. Newthread() { 4. T1 = New Thread(this,”thread_1

Threads t1 & t2 are created by class newthread that is implementing runnable interface, hence both the threads are provided their own run() method specifying the actions to be taken. When constructor of newthread class is called first the run() method of t1 executes than the run method of t2 printing 2 times “false” as both the threads are not equal one is having different priority than other, hence falsefalse is printed.

Output:

$ javac multithreaded_programing.java
$ java multithreaded_programing
falsefalse

Q24. Which Class Contains Only Floating Point Functions?

Math class contains all the floating point functions that are used for geometry, trigonometry, as well as several general purpose methods. Example : sin(), cos(), exp(), sqrt() etc.

Q25. What Is The Output Of This Program? 1. Class Isinfinite_output { 2. Public Static Void Main(string Args[]) { 3. Double D = New Double(1 / 0.);

isInfinite() method returns true is the value being tested is infinitely large or small in magnitude. 1/@is infinitely large in magnitude hence true is stored in x.

Output:

$ javac isinfinite_output.java
$ java isinfinite_output
true

Q26. Which Class Is Superclass Of All Other Classes?

The object class class is superclass of all other classes.

Q27. Which Method Is A Rounding Function Of Math Class?

max(), min() and abs() are all rounding functions.

Q28. What Is A Super Class Of Wrappers Long, Character & Integer?

Number is an abstract class containing subclasses Double, Float, Byte, Short, Integer and Long.

Q29. Which Class Contains All The Methods Present In Math Class?

SystemMath class defines complete set of mathematical methods that are parallel those in Math class. The difference is that the StrictMath version is guaranteed to generate precisely identical results across all Java implementations.

Q30. Which Method Returns The Remainder Of Dividend / Devisor?

IEEEremainder() returns the remainder of dividend / devisor.

Q31. What Is A Super Class Of Wrappers Double & Integer?

Number is an abstract class containing subclasses Double, Float, Byte, Short, Integer and Long.

Q32. Which Method Return A Largest Whole Number Less Than Or Equal To Variable X?

double floor(double X) returns a largest whole number less than or equal to variable X.

Q33. Toradian() And Todegree() Methods Were Added By Which Version Of Java?

toRadian() and toDegree() methods were added by Java 2.0 before that there was no method which could directly convert degree into radi and vice versa.

Q34. What Is The Output Of This Program? 1. Class Output { 2. Public Static Void Main(string Args[]) { 3. Double X = 102; 4. Double Y = 5;

IEEEremainder() returns the remainder of dividend / devisor. Here dividend is 102 and devisor is 5 therefore remainder is @It is similar to modulus – ‘%’ operator of C/C++ language.

Output:

$ javac Output.java
$ java Output
2

Q35. What Is The Output Of This Program? 1. Class Output { 2. Public Static Void Main(string Args[]) { 3. Long Start, End; 4. Start = S

end time is the time taken by loop to execute it can be any non zero value depending on the System.

Output:

$ javac Output.java
$ java Output
78

Q36. What Is The Output Of This Program? 1. Class Output { 2. Public Static Void Main(string Args[]) { 3. Long I = New Long(256); 4. Sys

Output:

$ javac Output.java
$ java Output
256

Q37. Which Methods Is Used To Obtain Value Of Invoking Object As A Long?

long longValue() is used to obtain value of invoking object as a long.

Q38. What Is The Output Of This Program? 1. Class Output { 2. Public Static Void Main(string Args[]) { 3. Double X = 3.14; 4. Int Y =

double floor(double X) returns a largest whole number less than or equal to variable X. Here the smallest whole number less than 3.14 is 3.

Output:

$ javac Output.java
$ java Output
3