The package java.lang contains classes and interfaces that are essential to the Java language. These include: Object, Thread, Throwable, Classes that encapsulate primitive data types in Java, Classes for accessing system resources and other low-level entities, Math, String. You can refer to all of the classes and interfaces in java.lang using their simple names. The java.lang.refs and java.lang.reflect packages provide, respectively, reference-object classes. One can check the availability of the job across cities including Mumbai, Delhi, Bangalore, Pune and Hyderabad. Java.lang role consists of high knowledge and proficient. Wisdomjobs has interview questions which are exclusively designed for job seekers to assist them in clearing job interviews. Java.lang interview questions are useful for developers to attend job interviews and get selected for job.
Question 1. Which Classes Is Not Included In Java.lang?
Answer :
Array class is a member of java.util.
Question 2. What Is A Super Class Of Wrappers Double & Integer?
Answer :
Number is an abstract class containing subclasses Double, Float, Byte, Short, Integer and Long.
Question 3. Which Methods Is Used To Check For Infinitely Large And Small Values?
Answer :
isinfinite() method returns true is the value being tested is infinitely large or small in magnitude.
Answer :
isInfinite() method returns true is the value being tested is infinitely large or small in magnitude. 1/0. is infinitely large in magnitude hence true is stored in x.
Output:
$ javac isinfinite_output.java
$ java isinfinite_output
true
Answer :
isisNaN() method returns true is the value being tested is a number. 1/0. 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
Answer :
output:
$ javac binary.java
$ java binary
10001
Question 7. What Is A Super Class Of Wrappers Long, Character & Integer?
Answer :
Number is an abstract class containing subclasses Double, Float, Byte, Short, Integer and Long.
Question 8. Which Methods Is Used To Obtain Value Of Invoking Object As A Long?
Answer :
long longValue() is used to obtain value of invoking object as a long.
Answer :
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
Answer :
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
Answer :
Output:
$ javac Output.java
$ java Output
257.0
Answer :
Output:
$ javac Output.java
$ java Output
256
Question 13. Which Class Have Only One Field ‘type’?
Answer :
The Void class has one field, TYPE, which holds a reference to the Class object for the type void.
Question 14. Standard Output Variable ‘out’ Is Defined In Which Class?
Answer :
Standard output variable ‘out’ is defined in System class. out is usually used in print statement i:e System.out.print().
Answer :
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
Answer :
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
Answer :
Output:
$ javac Output.java
$ java Output
ABCDEF GCDEFL
Answer :
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.
Question 19. Which Class Is Superclass Of All Other Classes?
Answer :
The object class class is superclass of all other classes.
Question 20. Which Method Is A Rounding Function Of Math Class?
Answer :
max(), min() and abs() are all rounding functions.
Question 21. Which Class Contains Only Floating Point Functions?
Answer :
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.
Answer :
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
Answer :
Output:
$ javac Output.java
$ java Output
3
Answer :
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
Question 25. Which Method Return A Smallest Whole Number Greater Than Or Equal To Variable X?
Answer :
double ciel(double X) returns the smallest whole number greater than or equal to variable X.
Question 26. Which Method Return A Largest Whole Number Less Than Or Equal To Variable X?
Answer :
double floor(double X) returns a largest whole number less than or equal to variable X.
Answer :
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
Answer :
ciel(double X) returns the smallest whole number greater than or equal to variable x.
Output:
$ javac Output.java
$ java Output
4
Answer :
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
Question 30. Which Class Contains All The Methods Present In Math Class?
Answer :
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.
Question 31. Which Method Returns The Remainder Of Dividend / Devisor?
Answer :
IEEEremainder() returns the remainder of dividend / devisor.
Question 32. Toradian() And Todegree() Methods Were Added By Which Version Of Java?
Answer :
toRadian() and toDegree() methods were added by Java 2.0 before that there was no method which could directly convert degree into radians and vice versa.
Answer :
3.14 in degree 179.9087. We usually take it to be 180. Buts here we have type casted it to integer data type hence 179.
Output:
$ javac Output.java
$ java Output
179
Answer :
IEEEremainder() returns the remainder of dividend / devisor. Here dividend is 102 and devisor is 5 therefore remainder is 2. It is similar to modulus – ‘%’ operator of C/C++ language.
Output:
$ javac Output.java
$ java Output
2
Answer :
There is no relation between random numbers generated previously in Java.
Answer :
Runnable interface defines all the methods for handling thread operations in Java.
Question 37. Which Class Is Used To Make A Thread?
Answer :
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.
Answer :
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
Answer :
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]
Answer :
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()
java.lang Related Tutorials |
|
---|---|
Adv Java Tutorial | J2EE Tutorial |
Core Java Tutorial | JSP Tutorial |
Java-Springs Tutorial | Java Tutorial |
Java 8 Tutorial |
All rights reserved © 2020 Wisdom IT Services India Pvt. Ltd
Wisdomjobs.com is one of the best job search sites in India.