iEntry 10th Anniversary Java Faqs RSS Feed

SCJP java.lang

By: admin - Tuesday, September 9th, 2008 at 10:14 am

QUESTION : 1

     What is the result of attempting to compile and run this ?
         public class Test {
              public static void main(String[] args){
              String s = "HelloWorld".substring(5,10);
              System.out.println(s);
              }
         }

1. The code will fail to compile.
2. Compile and run printing out "orld".
3. Compile and run printing out "oworl"
4. Compile and run printing out "World"
5. Run time exception

ANS : 4

QUESTION : 2

  Select one right answer.
  -----------------------
   What is the result of attempting to compile and run this ?
   1.	public class Test {
   2.     public static void main(String[] args){
   3.      Test t = new Test();
   4.      char c = 4 * 4;
   5.      String s = "bead";
   6.      s = t.pearl(s);
   7.      System.out.println(Byte.parseByte(s,c));
          }
   8.     String pearl(String s){
   9.      return s.substring(0,1);
          }
        }

1. Compiler error caused by line 4.
2. Compiler error caused by line 7.
3. Compiler error caused by line 9.
4. Compiles and throws a NumberFormatException at runtime.
5. Compiles and runs printing out a number.
6. Compiles and runs printing out an alphabet.

ANS : 5
   1. Is wrong because it is legal to assign integer
      literal to a char variable as long as the value
      does not exceed the range of a char.
   2. Is wrong because parseByte(String s , int radix)
      will accept any native numeric type that is not
      wider than an int.
   3  and 6 are just nonsense.
   4. Is wrong because the the character b falls within
      the radix range specified by the second parameter.

QUESTION : 3

   What is the value of d that will be printed out.

    public class Test {
      public final static void main(String[] args)
      {
      double d = - 22.22222;
      System.out.println(Math.ceil(d));
      }
    }

1.  22
2.  22.0
3. -22
4. -23
5. -22.0
6.  23.0

ANS : 5

QUESTION : 4

    What is the result of attempting to compile and run this ? 

    public class Test {
      public static void main(String[] args)
      {
      StringBuffer a =  "Hello";
      StringBuffer b = a.append("World");
      System.out.println(a);
      }
    }

1.  It will print "World"
2.  It will print "HelloWorld"
3.  It will print "Hello World"
4.  The code will not compile.
5.  It will print "Hello"
6.  It will throw a runtime exception

ANS : 4

QUESTION : 5

      Which of the follwing are valid methods of the String class.

1. String append(String s);
2. int length();
3. String toString(String str);
4. String trim();
5. int indexOf(int ch);
6. String append(char c);

ANS : 2,4,5

QUESTION : 6

    What is the result of attempting to compile and run this ? 

    public class Test {
      public static void main(String[] args)
      {
      Float f = new Float(32D);
      System.out.println(f);
      }
    }

1. Does not compile
2. Compiles and runs printing out "32"
3. Compiles and runs printing out "32.0"
4. Compiles but throws an error at runtime

ANS : 3

QUESTION : 7

    What is the result of attempting to compile and run this ? 

         public class Test {

              public static void main(String[] args){
               byte a = 10;
               Byte b    = new Byte(a);
               Byte c    = new Byte(11);
               System.out.println(b.compareTo(c));
              }
         }

1. Compiler error
2. Runtime error
3. Runs and prints "false"
4. Runs and prints "0"
5. Runs and prints "1"
6. Runs adn prints "-1"

ANS : 1

       correct answer/s : 1

QUESTION : 8

    What is the result of attempting to compile and run this ?
         public class Test {

              public static void main(String[] args){
               Float f = new Float(16/0);
               System.out.println(f.isNaN());
              }
         }

1. Compiler error
2. Runtime error
3. Runs and prints "false"
4. Runs and prints "true"

ANS : 2

QUESTION : 9
          What is the result of attempting to compile and run this ? 

         public class Test {

              public static void main(String[] args){
               Number n = new Number(16);
               Float f  = new Float(16);
               System.out.println(n.equals(f));
              }
         }

1. Compiler error
2. Runtime error
3. Runs and prints "false"
4. Runs and prints "true"

ANS : 1

QUESTION : 10

    What is the result of attempting to compile and run this ?
         public class Test {

              public static void main(String[] args){
              Integer i  = new Integer(256);
              System.out.println(i.byteValue());
              }
         }

1. Compiler error
2. Runtime error
3. Runs and prints "256"
4. Runs and prints "0"
5. Runs and prints "127"

ANS : 4

Stumble It!
 Digg!

One Response to “SCJP java.lang”

  1. sureshreddy Says:

    public class Test {
    2. public static void main(String[] args){
    3. Test t = new Test();
    4. char c = 4 * 4;
    5. String s = “bead”;
    6. s = t.pearl(s);
    7. System.out.println(Byte.parseByte(s,c));
    }
    8. String pearl(String s){
    9. return s.substring(0,1);
    }
    }

    how it is possible to assign integer value to char at line 4;
    can u explain what is this pearl();

Leave a Reply