Java Module Lesson 2A Practice Exercise

Similar documents
Lesson 2A Data. Data Types, Variables, Constants, Naming Rules, Limits. A Lesson in Java Programming

OWEN COMPUTER SCIENCE LESSONS L2RVW4 Pg 1. Lesson 2 Review #4. Matching. Match each description to the correct data type.

An Introduction to Processing

Ex: If you use a program to record sales, you will want to remember data:

The type of all data used in a C++ program must be specified

Day 3. Storage Devices + Types of Memory + Measuring Memory + Computer Performance

Intro to Computers in Arabic!!!!! MAI ELSHEHALY

The type of all data used in a C (or C++) program must be specified

Using sticks to count was a great idea for its time. And using symbols instead of real sticks was much better.

Jones and Bartlett Publishers. NOT FOR SALE OR DISTRIBUTION CHAPTER. Programming Building Blocks Java Basics

The Mathematics of Big Data

BASIC ELEMENTS OF A COMPUTER PROGRAM

Lecture 2: Variables and Operators. AITI Nigeria Summer 2012 University of Lagos.

Accelerating Information Technology Innovation

Data types Expressions Variables Assignment. COMP1400 Week 2

Variables, Constants, and Data Types

Datatypes, Variables, and Operations

COMP Computer Basics. Yi Hong May 13, 2015

Module 1: Information Representation I -- Number Systems

REVIEW. The C++ Programming Language. CS 151 Review #2

LESSON 2 VARIABLES, OPERATORS, EXPRESSIONS, AND USER INPUT

Zheng-Liang Lu Java Programming 45 / 79

Variables. Store information needed by the program

DEPARTMENT OF MATHS, MJ COLLEGE

2.1. Chapter 2: Parts of a C++ Program. Parts of a C++ Program. Introduction to C++ Parts of a C++ Program

Chapter 2: Introduction to C++

Variables and Functions. ROBOTC Software

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

Starting with a great calculator... Variables. Comments. Topic 5: Introduction to Programming in Matlab CSSE, UWA

Data and Variables. Data Types Expressions. String Concatenation Variables Declaration Assignment Shorthand operators. Operators Precedence

Introduction to Programming EC-105. Lecture 2

Basics of Java Programming

Basic data types. Building blocks of computation

Introduction to Java Applications

Fundamentals of Programming CS-110. Lecture 2

Expressions and Data Types CSC 121 Spring 2015 Howard Rosenthal

Java Basic Datatypees

