Chapter 1 - 1.7 A Simple Java Program

Réussis tes devoirs et examens dès maintenant avec Quizwiz!

What is Special characters in Java?

( - A table for Special Characters is shown here. )

What is the semicolon (;)?

Every statement in Java ends with a semicolon (;). ( - It's also known as the statement terminator. )

What does System.out.println("My output"); do?

We use this method to print things to the screen. ( Whatever is inside the parenthesis gets printed This is what we use to print hello world. )

Is Java case sensitive?

Yes, java source code is case sensitive.

Show the output of the following code: public class Test { public static void main(String[] args) { System.out.println("3.5 * 4 / 2 - 2.5 is "); System.out.println(3.5 * 4 / 2 - 2.5); } }

3.5 * 4 / 2 - 2.5 is 4.5

What is the function of curly braces in a program?

In Java, each block begins with an opening brace ({) and ends with a closing brace (}). ( - A pair of curly braces in a program forms a block that groups the program's components. - Every class has a class block that groups the data and methods of the class. - Similarly, every method has a method block that groups the statements in the method. - Blocks can be nested, meaning that one block can be placed within another. )

What is the main method in Java?

Main method in Java is an standard method which is used by JVM (Java Virtual Machine) to start execution of any Java program. ( - The main method is the entry point where the program begins execution. - A class may contain several methods but a class can only have a single main method. - A method is a construct that contains statements. For example the main method in a Java program contains the System.out.println statement. )

What is the output of Listing 1.2? Listing 1.2: public class WelcomeWithThreeMessages { public static void main(String[] args) { System.out.println("Programming is fun!"); System.out.println("Fundamentals First"); System.out.println("Problem Driven"); } }

Programming is fun! Fundamentals First Problem Driven

What is the line numbers in Java?

The line numbers are for reference purposes only, they are not part of the program.

How many classes must a Java program atleast have?

A Java program must have atleast one class. ( By convention, class names start with an uppercase letter. )

What is a comment? (What is a comment? Is the comment ignored by the compiler? How do you denote a comment line and a comment paragraph?)

Comments help programmers to communicate and understand the program. ( - In Java, comments are preceded by two slashes (//) on a line, called a line comment. - Enclosed between /*and */ on one or several lines, is called a block commentor paragraph comment. - When the compiler sees //, it ignores all text after // on the same line. - When it sees /*, it scans for the next */ and ignores any text between /*and */. - Comments is not programming statements and thus are ignored by the compiler. )

What is console input?

Console input means to receive input from the keyboard.

What is a console?

Console is used to display information in a text window. ( - The word "console" is an old computer term that refers to the text entry and display device of a computer. - The Console is also called Terminal. )

What is console output?

Console output means to display output on the monitor.

What is a keyword? List some Java keywords.

Keywords have specific meaning to the compiler and cannot be used for other purposes in the program (such as variables or method names). ( - Keywords is also called in programming terms as Reserved words. - Examples of keywords are: class, static, and void. )

What happens in Listing 1.2? Listing 1.2: public class WelcomeWithThreeMessages { public static void main(String[] args) { System.out.println("Programming is fun!"); System.out.println("Fundamentals First"); System.out.println("Problem Driven"); } }

Line 1 defines a class. Line 2 defines the main method. Line 3 is a System.out.println statement that displays the string "Programming is fun!" on the console. Line 4 is a System.out.println statement that displays the string "Fundamentals First" on the console. Line 5 is a System.out.println statement that displays the string "Problem Driven" on the console. Line 6 is a closing brace for a method. Line 7 is a closing brace for a class. ( Long Version: 1. Line 1 defines a class. 2. Line 2 defines the main method. 3. Line 3 The main method in this program contains the System.out.println statement. This statement displays the string "Programming is fun!" on the console (line 3). 4. Line 4 The main method in this program contains the System.out.println statement. This statement displays the string "Fundamentals First" on the console (line 4). 5. Line 5 The main method in this program contains the System.out.println statement. This statement displays the string "Problem Driven" on the console (line 5). 6. Line 6 is a closing brace for a method. 7. Line 7 is a closing brace for a class. )

What happens in Listing 1.3? Listing 1.3: public class ComputeExpression { public static void main(String[] args) { System.out.println((10.5 + 2 * 3) / (45 - 3.5)); } }

Line 1 defines a class. Line 2 defines the main method. Line 3 is a System.out.println statement that performs and displays a mathematical computations on the console. ( Long Version: 1. Line 1 defines a class. 2. Line 2 defines the main method. 3. Line 3 The main method in this program contains the System.out.println statement. This statement performs and displays a mathematical computations on the console. (line 3). 4. Line 6 is a closing brace for a method. 5 Line 7 is a closing brace for a class. The output displays )

What happens in Listing 1.1? Listing 1.1: public class Welcome { public static void main(String[] args) { // Display message Welcome to Java! on the console System.out.println("Welcome to Java!"); } }

Line 1 defines a class. Line 2 defines the main method. Line 3 is a comment. Line 4 is a System.out.println statement that displays the string "Welcome to Java!" on the console. Line 5 is a closing brace for a method. Line 6 is a closing brace for a class. ( Long Version: 1. Line 1 defines a class. 2. Line 2 defines the main method. 3. Line 3 is a comment that documents what the program is and how it is constructed. 4. Line 4 The main method in this program contains the System.out.println statement. This statement displays the string "Welcome to Java!" on the console (line 4). 5. Line 5 is a closing brace for a method. 6. Line 6 is a closing brace for a class. )

What is String?

String is a programming term meaning a sequence of characters.

What is the statement to display a string on the console?

System.out.println(string);

What is the common errors in Java?

The common errors in Java is syntax errors. ( - If your program violates a rule — for example, if the semicolon is missing, a brace is missing, a quotation mark is missing, or a word is misspelled—the Java compiler will report syntax errors. )

What is the output of Listing 1.1? Listing 1.1: public classWelcome { public static voidmain(String[] args) { // Display message Welcome to Java! on the console System.out.println("Welcome to Java!"); } }

Welcome to Java!

Matching curly braces with each other and organizing it in a good fashion, is it good or bad? (Yes or no)

Yes.


Ensembles d'études connexes

Priority Setting Framework (Adv)

View Set

Chapter 28 Homework: The Reproductive System

View Set

Section 2 Unit 2: Market Efficiency

View Set

the point pre infection and stress

View Set

Chapter 19: Diseases that affect the Respiratory System

View Set

Network+ 8th edition Chapter 3 Quiz

View Set