Java Chapter 1
The main method header is written as:
public static void main(String[] args)
True or False? A java interpreter is a program that translates Java source code into Java bytecode
False; java interpreter
What type of error is in this code? Where is the error? public class ShowSyntaxErrors { public static main(String[ ] args) { System.out.println(1/0); } }
Runtime error and Syntax error: 1 can not be divided by 0. void is missing from the main method
Write a statement to display "Good Morning".
System.out.println("Good Morning");
Suppose you define a Java class as follows: public class Test { } In order to compile this program, the source code should be stored in a file named
Test.java
Java bytecode
Which JDK command is correct to run a Java application in ByteCode.class?
One byte contains how many bits?
bits
network interface controller (NIC)
is a device to connect a computer to a local area network (LAN)
JVM (Java Virtual Machine)
is a software that interprets Java bytecode
Java language specification
is a technical definition of the language that includes the syntax and semantics of the Java programming language.
Hardware
is the physical aspect of the computer that can be seen.
Write a program that displays the following pattern: J A V V A J A A V V A A J J AAAAA V V AAAAA J J A A V A A
public class DisplayPattern { pubic static void main (String [ ] args) {
Describe these special symbols that are in a java program. { } ( ) [ ] // " " ;
-Braces denotes a block to enclose statements -Parentheses is used with methods -Brackets denotes an array -Double Slashes precedes a comment line - Quotation marks enclose a string ; ends a statement
This is the brain of a computer
CPU
What is the naming conventions of a class?
Capitalize the first letter of each word in a name. Name should be meaningful and descriptive
What is the Anatomy of a Java Program
Class name Main Method Statements Statement Terminator Reserved Words Comments Blocks
machine language
Computer can execute the code in this level of programming
Name the two block styles when programming in Java
End of line style Next-line Style
logic error
If a program compiles fine, but it produces incorrect result, then the program suffers __________.
compilation error
If you forget to put a closing quotation mark on a string, what kind error will be raised?
; represents what in a java program?
Statement Terminator which ends a action or sequence of actions in java
A group of statements enclosed by a pair of braces is called a _______
Statement block
Test.java
Suppose you define a Java class as follows: public class Test { } In order to compile this program, the source code should be stored in a file named
javac Test.java
The JDK command to compile a class in the file Test.java is
What is a main method and its characteristics?
The main method allows testing and execution of the class by default.
A class must contain a method. True or False?
True
If you forget to put a closing quotation mark on a string, what kind of error will be raised?
a compilation (syntax) error
System.out.println("Welcome to Java!"); represents what in a java program?
a statement which is an action or sequence of actions in a java program.
Name the fifty reserved words/ keywords in Java?
abstract assert boolean break byte case catch char class const continue default do double else enum extends final finally float for goto if implements import instanceof int interface long native new package private protected public return short static strictfp* super switch synchronized this throw throws transient try void volatile while
What command is used to run a Java program
java
Which JDK command is correct to run a Java application in ByteCode.class?
java ByteCode
What command is used to compile a Java program?
javac
The speed of the CPU may be measured in
megahertz / gigahertz
Name and Define 3 errors that are common in Java programming.
Syntax Errors-which is detected by the compiler Runtime errors - which causes the program to abort Logic Errors - which produces the incorrect result
What type of error is in this code? Where is the error? public class ShowSyntaxErrors { public static main(String[ ] args) { System.out.println(" 5+3=6"); } }
Syntax and logic error void is missing from the main method The string 5+3=6 is logically incorrect, the answer is 8.
What type of error is in this code? Where is the error? public class ShowSyntaxErrors { public static main(String[ ] args) { System.out.println("Welcome to Java); } }
Syntax error: 1. missing void in method: public static void main 2. missing quotations in string: System.out.println("Welcome to Java");
.class
The extension name of a Java bytecode file is
.java
The extension name of a Java source code file is
True or False? The public classname must be the same as the filename that contains the class?
True
Which of the following statements is correct to display Welcome to Java on the console? A. System.out.println('Welcome to Java'); B. System.out.println("Welcome to Java"); C. System.println('Welcome to Java'); D. System.out.print('Welcome to Java'); E. System.out.print("Welcome to Java");
Which of the following statements is correct to display Welcome to Java on the console? B and E
Why do computers used zeros and ones?
because digital devices have two stable states and it is natural to use one state for 0 and the other for 1.
{ marks the _____________ of a block and } marks the_______________ of a block.
beginning end
Java JDK
consists of a set of separate programs for developing and testing Java programs, each of which is invoked from a command line.
Java API
contains predefined classes and interfaces for developing Java programs.
Operating system
is a program that runs on a computer to manage and control a computer's activities.
Write a program that displays Welcome to Java Welcome to Computer Science Programming is Fun
public class Three Messages{ public static void main (String [ ] args){ System.out.println ("Welcome to Java"); System.out.println ("Welcome to Computer Science"); System.out.println ("Programming is Fun"); } }
Write a program that displays Welcome to Java five times.
public class WelcomeToJavaFiveTimes { public static void main (String [ ] args) { int count = 1; while (count <=5){ System.out.println ("Welcome to Java"); count++; } } }
A compiler
translates high-level language program into machine language program.
True or False. The keywords in java are all lowercase?
true
Reserved Words or Keywords are_________________.
words that have a specific meaning to the compiler that can not be used for other purpose in a java program
Which of the following code would run and display welcome to Java? I: public class Test { public static void main(String[] args) { System.out.println("Welcome to Java!"); } } II: public class Test { public static void main(String[] args) { System.out.println("Welcome to Java!"); } }
Both I and II can compile and run and display Welcome to Java, but the code in I has a better style.