JavaTM Tutorial Questions

Report 7 Downloads 243 Views
Java Tutorial Questions TM

With over 900 multiple choice questions to reinforce your Java programming skills

S. N. Lam

Copyright S.N. LAM JAVA TUTORIAL QUESTIONS Edited by Grace (Kieu Trang) Tran ISBN

978-0-9920233-0-0

© 2013, S.N. Lam Self publishing ALL RIGHTS RESERVED. This book contains material protected under International and Federal Copyright Laws and Treaties. Any unauthorized reprint or use of this material is prohibited. No part of this book may be reproduced or transmitted in any form or by any means, electronic or mechanical, including photocopying, recording, or by any information storage and retrieval system without express written permission from the author / publisher. Oracle and Java are registered trademarks of Oracle and/or its affiliates. Other names may be trademarks of their respective owners.

Specially dedicated to my wife, Loretta, and my son, Fredrick.

Contents Chapter 1 Java Programming Concepts .................................................................................................... 4 Chapter 2 Flow of Control ...................................................................................................................... 77 Chapter 3 Java API Programming ......................................................................................................... 162 Chapter 4 Multithreading .................................................................................................................... 218 Chapter 5 Object-Oriented Programming ............................................................................................ 253 Chapter 6 Collections........................................................................................................................... 348 Chapter 7 Java Language Fundamentals .............................................................................................. 417 Answer Key ......................................................................................................................................... 488 Answer Key to Chapter 1 ..................................................................................................................... 489 Answer Key to Chapter 2 ..................................................................................................................... 524 Answer Key to Chapter 3 ..................................................................................................................... 567 Answer Key to Chapter 4 ..................................................................................................................... 615 Answer Key to Chapter 5 ..................................................................................................................... 627 Answer Key to Chapter 6 ..................................................................................................................... 654 Answer Key to Chapter 7 ..................................................................................................................... 686

Chapter 1 Java Programming Concepts

Chapter 1 – Java Programming Concepts 1) Identify the legal identifiers from the following.

A) Hello1 B) 10 C) else D) my car E) 2) Which of the following is correct to declare a variable to hold a person's name?

A) int name; B) float name; C) String name; D) char name; E) Object name; 3) How do you invoke the constructor for ClassA?

A) ClassA a = ClassA.ClassA(); B) ClassA a = new ClassA(); C) ClassA a = new; D) ClassA a = ClassA.new(); E) ClassA a = ClassA(); 4) What is the file extension of Java source files?

A) .class B) .java C) .cpp D) .c E) .php 5) Which one of the following is a valid variable name?

A) temp B) 1temp C) tempD) temp num E) temp#1 Chapter 1

© 2013, S.N. Lam

5

Chapter 1 – Java Programming Concepts 6) Which one of the following is a valid class name?

A) ClassA B) class.A C) Class-A D) Class Name E) Class#A 7) Which one of the following is a valid method name?

A) method-1 B) 1method C) method#1 D) method$ E) method one 8) How many classes can be contained within a source file?

A) 1 public class but no limit on the default classes. B) 1 public class and 1 default class only. C) No limit on the number of public and default classes. D) 1 public class but no more than 32 default classes. E) No more than 64 classes altogether. 9) How many interfaces can be contained within a source file?

A) 1 public interface and 1 default interface only. B) No limit on the number of public and default interfaces. C) 1 public interface but no more than 32 default interfaces. D) No more than 64 interfaces altogether. E) Only 1 public interface but no limit on the number of default interface. 10) Which one of the following is a valid variable name?

A) temp#1 B) $temp C) 1temp D) tempE) temp num Chapter 1

© 2013, S.N. Lam

6