1.A computer game is an example of A.system software; B.a compiler; C.application software; D.hardware; E.none of the above. 2.JVM stands for: A.Java Virtual.

Slides:



Advertisements
Similar presentations
Topic Reviews For Unit ET156 – Introduction to C Programming Topic Reviews For Unit
Advertisements

Designing a Program & the Java Programming Language
AP Computer Science Anthony Keen. Computer 101 What happens when you turn a computer on? –BIOS tries to start a system loader –A system loader tries to.
Basic Java Constructs and Data Types – Nuts and Bolts
1 Arrays, Strings and Collections [1] Rajkumar Buyya Grid Computing and Distributed Systems (GRIDS) Laboratory Dept. of Computer Science and Software Engineering.
1 Exceptions: An OO Way for Handling Errors Rajkumar Buyya Grid Computing and Distributed Systems (GRIDS) Laboratory Dept. of Computer Science and Software.
10 Copyright © 2005, Oracle. All rights reserved. Reusing Code with Inheritance and Polymorphism.
0 - 0.
Introduction to arrays Array One dimenstional array.
Introduction to Programming
Lecture 10 Flow of Control: Loops (Part 2) COMP1681 / SE15 Introduction to Programming.
Lilian Blot 11 Spring 2014 TPOP 1. Lilian Blot 22 Spring 2014 TPOP 2.
Procedural Programming in C# Chapters Objectives You will be able to: Describe the most important data types available in C#. Read numeric values.
Classes and Objects. What is Design? The parts of the software including – what information each part holds – what things each part can do – how the various.
1 Lecture 16/3/11: Contents Example of an array of user-defined objects: Car and Carr Constructor Providing functionalities for a user- defined object.
Programming Methodology (1). public class Hello { public static void main(String[] args) { System.out.println("Hello world"); } } Hello world.
1 public class Newton { public static double sqrt(double c) { double epsilon = 1E-15; if (c < 0) return Double.NaN; double t = c; while (Math.abs(t - c/t)
Chapter 8: Arrays.
EXAMPLES (Arrays). Example Many engineering and scientific applications represent data as a 2-dimensional grid of values; say brightness of pixels in.
Programming Methodology (1). Implementing Methods main.
1 Arrays An array is a special kind of object that is used to store a collection of data. The data stored in an array must all be of the same type, whether.
1 Review Quisioner Kendala: Kurang paham materi. Praktikum Pengaruh teman.
Purpose : To convert this string to a new character array. Return Type : char[ ] Parameters : none Declaration : public char[ ] toCharArray() Returns.
Chapter 5 Loops Liang, Introduction to Java Programming, Tenth Edition, (c) 2015 Pearson Education, Inc. All rights reserved.
Addition 1’s to 20.
IT 325 OPERATING SYSTEM C programming language. Why use C instead of Java Intermediate-level language:  Low-level features like bit operations  High-level.
Loops –Do while Do While Reading for this Lecture, L&L, 5.7.
Types of selection structures
Computer Programming Lab(7).
Building Java Programs Interactive Programs w/ Scanner What is a class? What is an object? What is the difference between primitive and object variables?
Introduction to Programming G51PRG University of Nottingham Revision 1
Lecture 8 Instructor: Craig Duckett. Assignments TONIGHT Lecture 8 Assignment 2 Due TONIGHT Lecture 8 by midnight Monday, February 2 nd Lecture 10 Assignment.
Today’s lecture Review of Chapter 1 Go over homework exercises for chapter 1.
Chapter 3 Flow of Control Copyright © 2010 Pearson Addison-Wesley. All rights reserved.
Liang, Introduction to Java Programming, Eighth Edition, (c) 2011 Pearson Education, Inc. All rights reserved Chapter 3 Loops.
Air Force Institute of Technology Electrical and Computer Engineering
Core Java Lecture 4-5. What We Will Cover Today What Are Methods Scope and Life Time of Variables Command Line Arguments Use of static keyword in Java.
Craps. /* * file : Craps.java * file : Craps.java * author: george j. grevera, ph.d. * author: george j. grevera, ph.d. * desc. : program to simulate.
1 pritisajja.info Unlocking the World of Java Programming….. Priti Srinivas Sajja February, 2014 Visit pritisajja.info for detail Future Technology for.
MSc IT Programming Methodology (2). number name number.
Computer Programming Lab 8.
CS1010 Programming Methodology
Loops – While, Do, For Repetition Statements Introduction to Arrays
© The McGraw-Hill Companies, 2006 Chapter 5 Arrays.
Random (1) Random class contains a method to generate random numbers of integer and double type Note: before using Random class, you should add following.
1 Chapter 2 Introductory Programs. 2 Getting started To create and run a Java program –Create a text file with a.java extension for the source code. For.
CS107 Introduction to Computer Science Java Basics.
1 The First Step Learning objectives write Java programs that display text on the screen. distinguish between the eight built-in scalar types of Java;
Principles of Computer Programming (using Java) Review Haidong Xue Summer 2011, at GSU.
CS107 Introduction to Computer Science Java Basics.
© The McGraw-Hill Companies, 2006 Chapter 4 Implementing methods.
Java Programming: From the Ground Up
By Nicholas Policelli An Introduction to Java. Basic Program Structure public class ClassName { public static void main(String[] args) { program statements.
Arrays and ArrayLists in Java L. Kedigh. Array Characteristics List of values. A list of values where every member is of the same type. Each member in.
Hello.java Program Output 1 public class Hello { 2 public static void main( String [] args ) 3 { 4 System.out.println( “Hello!" ); 5 } // end method main.
Using Data Within a Program Chapter 2.  Classes  Methods  Statements  Modifiers  Identifiers.
Introduction to Java Java Translation Program Structure
Loops (cont.). Loop Statements  while statement  do statement  for statement while ( condition ) statement; do { statement list; } while ( condition.
BEGINNING PROGRAMMING.  Literally – giving instructions to a computer so that it does what you want  Practically – using a programming language (such.
Review TEST 2 Chapters 4,5,7. QUESTION For which type of operands does the == operator always work correctly: (a) int, (b) double, or (c) String?
Spring 2009 Programming Fundamentals I Java Programming XuanTung Hoang Lecture No. 8.
Review A program is… a set of instructions that tell a computer what to do. Programs can also be called… software. Hardware refers to… the physical components.
Information and Computer Sciences University of Hawaii, Manoa
Basic concepts of C++ Presented by Prof. Satyajit De
CSC111 Quick Revision.
Data types and variables
Control Statement Examples
Focus of the Course Object-Oriented Software Development
CS 101 First Exam Review.
Peer Instruction 4 Control Loops.
Presentation transcript:

1.A computer game is an example of A.system software; B.a compiler; C.application software; D.hardware; E.none of the above. 2.JVM stands for: A.Java Virtual Machine; B.Java Verified Machine; C.Java Voice Machine; D.Java Void Machine ; E.none of the above. 3.Which one of the following statements is true? A.Java is the only object-oriented programming language; B.Java programs can be run only on a PC - not an Apple Mac; C.Java is one of many object-oriented programming languages; D.Java does not allow you to write object-oriented programs; E. none of the above.

4.Which of the following is NOT a primitive Java data type? A.char; B.boolean; C.double; D.String; E.int. 5.Consider the following Java program and then choose the correct statement from the list that follows: public class Q5 { public static void main(String[] args) { System.out.print("Apple ") System.out.print("Lemon") } A.this program contains more than one syntax error; B.this program contains one and only one syntax error; C.this program compiles successfully and produces the following output: Apple Lemon D.this program compiles successfully and produces the following output: Apple Lemon E.none of the above.

6.Consider the following Java program and then choose the correct statement from the list that follows: public class Q6 { public static void main(String[] args) { System.out.print("I love programming in "); System.out.println("Java"); } A.this program contains more than one syntax error; B.this program contains one and only one syntax error; C.this program compiles successfully and produces the following output: I love programming inJava D.this program compiles successfully and produces the following output: I love programming in Java E.this program compiles successfully and produces the following output: I love programming in Java

7.Consider the following Java instruction that declares a variable to store the total number of students taking an exam: int student_total; Which one of the following statements is true? A.this variable declaration is not valid Java syntax ; B.the type int can be used only to store numbers greater than zero ; C.it would have been better to use the type double here; D.using the type double here instead of int would cause a compiler error; E.none of the above.

8.Consider the following Java program and then choose the correct statement from the list that follows: public class AnyProg { public static void main (String[] args) { int x, y; x = 5; x++; y = x; x = x + 3; System.out.println ("the value of y is " + y); } A. this program compiles successfully and produces the following output: the value of y is 9 B. this program contains at least one syntax error ; C. this program compiles successfully and produces the following output: the value of y is 6 D. this program compiles successfully and produces the following output: the value of y is + y E. this program compiles successfully and produces the following output: the value of y is 5

9.Consider the following two Java programs and then choose the correct statement from the list that follows: public class Prog1 { public static void main (String[] args) { int num; num = 10; System.out.print(num + " divided by " + num + " = " + (num/num)); } public class Prog2 { public static void main (String[] args) { System.out.print(10 + " divided by " " = " + (10/10)); }

A.program 1 does not compile but program 2 compiles successfully and produces the following output: 10 divided by 10 = 1 B.both program 1 and program 2 compile successfully and produce the following output: 10 divided by 10 = 1 C.program 2 does not compile but program 1 compiles successfully and produces the following output: 10 divided by 10 = 1 D.neither program compiles successfully; E.both programs compile successfully but produce different output.

10.Consider the following program: import java.util.*; public class Q10 { public static void main(String[] args) { int x; Scanner sc = new Scanner(System.in); System.out.print("Enter a number: "); x = sc.nextInt(); if (x > 10) { System.out.println("Liverpool"); } else { System.out.println("Chelsea"); } System.out.println(“Arsenal"); } What would be the output from this program once the user enters 10 when prompted? A.Chelsea Arsenal B.Liverpool Arsenal C.Arsenal D.Chelsea E.none of the above.

11.Consider the following program: import java.util.*; public class Q11 { public static void main (String[] args) { Scanner sc = new Scanner(System.in); int choice; System.out.println("enter choice"); choice = sc.nextInt(); switch (choice) { case 1: System.out.println("Gum"); break; case 2: System.out.println("Coke"); default: System.out.println("Error"); } System.out.println("Goodbye"); } If this program is run and the user enters 2 when prompted for a choice, which one of the following statements is true? A.the program displays the following messages before terminating: Gum Goodbye B.the program displays the following messages before terminating: Coke Goodbye C.the program displays the following messages before terminating: Coke Error Goodbye D.the program will crash; E.none of the above.

12.Consider the following Java program and then choose the correct statement from the list that follows: public class Q12 { public static void main (String[] args) { for (int i = 1; i < 7; i = i + 2) { System.out.println("*"); } A.this program compiles successfully and produces the following output: ***** B.this program compiles successfully and produces the following output: * * * * C.this program compiles successfully and produces the following output: *** D.this program compiles successfully and produces the following output: * * * E.this none of the above.

13.Assume that the user of a program is asked to enter a day number (1-7) into an integer variable called day. Assuming a Scanner object, sc, has been created, which one of the following while loops can then be used to validate the day entered? A.while (day >= 1 || day <= 7) { System.out.print("ERROR only, enter again: "); day = sc.nextInt(); } B.while (day >= 1 && day <= 7) { System.out.print("ERROR only, enter again: "); day = sc.nextInt (); } C.while (day = 7) { System.out.print("ERROR only, enter again: "); day = sc.nextInt (); } D.while (day > 1 && day < 7) { System.out.print("ERROR only, enter again: "); day = sc.nextInt (); } E.while (day 7) { System.out.print("ERROR only, enter again: "); day = sc.nextInt (); }

14.Consider the following program, and then choose the correct statement from those that follow. public class Q14 { public static void main(String[] args) { int x, result; x = 4; result = 0; result = myMethod(x); System.out.println(result); } private static int myMethod(int numIn) { return 3 * numIn; } A.this program will not compile; B.this program compiles properly and produces the following output: 12 C.this program compiles properly and produces the following output: 0 D.this program compiles properly and produces the following output: 7 E.none of the above.

15.Consider the following program, and then choose the correct statement from those that follow. public class Q15 { public static void main(String[ ] args) { int x, y; x = 4; y = 0; y = myMethod( ); System.out.println(y); System.out.println(x); } private static int myMethod(int x) { return 2 * x; } A.this program will not compile; B.this program compiles properly and produces the following output: 8 4 C.this program compiles properly and produces the following output: 0 4 D.this program compiles properly and produces the following output: y x E.none of the above:

16.Polymorphism means: A.declaring all the methods of a class as public; B.hiding of information so that it is not accessible to other classes; C.having methods or operators with the same name performing different functions; D.declaring all the attributes of a class as private; E.none of the above. 17.Which of the following statements is true of an array? A.the length of an array can be changed after the array has been created; B.the length of an array can be changed while the program is running; C.an array cannot hold items of mixed type; D.an array cannot be passed to a method; E.none of the above.

18.Consider the following explicit creation of an array and then choose the correct statement from the list that follows int[] someArray = { 12, 23, 7, 11, 10, 32 }; A.the value of someArray.length is 5; B.the value of someArray[2] is 23; C.an array cannot be created this way in Java; D.the value of someArray[11] is 4; E.none of the above.

19. Consider the following Java program import java.util.*; public class Q19 { public static void main (String[] args) { Scanner sc = new Scanner(System.in); int[ ] mark = new int[5]; for(int i = 0; i <= 5; i++) { System.out.print("Enter mark "); mark[i] = sc.nextInt(); } Which one of the following statements is true of the program above: A.this program will crash while it is running; B.this program cannot run as it contains one and only one syntax error; C.this program cannot run as it contains more than one syntax error; D.this program runs without crashing and allows 5 marks to be entered; E.this program runs without crashing and allows only 4 marks to be entered.

20.Consider the following creation of an array, name, to store a list of names: String[] name = new String[25]; Which of the following is the correct way of entering the name “Faith” into the last position of the array? A.name.last = [“Faith”]; B.name[24] = “Faith”; C.name[25] = “Faith”; D.name.length = “Faith”; E.none of the above.

21. Consider the Employee class shown in the UML diagram below: Employee name : String address : String phone : String yearOfBirth : int Employee(String, String, String, int) setAddress(String) getName() : String getAddress() : String getPhone() : String getYearOfBirth() : int calculateAge(int) : int Assuming that this class is accessible to the Java compiler, which of the following statements would NOT result in a compiler error? A.Employee emp1 = new Employee ("845", "5034", "0101", 0); B.Employee emp1 = new Employee ("Patel", "Essex", " ", "1970"); C.Employee emp1 = new Employee ("Patel", "Essex", "1970"); D.emp1 Employee = new Employee ("Patel", "Essex", " ", 1970); E.Employee emp1 = new Employee ("Patel", Essex, , 1970);

Employee name : String address : String phone : String yearOfBirth : int Employee(String, String, String, int) setAddress(String) getName() : String getAddress() : String getPhone() : String getYearOfBirth() : int calculateAge(int) : int 22.Assuming that an object called emp1, of the Employee class in question 21, has already been created, which of the following statements would cause the address of emp1 to be displayed on the screen? A.System.out.print(address); B.System.out.print(emp1.Address); C.System.out.print(emp1.getAddress()); D.System.out.print(emp1.getAddress); E.System.out.print(getAddress());

23.Study the following program (which assumes that the Employee class is accessible to the compiler), and then choose the correct statement from those that follow: public class EmployeeTester { public static void main(String[] args) { Employee emp = new Employee("Mary", "London", " ", 1981); System.out.print(emp.calculateAge(2006)); } A.the above program will not compile; B.the above program compiles successfully and results in the following output: The employee's age is 25 C.the above program compiles successfully and results in the following output: Mary's age is 25 D.the above program compiles successfully and results in the following output: 25 E.the above program compiles successfully and results in the following output: 24

public class SomeClass { private int one; private int two; public SomeClass() { one = 2; two = 4; } public SomeClass(int x, int y) { one = x; two = y; } public void setOne(int x) { one = x; } public void setTwo(int x) { two = x; } public void equalize() { one = two; } public int calcSum() { return (one + two); } public int calcDiff() { return (two - one); } 24.Consider the following program which uses SomeClass (as defined above), and choose the correct statement from those that follow: public class SomeProg { public static void main(String[] args) { SomeClass myClass = new SomeClass(); myClass.equalize(); System.out.print(myClass.calcSum()); } A.the program will not compile successfully; B.the program compiles successfully and produces an output of 4; C.the program compiles successfully and produces an output of 2; D.the program compiles successfully and produces an output of 8; E.the program compiles successfully and produces an output of 6.

public class SomeClass { private int one; private int two; public SomeClass() { one = 2; two = 4; } public SomeClass(int x, int y) { one = x; two = y; } public void setOne(int x) { one = x; } public void setTwo(int x) { two = x; } public void equalize() { one = two; } public int calcSum() { return (one + two); } public int calcDiff() { return (two - one); } 25.Consider the following program which uses SomeClass (as defined above), and choose the correct statement from those that follow: public class SomeProg { public static void main(String[] args) { SomeClass myClass = new SomeClass(3, 2); myClass.setTwo(1); System.out.print(myClass.calcDiff()); } A.the program will not compile successfully; B.the program compiles successfully and produces an output of 2; C.the program compiles successfully and produces an output of -1; D.the program compiles successfully and produces an output of 1; E.the program compiles successfully and produces an output of -2.