COP 2258 EXAM 1

Ace your homework & exams now with Quizwiz!

switch label

"Case" + constant which labels a code segment

remainder assignment

%=

multiplication assignment

*=

Preincrement

++var increase var by 1, and use the new var value in the statement int j = ++i // j is 2, i is 2

addition assignment

+=

predecrement

--var decrement var by 1, and use the new var value in the statement int j = --i; //j is 0, i is 0

subtraction assignment

-=

What does a computer consists of

-CPU -Memory -Hard drive -Floppy disk -Monitor -Printer -Communication devices

What is a class?

-a description of the representation of a specific kind of object, in terms of data and behavior -data class- data: month, day, year. operations to set and return month, day, year

what is a programming language?

-a language with strict grammatical rules, symbols, and special words used to construct a computer program

machine languages

-a set of primitive instructions built into every computer -instructions in form of binary code -program with native machines language is a tedious process

what is a program?

-an algorithm written for a computer that defines classes of objects and orchestrates their interactions to solve a problem -objects work together to create an application (or program) that solves a problem

what is an object?

-an instance of a class - a date object: June, 23, 2004

problem-solving phase

-analyze the problem and specify what the solutions must do -develop a general solution to solve the problem -verify that your solution really solves the problem

&&

-and -p && q mean p and q -p && q is true if both p and q are true; false otherwise

Anatomy of a Java Program

-class name -the main method -statements -statement terminator -reserved words -comments -blocks

Java is Dynamic

-designed to adapt to evolving environment -new code can be loaded on the fly without recompilation -no need for developers to create, and for users to install, major new software versions -new features can be incorporated transparently as needed

assembly language

-developed to make programming easy -computer cannot understand assembly language, however, a program called assembler is used to convert assembly language programs into machine code

^

-exclusive or -p^q means p exclusive or q -p^q is true when exactly one is true; false otherwise

reserved words

-import -public class -public static void main -system.out.println -int -Scanner -New Scanner(System.in) -.nextInt

characteristic of java

-java is simple -java is object-oriented -java is distributed -java is interpreted -java is robust -java is secure -java is architecture-neutral -java is portable -java's performance -java is multithreaded -java is dynamic

!

-not -!P means not P -!p is false if p is true -!p is true is p is false

||

-or -p || q means p or q -p||q is true if either p or q or both are true; false otherwise

Java is Simple

-partially modeled on C++ but greatly simplified and improved -like C++ but with more functionality and fewer negative aspect

Memory

-store data and program instructions for CPU to execute -a program and its data must be brought to memory before they can be executed -the current content of a memory byte is lost whenever new information is placed in it

Implementation Phase: Test

-testing means executing (running) your program on the computer, to see if it produces correct results -if it does not, check the algorithm and/or code to find the error and fix it -finding known errors is called debugging

CPU

-the central processing unit is the brain of a computer -it retrieves instructions from memory and executes them

break

-the keyword break is optional, but is should be used at the end of each case in order to terminate the remainder of the switch statement -if the break statement is not present, the next case statement will be executed

what is code?

-the product of translating an algorithm into a programming language -instructions for a computer that are written in a programming language

Maintenance phase

-use and modify the program to meet changing requirement or correct errors that show up in using it -maintenance begins when your program is put into use and accounts for the majority of effort on most programs

Java is architecture-neutral

-write once, run anywhere -with JVM, you can write one program that will run on any platform

double floor

-x is rounded down to its nearest integer -this integer is returned as a double value

double ceil

-x rounded up to the its nearest integer -this integer is returned as a double value

Java is interpreted

-you need an interpreter to run java programs -the programs are compiled into the JVM code called bytecode -bytecode is machine-independent and can run on any machine that has a java interpreter

Variable declaration

//declare age to be an integer variable int age; //declare radius to be a double radius double radius;

comments

//delcare variables

Prompt user for input

//prompt user for their age System.out.print("Please enter your age: ");

read the input and use the input

//read the users age age = input.nextInt();

division assignment

/=

Programming Life Cycle

1) Problem-solving -Analysis and Specification -General Solution -Verify 2) Implementation -Concrete Solution (code) -Test 3) Maintenance -Use -Maintain

steps for creating, running, and compiling a program

1. create a new files entitled: ProgrammingQuote.java 2. write a program source code that will print to the console System.out.print("Quote"); 3. compile the program in terminal using command: javac ProgrammingQuote.java 4. run/execute the program in the terminal using command: java ProgrammingQuote

