Full file at

Similar documents
Section 2.2 Your First Program in Java: Printing a Line of Text

Section 2.2 Your First Program in Java: Printing a Line of Text

C++ Spring Break Packet 11 The Java Programming Language

Università degli Studi di Bologna Facoltà di Ingegneria. Principles, Models, and Applications for Distributed Systems M

Introduction to Java Applications

12/22/11. Java How to Program, 9/e. Help you get started with Eclipse and NetBeans integrated development environments.

Assoc. Prof. Dr. Marenglen Biba. (C) 2010 Pearson Education, Inc. All rights reserved.

AL GHURAIR UNIVERSITY College of Computing. Objectives: Examples: Text-printing program. CSC 209 JAVA I

Introduction to Java Applications; Input/Output and Operators

2.8. Decision Making: Equality and Relational Operators

Introduction to Classes and Objects Pearson Education, Inc. All rights reserved.

Introduction to Classes and Objects

download instant at

Welcome1.java // Fig. 2.1: Welcome1.java // Text-printing program.

Introduction to Classes and Objects Pearson Education, Inc. All rights reserved.

Getting started with Java

Introduction to C++ Programming Pearson Education, Inc. All rights reserved.

B.V. Patel Institute of BMC & IT, UTU 2014

Tester vs. Controller. Elementary Programming. Learning Outcomes. Compile Time vs. Run Time

Elementary Programming

Entry Point of Execution: the main Method. Elementary Programming. Learning Outcomes. Development Process

CS111: PROGRAMMING LANGUAGE II

Object Oriented Programming. Java-Lecture 1

Introduction to Programming Using Java (98-388)

Course Outline. Introduction to java

3 CREATING YOUR FIRST JAVA APPLICATION (USING WINDOWS)

SCHOOL OF COMPUTING, ENGINEERING AND MATHEMATICS SEMESTER 1 EXAMINATIONS 2015/2016 CI101 / CI177. Programming

Chapter 1: Introduction to Computers, Programs, and Java

COSC 123 Computer Creativity. Introduction to Java. Dr. Ramon Lawrence University of British Columbia Okanagan

Java Foundations: Introduction to Program Design & Data Structures, 4e John Lewis, Peter DePasquale, Joseph Chase Test Bank: Chapter 2

Chapter 2: Basic Elements of Java

CMSC 150 INTRODUCTION TO COMPUTING LAB WEEK 3 STANDARD IO FORMATTING OUTPUT SCANNER REDIRECTING

2.5 Another Application: Adding Integers

Mid Term Exam 1. Programming I (CPCS 202) Instructor: M. G. Abbas Malik Date: Sunday November 3, 2013 Total Marks: 50 Obtained Marks:

CS 11 java track: lecture 1

Java: Comment Text. Introduction. Concepts

Review for Test 1 (Chapter 1-5)

First Java Program - Output to the Screen

An overview of Java, Data types and variables

CSc 2010 Principles of Computer Science, Fall 2013 Practice Problems for Midterm 3* * 3 17 % 9-20 % (26 / 7) "2"

Software and Programming 1

Lecture 05 I/O statements Printf, Scanf Simple statements, Compound statements

Programming with Java

DEPARTMENT OF MATHS, MJ COLLEGE

Lecture 7: Classes and Objects CS2301

Lecture 9. Assignment. Logical Operations. Logical Operations - Motivation 2/8/18

Interpreted vs Compiled. Java Compile. Classes, Objects, and Methods. Hello World 10/6/2016. Python Interpreted. Java Compiled

4 WORKING WITH DATA TYPES AND OPERATIONS

Project 1. Java Control Structures 1/17/2014. Project 1 and Java Intro. Project 1 (2) To familiarize with

Entry Point of Execution: the main Method. Elementary Programming. Compile Time vs. Run Time. Learning Outcomes

PROGRAMMING FUNDAMENTALS

CS110: PROGRAMMING LANGUAGE I

Key Differences Between Python and Java

INDEX. A SIMPLE JAVA PROGRAM Class Declaration The Main Line. The Line Contains Three Keywords The Output Line

Lecture Set 2: Starting Java

Java. Programming: Chapter Objectives. Why Is Repetition Needed? Chapter 5: Control Structures II. Program Design Including Data Structures

Selected Questions from by Nageshwara Rao

CSC 1051 Algorithms and Data Structures I. Midterm Examination February 24, Name: KEY 1

Lecture Set 2: Starting Java

Chapter 2 Author Notes

Introduction To Java. Chapter 1. Origins of the Java Language. Origins of the Java Language. Objects and Methods. Origins of the Java Language

c) Comments do not cause any machine language object code to be generated. d) Lengthy comments can cause poor execution-time performance.

Copyright 1999 by Deitel & Associates, Inc. All Rights Reserved.

Lecture Notes CPSC 224 (Spring 2012) Today... Java basics. S. Bowers 1 of 8

Chapter 2: Introduction to C++

