Survey
* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
Java A Beginner’s Guide Fifth Edition by Herbert Schildt Chapter 1 Questions 1. Bytecode is the language interpreted by the Java Virtual Machine (JVM). When you compile a Java program it is compiled into Bytecode, which is then interpreted by the systems local JVM into machine executable code. This is important to Internet programming because it allows the code to be universally executed by any system or device that has a JVM available. Also, the JVM itself provides a layer of security, helping prevent malicious code from being executed. 2. The three main principles of Object-Oriented (OO) programming follow are: a. Encapsulation i. Code is encapsulated in classes which group data and methods pertaining to that class together. b. Polymorphism i. Generic interfaces can be made that allow a standard method to be run but the outcome is difference based on the properties of the class. c. Inheritance i. Classes can inherit properties from a parent class, reducing the amount of duplicate code entered. 3. Java programs begin execution in the main method. 4. A variable provides storage for a value, or data, within a program. In Java variables have strict typing, which forces the values stored in a variable to be a certain type (String, integer, Boolean, ETC). 5. D - 67count is not a valid identifier name. If you recall from page 29 of the book an identifier cannot start with a digit, it must start with a letter, underscore (_) or dollar sign ($). 6. A single line comment is done using a double forward slash (//). A multi-line comment starts with a forward slash and asterisk (/*) and end with an asterisk and forward slash (*/). a. // Single line commend b. /* muti line comment */ 7. Control statements: a. if statmenet i. if (condition) statement; b. for loop i. for (initialization; condition; iteration) statement; 8. You create a block of code by encapsulating it in curly braces. a. { block of code } 9. Code: class MoonWeight { public static void main (String[] args) { double earthWeight = 170; double moonWeight = earthWeight * 0.17; System.out.println("Earth Weight: " + earthWeight + "\nMoon Weight: " + moonWeight); } } 10. Code: class InchesToMeters { public static void main (String[] args) { double inches, meters; int counter; counter = 0; for (inches = 1; inches <= (12 * 12); inches++) { meters = inches * 39.37; System.out.println(inches + " inches is " + meters + " meters."); counter++; // Every 12 inches, insert a blank line if (counter == 12) { System.out.println(); counter = 0; // Reset counter } } } } 11. Syntax error from the Java compiler. 12. No, Java ignores white space on lines. However, your statements must be well formatted and end with a semicolon.