Java Programming MCQ (Multiple Choice Questions) - SchoolingAxis

Java Programming MCQ (Multiple Choice Questions)

 Que- How to format date from one form to another?

a. SimpleDateFormat

b. DateFormat

c. SimpleFormat

d. DateConverter


Answer- SimpleDateFormat


Que- How to convert Date object to String?

a.SimpleDateFormat sdf = new SimpleDateFormat("yyyy-mm-dd"); sdf.parse(new Date());

b.SimpleDateFormat sdf = new SimpleDateFormat("yyyy-mm-dd"); sdf.format(new Date());

c.SimpleDateFormat sdf = new SimpleDateFormat("yyyy-mm-dd"); new Date().parse();

d.SimpleDateFormat sdf = new SimpleDateFormat("yyyy-mm-dd"); new Date().format();


Answer-SimpleDateFormat sdf = new SimpleDateFormat("yyyy-mm-dd"); sdf.format(new Date());


Que- How to convert a String to a Date object?

a.SimpleDateFormat sdf = new SimpleDateFormat("yyyy-mm-dd"); sdf.parse(new Date());

b.SimpleDateFormat sdf = new SimpleDateFormat("yyyy-mm-dd"); sdf.format(new Date());

c.SimpleDateFormat sdf = new SimpleDateFormat("yyyy-mm-dd"); new Date().parse();

d.SimpleDateFormat sdf = new SimpleDateFormat("yyyy-mm-dd"); new Date().format();


Answer-SimpleDateFormat sdf = new SimpleDateFormat("yyyy-mm-dd"); sdf.parse(new Date());


Que- How to identify if a timezone is eligible for DayLight Saving?

a. useDaylightTime() of Time class

b. useDaylightTime() of Date class

c. useDaylightTime() of TimeZone class

d. useDaylightTime() of DateTime class


Answer- useDaylightTime() of TimeZone class


Que- What is the replacement of joda time library in java 8?

a. java.time (JSR-310)

b. java.date (JSR-310)

c. java.joda

d. java.jodaTime


Answer- java.time (JSR-310)


Que- How is Date stored in database?

a. java.sql.Date

b. java.util.Date

c. java.sql.DateTime

d. java.util.DateTime


Answer- java.sql.Date


Que- What does LocalTime represent?

a. Date without time

b. Time without Date

c. Date and Time

d. Date and Time with timezone


Answer- Time without Date


Que- How to get difference between two dates?

a. long diffInMilli = java.time.Duration.between(dateTime1, dateTime2).toMillis();

b. long diffInMilli = java.time.difference(dateTime1, dateTime2).toMillis();

c. Date diffInMilli = java.time.Duration.between(dateTime1, dateTime2).toMillis();

d. Time diffInMilli = java.time.Duration.between(dateTime1, dateTime2).toMillis();


Answer- long diffInMilli = java.time.Duration.between(dateTime1, dateTime2).toMillis();


Que- How to get UTC time?

a. Time.getUTC();

b. Date.getUTC();

c. Instant.now();

d. TimeZone.getUTC();


Answer- Instant.now();


Que- Which of these is long data type literal?

a. 0x99fffL

b. ABCDEFG

c. 0x99fffa

d.99671246


Answer- 0x99fffL


Que- Which of these can be returned by the operator &?

a. Integer

b. Boolean

c. Character

d. Integer or Boolean


Answer- Integer or Boolean


Que- Literals in java must be appended by which of these?

a. "L"

b. "l"

c. "D"

d. L and I


Answer- L and I


Que- Literal can be of which of these data types?

a. integer

b. float

c. boolean

d. all of the mentioned


Answer- all of the mentioned


Que- Which of these can not be used for a variable name in Java?

a. identifier

b. keyword

c. identifier & keyword

d. none of the mentioned


Answer- keyword


Que- Which of these is necessary condition for automatic type conversion in Java?

a. The destination type is smaller than source type

b. The destination type is larger than source type

c. The destination type can be larger or smaller than source type

d. None of the mentioned


Answer- The destination type is larger than source type


Que- What is the prototype of the default constructor of this Java class?     public class prototype { }

a. prototype( )

b. prototype(void)

c. public prototype(void)

d. public prototype( )


Answer- public prototype( )


Que- What will be the error in the following Java code?     byte b = 50;     b = b * 50;

a. b cannot contain value 100, limited by its range

b. * operator has converted b * 50 into int, which can not be converted to byte without casting

c. b cannot contain value 50

d. No error in this code


Answer- * operator has converted b * 50 into int, which can not be converted to byte without casting


Que- If an expression contains double, int, float, long, then the whole expression will be promoted into which of these data types?

a.long

b.int

c.double

d.float


Answer-double


Que-What is Truncation is Java?

a.Floating-point value assigned to an integer type

b. Integer value assigned to floating type

c. Floating-point value assigned to an Floating type

d.Integer value assigned to floating type


Answer-Floating-point value assigned to an integer type


Que-Which of these operators is used to allocate memory to array variable in Java?

a.malloc

b.alloc

c.new

d.new malloc


Answer-new

Previous Post Next Post