Chapter 1: Review Questions
1. The most basic circuitry-level computer language, which consists of on and off switches, is machine language. (b)
2. Languages that let you use a vocabulary of descriptive terms, such as read, write, or add, are known as high-level languages. (a)
3. The rules of a programming language constitue its syntax. (d)
4. A compiler translates high-level language statements into machine code. (c)
5. Named computer memory locations are called variables. (b)
6. The individual operations used in a computer program are often grouped into units called procedures. (a)
7. Envisioning program components as objects that are similar to concrete objects in the real world is the hallmark of object-oriented programming (c).
8. The value of an object's attributes are also known as its state. (b)
9. An instance of a class is a(n) object. (a)
10. Java is architecturally neutral. (c)
11. You must compile classes written in Java into bytecode. (a)
12. All Java programming statements must end with semicolon. (c)
13. Arguments to methods always appear within parenthesis. (a).
14. In a Java program, you must use dots to separate classes, objects, and methods. (c)
15. All Java applications must have a method named main(). (b)
16. Nonexecuting program statements that provide documentation are called comments. (c)
17. Java supports three types of comments: line, block and javadoc. (a)
18. After you write and save a Java application file, you compile and then interpret it. (d)
19. The command to execute a compiled Java application is java. (d)
20. You save the text files containing Java source code using the file extension .java. (a)
Exercises (coming soon)
1.
a. weeklySales - legal
b. last character - illegal
c. class - illegal
d. MathClass - legal
e. myfirstinitial - legal
f. phone# - illegal
g. abcdefghiklmnop - legal
h. 23jordan - illegal
i. my_code - legal
j. 90210 - illegal
k. year2013budget - legal
l. abffraternity - legal
2.
a. TelevisionSet: size, make, numOfInputs
b. EmployeePaycheck: name, amount, department
c. PatientMedicalRecord: name, age, weight
3.
a. Politician: chrisChristie, mittRomney, barackObama
b. SportingEvent: superbowl, worldSeries, pGATour
c. Book: fightClub, oneFlewOverTheCuckoosNest, harryPotter
4.
a. mickeyMouse: Mouse, DisneyCharacter, Animal
b. myDogSpike: Dog, Animal, Pet
c. bostonMassachusetts: City, StateCapital, BaseballTeamHomeCity
public class Name /*Displays my name*/ { public static void main(String[] args) { System.out.println("Name Line 1"); } }
public class Address /*Displays my name and address*/ { public static void main(String[] args) { System.out.println("Address Line 1"); System.out.println("Address Line 2"); System.out.println("Address Line 3"); } }
public class Tree /*Displays a tree pattern on the screen*/ { public static void main(String[] args) { System.out.println(" X "); System.out.println(" XXX "); System.out.println(" XXXXX "); System.out.println("XXXXXXX"); System.out.println(" X "); } }
public class Initial /*Displays my initials */ { public static void main(String[] args) { System.out.println(" AA M M"); System.out.println(" A A M M M M"); System.out.println(" AAAAAA M M M"); System.out.println(" A A M M"); System.out.println("A A M M"); } }
public class Diamond /*Displays a Diamond */ { public static void main(String[] args) { System.out.println(" * "); System.out.println(" * * "); System.out.println("* * *"); System.out.println(" * * "); System.out.println(" * "); } }
//Displays the following comment:Program comments are nonexecuting statements you add to a file for the purpose of documentation. /*Displays the following comment: Program comments are nonexecuting statements you add to a file for the purpose of documentation. */ /**Displays the following comment: Program comments are nonexecuting statements you add to a file for the purpose of documentation. */ public class Comments { public static void main(String[] args) { System.out.println("Program comments are nonexecuting statements you add to a file for the purpose of documentation."); } }
//Displays the following comment: Program comments are nonexecuting statements you add to a file for the purpose of documentation. /*Displays the following comment: Program comments are nonexecuting statements you add to a file for the purpose of documentation. */ /**Displays the following comment: Program comments are nonexecuting statements you add to a file for the purpose of documentation. */ import javax.swing.JOptionPane; public class CommentsDialog { public static void main(String[] args) { JOptionPane.showMessageDialog(null, "Program comments are nonexecuting statements you add to a file for the purpose of documentation."); } }
import javax.swing.JOptionPane; public class BurmaShave /*Displays a Burma Shave rhyme in a dialog box*/ { public static void main(String[] args) { JOptionPane.showMessageDialog(null, "Shaving brushes"); JOptionPane.showMessageDialog(null, "You'll soon see 'em"); JOptionPane.showMessageDialog(null, "On a shelf"); JOptionPane.showMessageDialog(null, "In some museum"); JOptionPane.showMessageDialog(null, "Burma Shave"); } }
public class CardLayout /*Displays an attractive layout of information in a typical business card*/ { public static void main(String[] args) { System.out.println("Name Line 1"); System.out.println("Address Line 1"); System.out.println("Address Line 2"); System.out.println("Home: Home Phone 1"); System.out.println("Work: Home Phone 2"); } }
import javax.swing.JOptionPane; public class RandomGuess /* Guessing game where a user is challenged to guess a random number*/ { public static void main(String[] args) { JOptionPane.showMessageDialog(null, "Think of a number between 1 and 10."); JOptionPane.showMessageDialog(null, "Is it: " + (1 + (int)(Math.random()*10))); } }