Introduction to Computer Science Unit 2. Exercises

Chapter 2: Special Characters. Parts of a C++ Program. Introduction to C++ Displays output on the computer screen

Java Bytecode (binary file)

Features of C. Portable Procedural / Modular Structured Language Statically typed Middle level language

Simple Java Reference

Java provides a rich set of operators to manipulate variables. We can divide all the Java operators into the following groups:

STUDENT LESSON A7 Simple I/O

Object-Oriented Programming

COMP 110 Project 1 Programming Project Warm-Up Exercise

Introduction to C# Applications

DM550 / DM857 Introduction to Programming. Peter Schneider-Kamp

Software and Programming 1

Exam 1. Programming I (CPCS 202) Instructor: M. G. Abbas Malik. Total Marks: 45 Obtained Marks:

Chapter 2: Using Data

Sir Syed University of Engineering and Technology. Computer Programming & Problem Solving ( CPPS )

CS5000: Foundations of Programming. Mingon Kang, PhD Computer Science, Kennesaw State University

Gaddis: Starting Out with Java: From Control Structures through Objects, 6/e

Introduction to C# Applications Pearson Education, Inc. All rights reserved.

Wentworth Institute of Technology. Engineering & Technology WIT COMP1000. Java Basics

CS11 Java. Fall Lecture 1

last time in cs recitations. computer commands. today s topics.

Lecture Set 4: More About Methods and More About Operators

Review Chapters 1 to 4. Instructor: Scott Kristjanson CMPT 125/125 SFU Burnaby, Fall 2013

M105: Introduction to Programming with Java Midterm Examination (MTA) Makeup Spring 2013 / 2014

CHAPTER 2 Java Fundamentals

Chapter 2, Part I Introduction to C Programming

History of Java. Java was originally developed by Sun Microsystems star:ng in This language was ini:ally called Oak Renamed Java in 1995

Mr. Monroe s Guide to Mastering Java Syntax

Formatted Output (printf) CSE 1310 Introduction to Computers and Programming Vassilis Athitsos University of Texas at Arlington

Full file at C How to Program, 6/e Multiple Choice Test Bank

More on variables and methods

when you call the method, you do not have to know exactly what those instructions are, or even how the object is organized internally

