Java Chapter 1

Ace your homework & exams now with Quizwiz!

The main method header is written as:

public static void main(String[] args)

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 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) {

This is the brain of a computer

CPU

machine language

Computer can execute the code in this level of programming

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?

What is a main method and its characteristics?

The main method allows testing and execution of the class by default.

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.

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 API

contains predefined classes and interfaces for developing Java programs.

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.

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.

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

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

Name the two block styles when programming in Java

End of line style Next-line Style

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

; 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

A class must contain a method. True or False?

True

Java bytecode

Which JDK command is correct to run a Java application in ByteCode.class?

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

One byte contains how many bits?

bits

Java JDK

consists of a set of separate programs for developing and testing Java programs, each of which is invoked from a command line.

network interface controller (NIC)

is a device to connect a computer to a local area network (LAN)

Operating system

is a program that runs on a computer to manage and control a computer's activities.

JVM (Java Virtual Machine)

is a software that interprets Java bytecode

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


Related study sets

Chapter 19: Daily Financial Practices

View Set

Chapter 29: Management of Patients With Complications from Heart Disease

View Set

ENTREPRENEURSHIP MIDTERM STUDY GUIDE

View Set

Diversity and Social Issues in Sport Business Final

View Set

Planning for Career Requirements

View Set