Basic Datatypes


  1. How to convert a String to a Date object?











  1. View Hint View Answer Discuss in Forum

    NA

    Correct Option: D

    SimpleDateFormat takes a string containing pattern. sdf.parse converts the String to Date object.


  1. How to convert Date object to String?











  1. View Hint View Answer Discuss in Forum

    NA

    Correct Option: A

    SimpleDateFormat takes a string containing pattern. sdf.format converts the Date object to String.



  1. How to convert Date object to String?











  1. View Hint View Answer Discuss in Forum

    NA

    Correct Option: A

    SimpleDateFormat takes a string containing pattern. sdf.format converts the Date object to String.


  1. How to format date from one form to another?











  1. View Hint View Answer Discuss in Forum

    NA

    Correct Option: D

    SimpleDateFormat can be used as:


    Date now = new Date();
    SimpleDateFormat date = new SimpleDateFormat ("yyyy-mm-dd'T'hh:MM:ss");
    String nowStr = date.format(now);
    System.out.println("Current Date: " + );



  1. What is the output of below code snippet?

    public class Output
    {
    public static void main(String args[])
    {
    BigDecimal z = new BigDecimal("23.43");
    BigDecimal br = new BigDecimal("24");
    BigDecimal bres = z.add(new BigDecimal("450.23"));
    System.out.println("Add: "+bres);

    MathContext mc = new MathContext(2, RoundingMode.DOWN);
    BigDecimal bdecMath = z.add(new BigDecimal("450.23"), mc);
    System.out.println("Add using MathContext: "+bdecMath);
    }
    }











  1. View Hint View Answer Discuss in Forum

    NA

    Correct Option: C

    add() adds the two numbers, MathContext provides library for carrying out various arithmetic operations.