Top 38 Java.lang Interview Questions You Must Prepare 03.Feb.2023

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

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.

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

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

Array class is a member of java.util.

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.

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]

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

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

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

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

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

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

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

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()

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

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

Output:

$ javac Output.java
$ java Output
4

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

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.

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

The object class class is superclass of all other classes.

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

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

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.

IEEEremainder() returns the remainder of dividend / devisor.

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

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

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.

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

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

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

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