Wednesday 21 August 2013

Top Most the java.lang Package Interview questions



  1. Wrappper classes :-
·         Wrapper classes are immutable.
·         given,
Float f  = new Float(“Str”);

Str can take values
Str can’t take values
123 or +123 i.e. positive integer(with ‘+’ sign)
1l or 1L i.e. suffixing ‘L’ will cause error.
-2343 i.e. negative integer
0x10 i.e. we cannot give hexadecimal numbers as input.
±1.0 or ±.0d i.e. double number

±.0f i.e. float number

±1.1e5f i.e. we can have ‘e’ in the input string

±1.1e5d i.e. we can have ‘e’ in the input string


·         given ,
Long l = new Long(“Str”);
Str can take values
Str can’t take values
123  i.e. positive integer without ‘+’ sign 
+123 i.e. positive number with ‘+’ sign
-234 i.e. negative integer
0x133 i.e. hexadecimal number

±1.0f i.e. floating point number

±1.0 i.e. double precision number

±.1e1f or ±.1e2d i.e. ‘e’ is not allowed

1l or 1L i.e. suffixing ‘L’ is not allowed

·         Float constructor is overloaded,
Ø  takes a primitive “double number”
Ø  takes a string
Ø  takes a primitive “float number”

·         The equals method when used with wrapper classes gives output as true if
Ø  both input objects are of the same class
Ø  both have the same value
→ Remember if two objects of different class are input to equals method then the output is false and not compiler or runtime error.

·         there isn’t a no argument constructor in any of the wrapper classes.
·         given,
Byte b = new Byte(1);//causes compiler error because 1 → is an integer and Byte constructor takes only byte .similarly for short.


·         given,
Long lg1 = new Long(1);
Long lg2 = new Long(lg1);//causes compiler error because Long constructor doesn’t take in Long object
·         <wrapperClassName>.toString(); is overloaded
Ø  takes a no argument constructor and returns string of the given wrpper object
Ø  (static)takes argument corresponding to the wrapper class i.e.
Integer.toString()  takes int number and Float.toString() takes float number only unlike its constructor
·         wrapper classes ( excluding Character and Boolean) extends Number class and has 6 methods and they are
Ø  byteValue
Ø  shortValue
Ø  intValue
Ø  longValue
Ø  floatValue
Ø  doubleValue
→ there isn’t a “charValue” int the wrapper class(excluding Character).
·         Boolean.valueOf() returns a reference to either Boolean.TRUE or Boolean.FALSE

Boolean b1 = Boolean.valueOf(true);
Boolean b2 = Boolean.valueOf(“TrUe”);

 “b1==b2“ is true.
·         Remember NaN is not equal to Nan.
·         Boolean has two constructors,
Ø  takes boolean values i.e. true or false.
Ø  takes String values i.e given,
Boolean b = new Boolean(“TrUe”);//input string if passes the equalsIgnoreCase method with the string “true” then the new Boolean object will contain value - true.
Ø  given,
Boolean b = new Boolean(<<AnyStringLiteral>>);
for e.g. Boolean b = new Boolean(“santosh”);
            Boolean b1 = new Boolean(null);
            then , b.equals(b1) will be true because b and b1 contain – false .
·         given,
Double a = new Double(Double.NaN);
Double b = new Double(Double.NaN);
then a.equals(b) will be true.
·         Given,
Double c = new Double(0.0);
Double d = new Double(-0.0);
c.equals(d) → gives the output of false.
·         Remember “0.0 == -0.0” is true.

LinkWithin

Related Posts Plugin for WordPress, Blogger...

Labels

Core Java programming core java interview question Core Java Faq's Servlets coding database jsp-servlet spring Java linux unix interview questions java investment bank Web Services Interview investment bank mysql Senior java developer interviews best practices java collection tutorial RMI SQL Eclipse FIX protocol tutorial tibco J2EE groovy java questions SCJP grails java 5 tutorial jdbc beginner error and exception Design Patterns Java Programming Tutorials fundamentals general object oriented programming xml Java Programs Hibernate Examples Flex JAMon Java xml tutorial logging Jsp Struts 2.0 Sybase and SQL Server debugging java interviews performance FIX Protocol interview questions JUnit testing WebSphere date and time tutorial experienced java IO tutorial java concurrency thread Ejb Freshers Papers IT Management Java Exapmle Java Script SQL and database tutorial examples Scwcd ant tutorials concurrency example and tutorial future state homework java changes java threading tricky Agile Business of IT Development JSTL Java JSON tutorial Java multithreading Tutorials PM Scrum data structure and algorithm java puzzles java tips testing tips windows 8 5 way to create Singleton Object Architect Interview Questions and Answers Architecture Architecure Bluetooth server as swing application that searches bluetooth device in 10 meter circle and show all devices. You can send file to any bluetooth device. C Programming CIO Callable Statement in Java Circular dependency of Objects in Java Comparable Example in Collection Custom annotation in Java Developer Interview Divide and rule example in java Drupal Example of Singleton Pattern FIX protocol ForkJoin Example in Java 7 Get data from dynamic table with Java Script Git HTML and JavaScript Health Hello World TCP Client Server Networking Program Hibernate Basics Hibernate Interview Question Answer J2EE Interview Question And Answers J2ME GUI Program JEE Interview QA JMS interview question Java J2EE Hibernate Spring Struts Interview Question Java System Property Java Threads Manager Portlets Provident Fund Read data from any file in same location and give the required result. Reading Properties File in Java Redpoint Rest WebService Client Rest Webservice Test SAL join with ven diagram SCP UNIX COMMAND SSL Singleton Pattern in Java Spring Bean Initialization methods and their order Spring Interview Questions Struts Struts 2.0 Basics Struts 2.0 Design Pattern Submit Html Form With Java Script On The Fly Unix executable For Java Program XOM DOM SAX XP books computers core java; core java; object oriented programming data structure; java investment bank; design pattern dtd duplicate rows in table get browser name with jquery grails podcast inner class java beginners tutorial java cache java networking tutorial java spring java util; java collections; java questions java.java1.5 linked list mailto function with all browser oracle database oracle duplicate rows orm schema social spring mvc questions struts transaction tricks tweet windows xslt