1 class Lecture2 { 2 3 "Elementray Programming" / References 8 [1] Ch. 2 in YDL 9 [2] Ch. 2 and 3 in Sharan 10 [3] Ch.

Introduction to the C++ Programming Language

Electronic Data and Instructions

Today. o main function. o cout object. o Allocate space for data to be used in the program. o The data can be changed

Reserved Words and Identifiers

Informatics 1. Lecture 1: Hardware

Introduction to the Mathematics of Big Data. Philippe B. Laval

b A bit is the basic unit for storing electronic data, for example an MP3 file. The term bit is a

Software and Programming 1

Key Differences Between Python and Java

Lecture 2 Tao Wang 1

Object-Oriented Programming

Expressions and Data Types CSC 121 Fall 2015 Howard Rosenthal

BIT Java Programming. Sem 1 Session 2011/12. Chapter 2 JAVA. basic

Computer Programming : C++

Discovering Computers 2008

UNIT - I. Introduction to C Programming. BY A. Vijay Bharath

(CONDITIONALS_BOUNDARY)

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

Computational Expression

CS242 COMPUTER PROGRAMMING

Getting started with Java

CP122 Computer Science I. Chapter 2: Data Types, Variables, and I/O

Fall 2017 CISC124 9/16/2017

CS 106 Introduction to Computer Science I

Exercise: Using Numbers

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

LECTURE 02 INTRODUCTION TO C++

Hello, World and Variables

Experimental Methods I

Computers and Programming Section 450. Lab #1 C# Basic. Student ID Name Signature

Starting Out with Java: From Control Structures through Data Structures 3e (Gaddis and Muganda) Chapter 2 Java Fundamentals

Computer Systems. IGCSE OCR AQA Edexcel Understand the term. embedded system and how an Purpose of embedded system

3. Except for strings, double quotes, identifiers, and keywords, C++ ignores all white space.

AP Computer Science A

Chapter 2. C++ Basics. Copyright 2014 Pearson Addison-Wesley. All rights reserved.

Chapter 2. C++ Basics

CST112 Variables Page 1

Chapter 2. C++ Basics. Copyright 2014 Pearson Addison-Wesley. All rights reserved.

data within a computer system are stored in one of 2 physical states (hence the use of binary digits)

Basic Programming Elements

CSc 10200! Introduction to Computing. Lecture 2-3 Edgardo Molina Fall 2013 City College of New York

Lecture 2. Examples of Software. Programming and Data Structure. Programming Languages. Operating Systems. Sudeshna Sarkar

Language Reference Manual

Program Fundamentals

What did we talk about last time? Examples switch statements

Storage. Chapter3 ITBIS105

Decisions in Java IF Statements

Chapter 2: Using Data

Full file at

DATA 301 Introduction to Data Analytics Data Representation. Dr. Ramon Lawrence University of British Columbia Okanagan

4. If the following Java statements are executed, what will be displayed?

ST445 Managing and Visualizing Data. Introduction to Data. Week 1 Lecture, MT Kenneth Benoit

CSc Introduction to Computing

The C++ Language. Arizona State University 1

CP122 Computer Science I. Binary, Strings, Conditionals, User Input

A First Program - Greeting.cpp

CSCE 120: Learning To Code

JAVA Programming Fundamentals

Software and Programming 1

Values, Variables, Types & Arithmetic Expressions. Agenda

Review for COSC 120 8/31/2017. Review for COSC 120 Computer Systems. Review for COSC 120 Computer Structure

Chapter 1 INTRODUCTION

Transcription:

Java Module Lesson 2A Practice Exercise Name Completion Complete each sentence or statement. 1. The three main data types used in a typical Java program are:,, and. 2. In general, data types that are simple in nature are referred to as p, and more complex data types are called o. 3. The four main primitive data types are:,,, and. 4. The four other less used primitive data types are:,,, and. 5. The main object data type used so far is the S. 6. Describe the difference between Strings and chars, discussing length and symbols used. 7. List the five parts of a typical initialization statement,,,,, 8. Rewrite the following initialization statement as two separate statements: a declare and an assignment. int x = 5; ------------------------------ ; ; 9. Rewrite the following initialization statement as two separate statements: a declare and an assignment. double wage = 9.25; ------------------------------ ; ;

10. Fill in the blanks below with appropriate data about you. String name = ; int age = ; double wage = ; char initial = ; boolean smart = ; 11. A variable that is permanently assigned inside a program is called a and uses the word to indicate this. 12. The difference between a primitive and an object is that a primitive is a memory location that actually contains a, but an object is a memory location that contains the of a value. 13. List the absolute must rules for creating valid Java identifiers. 14. List the good idea rules for creating valid Java identifiers. 15. List the conventions, or commonly agreed upon rules for creating valid Java identifiers.

16. For what two word phrase is bit an abbreviation? 17. When the maximum or minimum value is exceeded by 1 in an outward direction, such as adding 1 to the maximum, or subtracting 1 from the minimum, this causes a computer phenomenon called. 18. When 1 is added to the maximum value of a data type, what value is the result of this? 19. When 1 is subtracted from the minimum value of a data type, what value is the result of this? 20. In general terms, the word transcendental refers to concepts, ideas, and beliefs that come to us from beyond our senses, things we cannot see, hear, touch, feel, or taste, but have a gut feeling about. Similarly, in mathematics, there are certain numbers that are referred to as transcendental numbers, in the fact that they are irrational (cannot be expressed as a ratio of discreet values), and highly significant in mathematics. Two well-known examples of these numbers are represented as the Java mathematical constants (the ratio of the circumference of a circle to its diameter) and (the base of the natural logarithms). True/False 21. final int x = 4; x = 5; 22. char a; a = 'a'; 23. first name 24. String word = 'hello'; 25. boolean flag = "true"; 26. int x = 45; 27. 5_star 28. FLAG 29. final char a = 'a'; 30. main 31. myname 32. final char a; a = 'a'; 33. $cost 34. double d; d = 4.5;

Matching Match each value with the correct Java constant. a. Byte.MIN_VALUE e. Byte.MAX_VALUE b. Short.MIN_VALUE f. Short.MAX_VALUE c. Integer.MIN_VALUE g. Integer.MAX_VALUE d. Long.MIN_VALUE h. Long.MAX_VALUE 35. -9223372036854775808 36. Long.MAX_VALUE+1 37. -32768 38. -128 39. Short.MAX_VALUE+1 40. Integer.MAX_VALUE+1 41. Integer.MIN_VALUE-1 42. 127 43. Byte.MAX_VALUE+1 44. 2147483647 45. Long.MIN_VALUE-1 46. 9223372036854775807 47. 32767 48. Byte.MIN_VALUE-1 49. -2147483648 50. Short.MIN_VALUE-1

51. long 52. int 53. short 54. byte 55. char 56. double 57. float 58. byte 59. gigabyte 60. kilobyte 61. bit 62. exabyte 63. zettabyte 64. megabyte 65. terabyte 66. petabyte 67. yottabyte Match each data type with the number of memory storage bits required. a. 4 e. 64 b. 8 f. 128 c. 16 g. 256 d. 32 Match each abbreviation with the correct memory designation. a. b f. TB b. B g. PB c. KB h. EB d. MB i. ZB e. GB j. YB Match each given range or description to the correct data type. a. int e. short b. float f. long c. double g. char d. byte 68. -2147483648...2147483647 69. 0...65535 70. -128...127 71. approximately -9 quintillion...9 quintillion 72. -32768...32767 73. up to 15 decimal places of storage and output precision 74. up to 7 decimal places of storage and output precision

75. "Hello" 76. 0.28 77. 'A' 78. '9' 79. 3.4 80. 65 81. 100000 82. "true" 83. false 84. "B" Match each data value with the most appropriate Java data type. a. int d. boolean b. double e. String c. char

Java Module Lesson 2A Practice Exercise Key 1. int - integers double - decimals String - words and sentences 2. primitives objects 3. int, double, char, boolean 4. float, short, byte, long 5. String 6. chars are exactly one character and are enclosed in single quotes Strings can be zero or more characters long and are enclosed in double quotes. 7. data type, identifier, = sign, the value, semicolon 8. int x; x = 5; 9. double wage; wage = 9.25; 10. String name = "John Owen"; int age = 57; double wage = 54.65; char initial = 'B'; boolean smart = true; 11. A variable that is permanently assigned inside a program is called a constant and uses the word final to indicate this. 12. The difference between a primitive and an object is that a primitive is a memory location that actually contains a value, but an object is a memory location that contains the memory location of a value. 13. No magic Java reserved words Start with an underscore or a letter, but never a digit Use only letters, digits, and underscore, never symbols or spaces 14. Use descriptive names for variables Avoid single letters for important variables, ok for utility variables like loop control variables 15. Multiple words are separated by underscore, OR start with lowercase and capitalize any word after that Variables always start with lowercase letter Contants are always in all caps Class identifiers start with capital letters 16. binary digit 17. wraparound 18. The minimum value of that data type. 19. The maximum value of that data type. 20. Math.PI and Math.E

Java Module Lesson 2A Practice Exercise Key (cont.) TRUE/FALSE 21. F Once a constant (final) variable has been assigned within a program, it cannot be changed. 22. T 23. F Invalid - has a space 24. F 25. F 26. T 27. F Invalid - starts with a digit 28. T 29. T 30. F Invalid - reserved Java word 31. T 32. T 33. F Invalid - starts with a symbol 34. T MATCHING 35. D 36. D 37. B 38. A 39. B 40. C 41. G 42. E 43. A 44. G 45. H 46. H 47. F 48. E 49. C 50. F 51. E 52. D 53. C 54. B 55. C 56. E 57. D 58. B 59. E 60. C 61. A 62. H 63. I 64. D 65. F 66. G 67. J 68. A 69. G 70. D 71. F 72. E 73. C 74. B 75. E 76. B 77. C 78. C 79. B 80. A 81. A 82. E 83. D 84. E