1. Find the output of following java program. class MainClass { public static void main (String arg[])

Computer Components. Software{ User Programs. Operating System. Hardware

Programming in Java Prof. Debasis Samanta Department of Computer Science Engineering Indian Institute of Technology, Kharagpur

Transcription:

Chapter 2 Introduction to Java Applications Section 2.1 Introduction ( none ) Section 2.2 First Program in Java: Printing a Line of Text 2.2 Q1: End-of-line comments that should be ignored by the compiler are denoted using a. Two forward slashes ( // ). b. Three forward slashes ( /// ). c. A slash and a star ( /* ). d. A slash and two starts ( /** ). e. ANS: a. Two forward slashes ( // ). 2.2 Q2: Which of the following is not a valid Java identifier? a. my Value b. $_AAA1 c. width d. m_x ANS: a. my Value (Identifiers may not contain blanks). 2.2 Q3: Which of the following cannot cause a syntax error to be reported by the Java compiler? a. Mismatched {} b. Missing */ in a comment that begins with /* c. Missing ; d. Extra blank lines. ANS: d. Extra blank lines. 2.2 Q4: Which of the following is not a syntax error? a. System.out.println( 'Hello world!' ): b. System.out.println( "Hello world!" ); c. System.out.println( "Hello world!" ); d. System.out.println( Hello world! ); ANS: c. System.out.println( "Hello world!" ); Compiling and Executing Your First Java Application 2.2 Q5: Which command compiles the Java source code file Welcome.java? a. cd Welcome.java b. javac Welcome.java c. java Welcome.java

d. compile Welcome.java ANS: b. javac Welcome.java 2.2 Q6: Which command executes the Java class file Welcome.class? a. javac Welcome.class b. java Welcome.class c. java Welcome d. run Welcome.class ANS: c. java Welcome Section 2.3 Modifying Our First Java Program Displaying a Single Line of Text with Multiple Statements 2.3 Q1: Which is the output of the following statements? System.out.print( "Hello "); System.out.println( "World" ); a. Hello World b. HelloWorld c. Hello World d. World Hello ANS: a. Hello World Displaying Multiple Lines of Text with a Single Statement 2.3 Q2: Which of the following characters is the escape character? a. * b. \ c. \n d. " ANS: b. \ 2.3 Q3: Which of the following statements will print a single line containing "hello there"? a. System.out.println( "hello" ); System.out.println( " there" ); b. System.out.println( "hello", " there" ); c. System.out.println( "hello" ); System.out.print( " there" ); d. System.out.print( "hello" ); System.out.println( " there" ); ANS: d. System.out.print( "hello" ); System.out.println( " there" ); 2.3 Q4: Which of the following escape sequences represents carriage return? e. \n. f. \r. g. \cr.

h. \c. ANS: b. \r. 2.3 Q4: Which of the following statements would display the phase Java is fun? a. System.out.println( "hellois fun\rjava " ); b. System.out.println( 'Java is fun' ); c. System.out.println( "\"Java is fun\"" ); d. System.out.println( Java is fun ); ANS: a. System.out.println( "hellois fun\rjava " ); Section 2.4 Displaying Text with printf 2.4 Q1: When method printf requires multiple arguments, the arguments are separated with. a. colons (:). b. semicolons (;). c. commas (,). d. periods (.). ANS: c. commas (,). 2.4 Q2: Which of the following statement displays Hello World? a. System.out.printf( "%2s", "Hello " "World" ); b. System.out.printf( "%s %s", "Hello", "World" ); c. System.out.printf( "%s%s", "Hello, World" ); d. System.out.printf( "s% s%", "Hello", "World" ); ANS: b. System.out.printf( "%s %s", "Hello", "World" ); Section 2.5 Another Java Application: Adding Integers 2.5 Q1: All import declarations must be placed a. inside the class declaration s body. b. before the class declaration. c. after the class declaration. d. all of the above will work. ANS: b. before the class declaration. 2.5 Q2: Which of the following is a variable declaration statement? a. int total; b. import java.util.scanner; c. public static void main( String args[] ) d. // first string entered by user ANS: a. int total; 2.5 Q3: A(n) enables a program to read data from the user.

a. printf. b. import declaration. c. Scanner. d. main. ANS: c. Scanner. 2.5 Q4: Which of the following is not a Java primitive type? a. char b. byte c. real d. double ANS: c. real 2.5 Q5: The format specifier is a place-holder for an int value? a. %a. b. %d. c. %int. d. %s. ANS: b. %d. Java API Documentation ( none ) Section 2.6 Memory Concepts 2.6 Q1: Which of the following statements does not alter a memory location? a. int a; b. number = 12; c. y = y + 2; d. width = Integer.parseInt(input); ANS: a. int a; Section 2.7 Arithmetic 2.7 Q1: What is the value of result after the following Java statements execute? int a, b, c, d, result; a = 4; b = 12; c = 37; d = 51; result = d % a * c + a % b + a; a. 119 b. 51 c. 127

d. 59 ANS: a. 119 2.7 Q2: List the following operators in the order that they will be evaluated: -, *, /, +, %. Assume that if two operations have the same precedence, the one listed first will be evaluated first. a. +, -, /, *, %. b. -, +, %, *, /. c. -, *, %, +, /. d. *, /, %, -, +. ANS: d. *, /, %, -, +. 2.7 Q3: Which of the following is not an arithmetic operator? a. + b. - c.. d. % ANS: c.. Section 2.8 Decision Making: Equality and Relational Operators 2.8 Q1: What will be output after the following Java statements have been executed? int a, b, c, d; a = 4; b = 12; c = 37; d = 51; a. a < b b. a < b d <= c c. a > b d. a < b c < d a!= b ANS: a. a < b if ( a < b ) System.out.println( "a < b" ); if ( a > b ) System.out.println( "a > b" ); if ( d <= c ) System.out.println( "d <= c" ); if ( ) System.out.println( "" );

2.8 Q2: Which of the following is not a syntax error? a. Neglecting to initialize a local variable in a method before it is used. b. Using a single equals sign instead of a double equals sign in the condition of an if statement. c. Placing a semicolon at the end of the first line of an if statement. d. Omitting the left and right parenthesis for the condition of an if statement. ANS: c. Placing a semicolon at the end of the first line of an if statement. 2.8 Q3: Each of the following is a relational or equality operator except: a. <= b. =! c. == d. > ANS: b. =! Section 2.9 (Optional) Software Engineering Case Study: Examining the Requirements Document Requirements Document ( none ) Analyzing the ATM System 2.9 Q1: Which of the following is the first stage of the software life cycle? a. design. b. implementation. c. requirements gathering. d. analysis. ANS: c. requirements gathering. Use Case Diagrams 2.9 Q2: The use case diagram models. a. the interactions between a system s client and its use case. b. each software life cycle stage in succession. c. each software life cycle by repeating one or more stages several times via use cases. d. the interactions between implementations and testing. ANS: a. the interactions between a system s client and its use case. 2.9 Q3: Which of the following is not an actor of the ATM system? a. A user who views an account balance. b. A user who provides requirements for building the ATM system.

c. A user who withdraws cash from the ATM. d. A user who deposits funds into the ATM. ANS: b. A user who provides requirements for building the ATM system. Designing the ATM System 2.9 Q4: Which diagram models system structure? a. State machine diagram. b. Class diagram. c. Activity diagram. d. Sequence diagram. ANS: b. Class diagram. 2.9 Q4: Which diagram is also called a collaboration diagram. a. State machine diagram. b. Communication diagram. c. Activity diagram. d. Sequence diagram. ANS: b. Communication diagram.