, TESTBANK FOR Java Software Solutions,
Foundations of Program Design, 10th edition Lewis
Notes
1- The file is chapter after chapter.
2- We have shown you few pages sample.
3- The file contains all Appendix and Excel sheet
if it exists.
4- We have all what you need, we make update
at every time. There are many new editions
waiting you.
5- If you think you purchased the wrong file You
can contact us at every time, we can replace it
with true one.
Our email:
,Java Software Solutions, 10e (Lewis/Loftus)
Chapter 1 Introduction
TRUE/FALSE
1. All information is stored in the computer using binary numbers.
ANS: T
The computer is a digital device meaning that it stores information in one of two states using binary.
We must determine then how to represent meaningful information (such as a name or a program in-
struction or an image) in binary.
2. Java is an object-oriented programming language.
ANS: T
Java is classified as a high-level programming language but it is also classified as an object-oriented
programming language because it allows the programmer to implement data structures as classes.
3. System.out.print is used in a program to denote that a documentation comment follows.
ANS: F
Documentation comments follow // marks or are embedded between */ and */. Sys-
tem.out.print is an instruction used to output a message to the screen (the Java console window).
4. Java byte codes are directly executable whereas Java source code is not.
ANS: F
Neither Java source code nor Java byte codes are executable. Both must be compiled or interpreted
into machine code. Java byte codes are useful however in that they are machine-independent but
semi-compiled code that allows your Java code to be transmitted over the Internet and executed on
another computer even if that other computer is a completely different type.
5. The Java compiler is able to find all programmer errors.
ANS: F
The Java compiler can find syntax errors but cannot find either logical errors (errors that are caused
because of poor logic in writing the program) or run-time errors (errors that arise during the execution
of the program).
6. Java is a case-sensitive language which means Current, CURRENT, and current will all reference
the same identifier.
ANS: F
Java is case sensitive which means that Current, CURRENT, and current will all be recognized
as different identifiers. This causes problems with careless programmers who do not spell an iden-
tifier consistently in terms of upper and lower case characters.
, 7. Code placed inside of comments will not be compiled and, therefore, will not execute.
ANS: T
The compiler discards comments; therefore, any code inside a comment is discarded and is not com-
piled. Your executable program consists only of the code that is compiled.
8. The word Public is a reserved word.
ANS: F
public is a reserved word, but since Java is case sensitive, Public differs from public and there-
fore Public is not a reserved word.
9. Reserved words in Java can be redefined by the programmer to mean something other than their
original intentions.
ANS: F
Java reserved words cannot be redefined.
10. In a Java program, dividing by zero is a syntax error.
ANS: F
Dividing by 0 is not detected at compile time, and because a computer cannot divide by 0, this is a run-
time error.
11. In a Java program, dividing by zero is a syntax error.
ANS: F
Dividing by 0 is not detected at compile time, and because a computer cannot divide by 0, this is a run-
time error.
12. During translation, the compiler puts its output (the compiled Java program) into ROM.
ANS: F
ROM stands for read-only-memory. The compiled output (the byte codes) may be placed into RAM
(writable random access memory) or into a file (on your hard drive, for example).
13. Objects are defined by a class that describes the characteristics common to all instances of the class.
ANS: T
An object is an instance of a class. And, the purpose of a class is to describe these common charac-
teristics.
14. Inheritance is a form of software reuse.
ANS: T
, Inheritance allows us to capitalize on the similarities among various kinds of classes that have a com-
mon base (parent) class. Thus we reuse the base class each time a class inherits from it.
15. Polymorphism is the idea that we can refer to multiple types of related objects in consistent ways.
ANS: T
Polymorphism allows us to use the same name for similar behaviors that occur among diverse and pos-
sibly unrelated objects. For example, to "open" may refer to a file, or to a device, or to a communi-
cations line, etc. The same term, "open," is being used even though the objects that are being opened
are quite different.
16. In Java, identifiers may be of any length up to a limit determined by the compiler.
ANS: F
Java (and Java compilers) do not limit the length of the identifiers you use. Identifiers may be as
long as you wish. Good programming practice, however, will limit the lengths of the identifiers you
create.
MULTIPLE CHOICE
1. A Java program is best classified as
a. hardware
b. software
c. storage
d. processor
e. input
ANS: B
Programs are classified as software to differentiate them from the mechanisms of the computer (hard-
ware). Storage and the processor are two forms of hardware while input is the information that the
program processes.
2. Six bits can be used to represent __________ distinct items or values.
a. 6
b. 20
c. 24
d. 32
e. 64
ANS: E
With n bits, we can represent 2^n different values. 2^6 = 64.
3. When executing a program, the processor reads each program instruction from
a. secondary memory (storage)
b. the Internet
c. registers stored in the processor
d. main memory
e. Any of these
, ANS: D
The program is first loaded from secondary memory into main memory before it is executed so that the
processor is not slowed down by reading each instruction. This idea of executing programs stored in
memory is called the Stored Program Computer and was pioneered by John Von Neumann in the
1940s.
4. Which memory capacity is the largest?
a. 1,500,000,000,000 bytes
b. 100 gigabytes
c. 3,500,000 kilobytes
d. 10 terabytes
e. 12,000,000 megabytes
ANS: E
We convert each of these capacities to bytes (rounding off) to compare them. The value in A remains
the same, 1 1/2 trillion bytes. The value in B is 100 billion bytes. The value in C is 3 1/2 billion
bytes. The value in D is 10 trillion bytes. The answer in E is 12 trillion bytes.
5. Binary numbers are composed entirely of
a. 0s
b. 1s
c. 0s and 1s
d. any digits between 0 and 9
e. 0s, 1s, and 2s
ANS: C
Binary is base 2. In Mathematics, numbers in base n are composed entirely of digits between 0 and
n-1.
6. Volatility is a property of
a. RAM
b. ROM
c. disk
d. software
e. computer networks
ANS: A
Volatility means that the contents of memory are lost if the electrical power is shut off. This
is true of RAM (Random Access Memory), but not ROM (Read Only Memory) or disk.
Software and computer networks are not forms of memory.
7. The ability to directly obtain a stored item by referencing its address is known as
a. random access
b. sequential access
c. read-only access
d. fetch access
e. volatility
ANS: A
, Random access is meant to convey the idea that accessing any item is equally easy, and that any item
is retrievable based solely on its address. Random access is the form of access used by both RAM
and ROM memory. Disk access, called direct access, is a similar idea, and direct and random access
are sometimes referred to synonymously. Sequential access is used by tape.
8. Which phase of the fetch-decode-execute cycle might use a circuit in the arithmetic-logic unit?
a. fetch
b. decode
c. execute
d. during fetch or execute, but not decode
e. any of the phases
ANS: C
The fetch phase retrieves (fetches) the next program instruction from memory. The decode phase
determines which circuit(s) needs to be used to execute the instruction. The instruction is executed
during the execute phase. If the instruction is either an arithmetic operation (like add or multiply) or
a logical operation (like comparing two values), then it is carried out by the ALU.
9. In order for a computer to be accessible over a computer network, the computer needs its own
a. MODEM
b. communication line
c. network address
d. packet
e. router
ANS: C
In order to differentiate between the computers on a network, each is given its own, unique, network
address. In this way, a message intended for one computer can be recognized by that computer
through the message's destination address. A MODEM is a device that is used to allow a computer to
communicate to another computer over a telephone line. A communication line is the network media
itself. A packet is a collection of data that is sent over a network. A router is a hardware device
used to take a message from one network and move it to another based on the message's destination
address.
10. For a computer to communicate over the Internet, it must use
a. the TCP protocol
b. the IP protocol
c. the combined TCP/IP protocol
d. the Ethernet protocol
e. the ARPANET protocol
ANS: C
IP is the Internet Protocol, but the TCP (Transmission Control Protocol) also must be used because it
handles such problems as how to piece together packets of the same message that arrive out of order.
Ethernet is a LAN protocol, which might be used in addition to TCP/IP in some networks, but it is not
needed to communicate over the Internet. There is no such thing as the ARPANET protocol.
11. A URL (Uniform Resource Locator) specifies the address of a
a. computer on any network
b. computer on the Internet
, c. local area network (LAN) on the Internet
d. a document or other type of file on the Internet
e. a Java program on the Internet
ANS: D
URLs are used to locate documents (or other types of files such as an image or sound file) anywhere
on the Internet. A URL contains the address of the LAN or WAN and the specific computer from
which the file is to be retrieved; it specifies the file's address, not just the computer's address.
12. It is important to dissect a problem into manageable pieces before trying to solve the problem because
a. most problems are too complex to be solved as a single, large activity
b. most problems are solved by multiple people and it is easy to assign each piece to a sep-
arate person
c. ir is easier to integrate small pieces of a program into one program than it is to integrate
one big chunk of code into one program
d. the first solution may not solve the problem correctly
e. All of these
ANS: A
Any interesting problem will be too complex to solve easily as a single activity. By decomposing the
problem, we can build small solutions for each piece and then integrate the pieces. Answer D is true,
but it is not the reason why we will break a problem into pieces.
13. Once we have implemented a solution, we are not done with the problem because
a. the solution may not be the best (most efficient)
b. the solution may have errors and need testing and fixing
c. the solution may, at a later date, need revising to handle new specifications
d. the solution may, at a later date, need revising because of new programming language fea-
tures
e. All of these
ANS: E
A program should not be considered as a finished product until we are reasonably assured that it is ef-
ficient and error-free. Further, it is common that programs require modification in the future because
of a change to specifications or a change to the language or computer running the program.
14. Java is an example of a(n)
a. machine language
b. Assembly language
c. high-level language
d. fourth generation language
e. both high-level and fourth generation language
ANS: E
While Java was created during the fourth generation, it is clearly also a high-level language. Machine
language is the executable language of a machine, with programs written in 1s and 0s only. Assem-
bly language uses mnemonics. Fourth generation languages are tools wrapped inside of programs so
that the user has the flexibility to write some code to executed from within the program.
15. Of the following, which statement is not true regarding Java as a programming language?
, a. Java is a relatively recent language; it was introduced in 1995.
b. Java is a language whose programs do not require translating into machine language be-
fore they are executed.
c. Java is an object-oriented language.
d. Java is a language that embraces the idea of writing programs to be executed with the
World Wide Web.
e. All of these are true
ANS: B
All languages require translation into machine language. The other statements are all true about Java.
16. Comments should
a. rephrase all the code to explain it in English
b. be insightful and explain the intention of an instruction or block of code
c. only be included with code that is difficult to understand
d. be used to define variables that have hard to understand names
e. All of these
ANS: B
Comments should not rephrase in English what an instruction says, but instead should explain what
that instruction is doing in relation to the program. Introductory programmers often have difficult
explaining their code and wind up stating the obvious in their comments. While answer D is partially
correct, it is not entirely true even though all variables should have comments that explain their use.
17. The main method for a Java program is defined by
a. public static main()
b. public static main(String[] args);
c. public static main(String[] args)
d. private static main(String[] args)
e. The main method could be defined by all of these except B
ANS: C
In A, the parameter is missing. The parameters are defined later in the text, but in effect, they allow
the user to run the program and include some initial arguments if the program calls for it. In B, the
semicolon at the end of the statement is not allowed. In D, private instead of public would
make the program non-executable by anyone and thus makes the definition meaningless.
18. What does the following line of Java code do?
//System.out.println("Hello");
a. nothing
b. cause Hello to be output
c. cause a syntax error
d. cause ("Hello") to be output
e. There is no way to tell without executing the code.
ANS: A
The characters // denote the beginning of a comment. The comment is not compiled and so, nothing
would happen when this code is executed.
19. What comment might be added to explain the following instruction?
, System.out.println("Hello World");
a. // prints "Hello World" to the screen
b. //prints a message
c. //used to demonstrate an output message
d. //
e. // meaningless instruction
ANS: C
Comments in A and B state the obvious while the comments in D and E are meaningless. The com-
ment in C explains why the instruction appears in the program.
20. Which character belowis not allowed in an identifier?
a. $
b. _
c. 0
d. 1
e. ^
ANS: E
Java identifiers can consist of any letter, digit, $ or _ as long as the identifier starts with a letter or _.
^ is not a legal character.
21. Which of the following is not syntactically legal in Java?
a. System.out.println("Hi");
b. public class Foo
c. s t a t i c main(String[] args)
d. {}
e. only A is legally valid; all the others are illegal
ANS: C
The Java compiler would not recognize "s t a t i c" as "static" because the Java compiler
treats white space (blanks) as separators between entities. The other statements are all legal, includ-
ing "{}" which is a block that happens to have no statements within it.
22. Which of the following is a legal Java identifier?
a. i
b. class
c. 1likeclass!
d. idon'tlikeclass
e. i-like-class
ANS: A
Java identifiers cannot have the characters !, ' or - in them so answers C, D and E are wrong.
The word class is a reserved word in Java and cannot be used as an identifier. The identifier i is
perfectly legal although it is not necessarily a good identifier since it is not descriptive of its use.
23. A unique aspect of Java that allows code compiled on one machine to be executed on a machine with a
different hardware platform is Java's
a. bytecodes
Foundations of Program Design, 10th edition Lewis
Notes
1- The file is chapter after chapter.
2- We have shown you few pages sample.
3- The file contains all Appendix and Excel sheet
if it exists.
4- We have all what you need, we make update
at every time. There are many new editions
waiting you.
5- If you think you purchased the wrong file You
can contact us at every time, we can replace it
with true one.
Our email:
,Java Software Solutions, 10e (Lewis/Loftus)
Chapter 1 Introduction
TRUE/FALSE
1. All information is stored in the computer using binary numbers.
ANS: T
The computer is a digital device meaning that it stores information in one of two states using binary.
We must determine then how to represent meaningful information (such as a name or a program in-
struction or an image) in binary.
2. Java is an object-oriented programming language.
ANS: T
Java is classified as a high-level programming language but it is also classified as an object-oriented
programming language because it allows the programmer to implement data structures as classes.
3. System.out.print is used in a program to denote that a documentation comment follows.
ANS: F
Documentation comments follow // marks or are embedded between */ and */. Sys-
tem.out.print is an instruction used to output a message to the screen (the Java console window).
4. Java byte codes are directly executable whereas Java source code is not.
ANS: F
Neither Java source code nor Java byte codes are executable. Both must be compiled or interpreted
into machine code. Java byte codes are useful however in that they are machine-independent but
semi-compiled code that allows your Java code to be transmitted over the Internet and executed on
another computer even if that other computer is a completely different type.
5. The Java compiler is able to find all programmer errors.
ANS: F
The Java compiler can find syntax errors but cannot find either logical errors (errors that are caused
because of poor logic in writing the program) or run-time errors (errors that arise during the execution
of the program).
6. Java is a case-sensitive language which means Current, CURRENT, and current will all reference
the same identifier.
ANS: F
Java is case sensitive which means that Current, CURRENT, and current will all be recognized
as different identifiers. This causes problems with careless programmers who do not spell an iden-
tifier consistently in terms of upper and lower case characters.
, 7. Code placed inside of comments will not be compiled and, therefore, will not execute.
ANS: T
The compiler discards comments; therefore, any code inside a comment is discarded and is not com-
piled. Your executable program consists only of the code that is compiled.
8. The word Public is a reserved word.
ANS: F
public is a reserved word, but since Java is case sensitive, Public differs from public and there-
fore Public is not a reserved word.
9. Reserved words in Java can be redefined by the programmer to mean something other than their
original intentions.
ANS: F
Java reserved words cannot be redefined.
10. In a Java program, dividing by zero is a syntax error.
ANS: F
Dividing by 0 is not detected at compile time, and because a computer cannot divide by 0, this is a run-
time error.
11. In a Java program, dividing by zero is a syntax error.
ANS: F
Dividing by 0 is not detected at compile time, and because a computer cannot divide by 0, this is a run-
time error.
12. During translation, the compiler puts its output (the compiled Java program) into ROM.
ANS: F
ROM stands for read-only-memory. The compiled output (the byte codes) may be placed into RAM
(writable random access memory) or into a file (on your hard drive, for example).
13. Objects are defined by a class that describes the characteristics common to all instances of the class.
ANS: T
An object is an instance of a class. And, the purpose of a class is to describe these common charac-
teristics.
14. Inheritance is a form of software reuse.
ANS: T
, Inheritance allows us to capitalize on the similarities among various kinds of classes that have a com-
mon base (parent) class. Thus we reuse the base class each time a class inherits from it.
15. Polymorphism is the idea that we can refer to multiple types of related objects in consistent ways.
ANS: T
Polymorphism allows us to use the same name for similar behaviors that occur among diverse and pos-
sibly unrelated objects. For example, to "open" may refer to a file, or to a device, or to a communi-
cations line, etc. The same term, "open," is being used even though the objects that are being opened
are quite different.
16. In Java, identifiers may be of any length up to a limit determined by the compiler.
ANS: F
Java (and Java compilers) do not limit the length of the identifiers you use. Identifiers may be as
long as you wish. Good programming practice, however, will limit the lengths of the identifiers you
create.
MULTIPLE CHOICE
1. A Java program is best classified as
a. hardware
b. software
c. storage
d. processor
e. input
ANS: B
Programs are classified as software to differentiate them from the mechanisms of the computer (hard-
ware). Storage and the processor are two forms of hardware while input is the information that the
program processes.
2. Six bits can be used to represent __________ distinct items or values.
a. 6
b. 20
c. 24
d. 32
e. 64
ANS: E
With n bits, we can represent 2^n different values. 2^6 = 64.
3. When executing a program, the processor reads each program instruction from
a. secondary memory (storage)
b. the Internet
c. registers stored in the processor
d. main memory
e. Any of these
, ANS: D
The program is first loaded from secondary memory into main memory before it is executed so that the
processor is not slowed down by reading each instruction. This idea of executing programs stored in
memory is called the Stored Program Computer and was pioneered by John Von Neumann in the
1940s.
4. Which memory capacity is the largest?
a. 1,500,000,000,000 bytes
b. 100 gigabytes
c. 3,500,000 kilobytes
d. 10 terabytes
e. 12,000,000 megabytes
ANS: E
We convert each of these capacities to bytes (rounding off) to compare them. The value in A remains
the same, 1 1/2 trillion bytes. The value in B is 100 billion bytes. The value in C is 3 1/2 billion
bytes. The value in D is 10 trillion bytes. The answer in E is 12 trillion bytes.
5. Binary numbers are composed entirely of
a. 0s
b. 1s
c. 0s and 1s
d. any digits between 0 and 9
e. 0s, 1s, and 2s
ANS: C
Binary is base 2. In Mathematics, numbers in base n are composed entirely of digits between 0 and
n-1.
6. Volatility is a property of
a. RAM
b. ROM
c. disk
d. software
e. computer networks
ANS: A
Volatility means that the contents of memory are lost if the electrical power is shut off. This
is true of RAM (Random Access Memory), but not ROM (Read Only Memory) or disk.
Software and computer networks are not forms of memory.
7. The ability to directly obtain a stored item by referencing its address is known as
a. random access
b. sequential access
c. read-only access
d. fetch access
e. volatility
ANS: A
, Random access is meant to convey the idea that accessing any item is equally easy, and that any item
is retrievable based solely on its address. Random access is the form of access used by both RAM
and ROM memory. Disk access, called direct access, is a similar idea, and direct and random access
are sometimes referred to synonymously. Sequential access is used by tape.
8. Which phase of the fetch-decode-execute cycle might use a circuit in the arithmetic-logic unit?
a. fetch
b. decode
c. execute
d. during fetch or execute, but not decode
e. any of the phases
ANS: C
The fetch phase retrieves (fetches) the next program instruction from memory. The decode phase
determines which circuit(s) needs to be used to execute the instruction. The instruction is executed
during the execute phase. If the instruction is either an arithmetic operation (like add or multiply) or
a logical operation (like comparing two values), then it is carried out by the ALU.
9. In order for a computer to be accessible over a computer network, the computer needs its own
a. MODEM
b. communication line
c. network address
d. packet
e. router
ANS: C
In order to differentiate between the computers on a network, each is given its own, unique, network
address. In this way, a message intended for one computer can be recognized by that computer
through the message's destination address. A MODEM is a device that is used to allow a computer to
communicate to another computer over a telephone line. A communication line is the network media
itself. A packet is a collection of data that is sent over a network. A router is a hardware device
used to take a message from one network and move it to another based on the message's destination
address.
10. For a computer to communicate over the Internet, it must use
a. the TCP protocol
b. the IP protocol
c. the combined TCP/IP protocol
d. the Ethernet protocol
e. the ARPANET protocol
ANS: C
IP is the Internet Protocol, but the TCP (Transmission Control Protocol) also must be used because it
handles such problems as how to piece together packets of the same message that arrive out of order.
Ethernet is a LAN protocol, which might be used in addition to TCP/IP in some networks, but it is not
needed to communicate over the Internet. There is no such thing as the ARPANET protocol.
11. A URL (Uniform Resource Locator) specifies the address of a
a. computer on any network
b. computer on the Internet
, c. local area network (LAN) on the Internet
d. a document or other type of file on the Internet
e. a Java program on the Internet
ANS: D
URLs are used to locate documents (or other types of files such as an image or sound file) anywhere
on the Internet. A URL contains the address of the LAN or WAN and the specific computer from
which the file is to be retrieved; it specifies the file's address, not just the computer's address.
12. It is important to dissect a problem into manageable pieces before trying to solve the problem because
a. most problems are too complex to be solved as a single, large activity
b. most problems are solved by multiple people and it is easy to assign each piece to a sep-
arate person
c. ir is easier to integrate small pieces of a program into one program than it is to integrate
one big chunk of code into one program
d. the first solution may not solve the problem correctly
e. All of these
ANS: A
Any interesting problem will be too complex to solve easily as a single activity. By decomposing the
problem, we can build small solutions for each piece and then integrate the pieces. Answer D is true,
but it is not the reason why we will break a problem into pieces.
13. Once we have implemented a solution, we are not done with the problem because
a. the solution may not be the best (most efficient)
b. the solution may have errors and need testing and fixing
c. the solution may, at a later date, need revising to handle new specifications
d. the solution may, at a later date, need revising because of new programming language fea-
tures
e. All of these
ANS: E
A program should not be considered as a finished product until we are reasonably assured that it is ef-
ficient and error-free. Further, it is common that programs require modification in the future because
of a change to specifications or a change to the language or computer running the program.
14. Java is an example of a(n)
a. machine language
b. Assembly language
c. high-level language
d. fourth generation language
e. both high-level and fourth generation language
ANS: E
While Java was created during the fourth generation, it is clearly also a high-level language. Machine
language is the executable language of a machine, with programs written in 1s and 0s only. Assem-
bly language uses mnemonics. Fourth generation languages are tools wrapped inside of programs so
that the user has the flexibility to write some code to executed from within the program.
15. Of the following, which statement is not true regarding Java as a programming language?
, a. Java is a relatively recent language; it was introduced in 1995.
b. Java is a language whose programs do not require translating into machine language be-
fore they are executed.
c. Java is an object-oriented language.
d. Java is a language that embraces the idea of writing programs to be executed with the
World Wide Web.
e. All of these are true
ANS: B
All languages require translation into machine language. The other statements are all true about Java.
16. Comments should
a. rephrase all the code to explain it in English
b. be insightful and explain the intention of an instruction or block of code
c. only be included with code that is difficult to understand
d. be used to define variables that have hard to understand names
e. All of these
ANS: B
Comments should not rephrase in English what an instruction says, but instead should explain what
that instruction is doing in relation to the program. Introductory programmers often have difficult
explaining their code and wind up stating the obvious in their comments. While answer D is partially
correct, it is not entirely true even though all variables should have comments that explain their use.
17. The main method for a Java program is defined by
a. public static main()
b. public static main(String[] args);
c. public static main(String[] args)
d. private static main(String[] args)
e. The main method could be defined by all of these except B
ANS: C
In A, the parameter is missing. The parameters are defined later in the text, but in effect, they allow
the user to run the program and include some initial arguments if the program calls for it. In B, the
semicolon at the end of the statement is not allowed. In D, private instead of public would
make the program non-executable by anyone and thus makes the definition meaningless.
18. What does the following line of Java code do?
//System.out.println("Hello");
a. nothing
b. cause Hello to be output
c. cause a syntax error
d. cause ("Hello") to be output
e. There is no way to tell without executing the code.
ANS: A
The characters // denote the beginning of a comment. The comment is not compiled and so, nothing
would happen when this code is executed.
19. What comment might be added to explain the following instruction?
, System.out.println("Hello World");
a. // prints "Hello World" to the screen
b. //prints a message
c. //used to demonstrate an output message
d. //
e. // meaningless instruction
ANS: C
Comments in A and B state the obvious while the comments in D and E are meaningless. The com-
ment in C explains why the instruction appears in the program.
20. Which character belowis not allowed in an identifier?
a. $
b. _
c. 0
d. 1
e. ^
ANS: E
Java identifiers can consist of any letter, digit, $ or _ as long as the identifier starts with a letter or _.
^ is not a legal character.
21. Which of the following is not syntactically legal in Java?
a. System.out.println("Hi");
b. public class Foo
c. s t a t i c main(String[] args)
d. {}
e. only A is legally valid; all the others are illegal
ANS: C
The Java compiler would not recognize "s t a t i c" as "static" because the Java compiler
treats white space (blanks) as separators between entities. The other statements are all legal, includ-
ing "{}" which is a block that happens to have no statements within it.
22. Which of the following is a legal Java identifier?
a. i
b. class
c. 1likeclass!
d. idon'tlikeclass
e. i-like-class
ANS: A
Java identifiers cannot have the characters !, ' or - in them so answers C, D and E are wrong.
The word class is a reserved word in Java and cannot be used as an identifier. The identifier i is
perfectly legal although it is not necessarily a good identifier since it is not descriptive of its use.
23. A unique aspect of Java that allows code compiled on one machine to be executed on a machine with a
different hardware platform is Java's
a. bytecodes