How to use the Scanner class

1: import the Scanner 2: create scanner object 3: prompt user for input 4: read input and use the input

Statements & Statement Terminator

;

primitive data types

Integer Java Data Types -byte (1) -Short (2) -int (4) -long (8) Floating Java Data Types -float (4) -double (8) Textual Java Type -char (2) Logical Java Data Type -Boolean (1) (T/F)

How java compiles and interpets code

Java IDE -> Source code (*.java files) -> java compiler -> bytecodes (*.class files) ->Java virtual machine <--> operating system

create scanner object

Scanner input = new Scanner(System.in);

package

a collection of related classes

compiling source code

a compiler translate the entire source code into a machine-code file, and the machine-code file is then executed

compiler

a compiler translates a program from a high-level language to a low-level language the computer can run

interpreting source code

a interpreter reads one statement from the source code, translates it to the machine code or virtual machine code, and then executes it right away

Boolean data type

a primitive type consisting of just two values, the constants are true and false

Operating System (OS)

a program that manages and controls a computers activities ex. microsoft windows, mac os, linux

switch statement

a selection control structure for multiway branching

Sequence

a series of statements that executes one after another

control structure

a statement used to alter the normally sequential flow of control

Variable initialization

age = 23; //assign 1 to x; radius = 1.5;// assign 1.5 to radius;

logical expression

an expression made up of boolean values and logical operations that evalutes to true or false

Java Virtual Machine (JVM)

an interpreter program that translates each successive instruction in the bytecode program to machine language and immediately runs it

case labels

are constant expressions; several case labels can we associated with a statement

subprogram/subroutine

breaks the program into smaller units

high-level languages

english-like and easy to learn and program

Selection(branch)

executes different statements depending on certain conditions

named constants

final datatype CONSTANTNAME = VALUE; final double PI= 3.14159; final int SIZE = 3;

import scanner

import java.util.Scanner;//import only the scanner class or import java.util.*;//import all classes in java.util

Algorithm

instructions for solving a problem in a finite amount of time using a finite amount of data

declaring and initializing in one step

int age = 15 double d = 1.4;

default case

is optional and is used to perform actions when none of the specified cases matches in the switch-expression

What is computer programming?

it is the process of specifying the data types and the operations for a computer to apply to data in order to solve a problem

Java is secure

java implements several security mechanisms to protect your system against harm caused by stray programs

Java is Object-Oriented

object-oriented programming provides great flexibility, modularity, clarity, and reusability through encapsulation, inheritance, and polymorphism

class name

public class FirstProgram { firstprogram is class name

the main method

public static voide main(String[] args) {

Loop

repeats statements while certain conditions are met

random ()

returns a random double value in the range [0.0,1.0)

abs (a)

returns the absolute value of the parameter

max (a,b) and min (a,b)

returns the maximum or minimum of two parameters

switch expression

the integral expression whose value determines which switch label is selected

byte-code

the machine language for a hypothetical computer called the Java Virtual Machine

flow of control

the order in which the computer executes statements

instantiation

the process of creating an object based on the description provided by a class

data type

the specification in a programming language of how information is represented as data and the operations that can be performed on the data

Java is portable

they can be run on any platform without being recompiled

explicit casting

type narrowing

implicit casting

type widening

increment and decrement operators

using increment and decrement operators makes expressions short, but it also makes them complex and difficult to read

postincrement

var++ increase var by 1 int j = i++; //j is 1, i is 2

postdecrement

var-- decrement var by 1, and use the original var value in the statement int j = i-- //j is 1,i is 0

double rint

x is rounded to its nearest integer -if x is equally close to two integers, the even one is returned as a double

source program/ source code

you compile a program by running the compiler on the high-level language version of the program called the source program

blocks

{ }


Related study sets

HK: Motor Learning and Performance (Chapter 10)

View Set

Midterm Exam Questions // Smith // Ole Miss

View Set

Pharm, Chapter 51: Breast Disorders, Chapter 27: Lower Respiratory Problems, Chapter 54: Male Reproductive Problems, Chapter 15: Cancer, Nurs 342 Test #1 - Ch. 15 - Cancer - Evolve NCLEX practice, Nurs 342 Test #1 - Ch. 15- Cancer - Lewis 10th ed. pr...

View Set

Pre-Lecture Chapter 7 General Chemistry 1

View Set