CSC 116 - Exam 1

अब Quizwiz के साथ अपने होमवर्क और परीक्षाओं को एस करें!

<var>.indexOf("<string>");

Returns the first instance of the string indicated. String must be in quotation marks. Counting starts at 0 String x = "Raleigh"; System.out.println(x.indexOf("al")); output: 1

Object

A programming entity that contains states and behavior An object is an instance of a class

Declaration

A request to set aside a new variable with a given type and name int x; //this is declaring a variable

\t

Tab System.out.println("Hello\tWorld"); output: Hello World

Statement

Line of Code which contains a Declaration, Equation, or Initialization; Ends with a Semicolon An executable snippet of code that represents a complete command System.out.println("Hello World!");

Memory Address

Name for a main memory cell which can contain a byte of data

Identifier

Name used to identify and reference to Class, Method, and Variables int x = 2; x is the identifier.

printf

format strings int x = 3; int y = -17; System.out.printf("x is %d and y is %d!\n", x, y); // x is 3 and y is -17!

Math.toDegrees Math.toRadians

converts to degrees from radians and vice versa

Math.max

larger of two values

<=

less than or equal to

Math.floor

rounds down

Math.round

rounds to the nearest whole number

Math.ceil

rounds up

\\

Include backslash System.out.println("\\Hello World\\"); output: \Hello World\

\"

Include the double quotes in the string System.out.println("He said, \"Hello\""); output: He said, "Hello"

++

Increment Operator which increases the variable by 1

Math.abs

absolute value

byte short long float

1 byte 2 bytes 8 bytes 4 bytes

for loops

1. initialization 2. continuation test 3. update 4. body for (int i = 0; i < 5; i++){

Class Constants

A fixed value visible to the whole program. Allows for multiple methods to access the constant Must be written in a different way: public static final int x = 5;

Variable

A memory location with a name and a type that stores a value

String

A sequence of characters enclosed in double-quotes String str = new String("Hello World"); String str = "Hello World";

Expression

A simple value or a set of operations that produces a value

Algorithm

A step-by-step description of how to accomplish a task Sequence of steps Repetitive (Loops) Decisions (If-else)

Index

An integer used to specify a location in a sequence of values. Indexes are zero based so the first character in a string is 0!

+=

Augmented operator which performs Mathematical Addition on Numbers or Concatenation on Strings and Stores the value into the original variable

/=

Augmented operator which performs Mathematical Division and Stores the value into the original variable

%=

Augmented operator which performs Mathematical Modulus (Remainder) and Stores the value into the original variable

*=

Augmented operator which performs Mathematical Multiplication and Stores the value into the original variable

-=

Augmented operator which performs Mathematical Subtraction and Stores the value into the original variable

Bit

Binary Digit

Procedural Decomposition

Breaking down a problem into simpler parts by using methods that do a certain task. This is useful for doing repetitive tasks.

Logical Error

Bug in a program that allows the program to run but does not give the output that it needs error in algorithm

System.in

Class and Variable which is used to collect information from the Keyboard; Used in conjunction with "Scanner" method Scanner sc = new Scanner(System.in);

System.out

Class and Variable which is used to send information to the Screen; Provokes "Println" and "Print" System.out.println(); System.out.print();

Casting

Convert a data type to a different data type int k = 5; double p = (double) k;

Numeric Literals

Constant value which appears directly in a program as a digit; Integer Literals can be stored as Long by adding "L"; Double Literals can be stored as Float by adding "F"

Method (Function)

Construct which contains the statements within a program A program unit that represents a particular action or computation Two types ○ Static methods ○ Class methods

--

Decrement Operator which decreases the variable by 1

Class Method Instance Method

Dependent on the class s.length(); Scanner scr = new Scanner(System.in);

Class

Division of a Java Program, of which all programs must have at least one; Contains specific items called "objects" A unit of code that is the basic building block of Java programs. ● Every program in Java is a "class" Two types of programming ○ Procedural (like a recipe) ○ Object-oriented

void method

Does not return a value to the method call public static void <name> (){

Runtime Error

Error that occurs while the program is running spelling "main" wrong divide by 0

import java.util.Scanner;

Explicit Statement to import Scanner Class

<var>.substring(<index>, <index+1>)

Extracts a portion of the string from the given starting index and 1 plus the ending index

nextDouble()

Function used to collect the next Double input from the keyboard

nextFloat()

Function used to collect the next Float input from the keyboard

nextInt()

Function used to collect the next Integer input from the keyboard

nextLong()

Function used to collect the next Long input from the keyboard

nextShort()

Function used to collect the next Short input from the keyboard

Initialization

Giving a value to a variable at the same time that it is "declared" int x = 7;

Named Constants

Identifier which represents a variable storing a permanent value; Declaration must be preceded by "final"

import java.util.*;

Implicit Statement to import Scanner Class

Static Method

Independent of Class public static void getAverage(){ public static double average() { double x = 7.0; return x;

Scanner input = new Scanner(System.in);

Initialization Statement for new Scanner Instance

Translator

Interpreter which converts and runs one line of code at a time

Compiler

Interpreter which converts entire file at once javac HelloWorld.java

!=

Is not equal?

Programming Language

Languages understood by the computer; Used to create Computer programs, or software

Integer Division

Mathematical division which returns only the Whole number and truncates the Decimal

Floating Point Division

Mathematical division which returns the Whole number and the Decimal; Requires one Operator to be a Floating Point

Byte

Measurement of 8 bits

\n

New line System.out.println("Hello \nWorld"); output: Hello World

+ (Addition)

Operator which performs Mathematical Addition on Numbers and Concatenation on Strings

% (Remainder or Modulus)

Operator which returns the Remainder from performing Division on Numbers

=

Operator which stores the value on the right into the variable on the left

Java Virtual Machine

Program which executes Java Bytecode (i.e., code w/ .class extension)

Interpreter

Programming Tool which converts programs into binary code

Low- level Language

Programming language that is understood by the computer but not by the reader.

High-Level Language

Programming language which uses a series of statements to create programs; Uses language similar to English. Can be read by the reader but not the computer

return method

Returns a value to the method call. public static <type> <name>() { return x; }

Class Block

Section of code which is associated with a particular Class name

Method block

Section of code which is associated with a particular Method name

Comment

Section of code which is ignored by the Compiler; Used to leave messages to the programmer // or /**/

double <var> = <value>;

Stores a decimal value 8 bytes

int <var> = <value>;

Stores a whole number only 4 bytes

char <var> = '<string>'

Stores one character enclosed in single quotes char hello = 'h'; System.out.print(hello); output: h

>

Strictly greater than

<

Strictly less than

Syntax Error

The Java program is not able to read the code because of improper grammar. Caught by the compiler

Method Overloading

The ability to define two or more different methods with the same name but different method signatures

Evaluation

The process of obtaining the value of an expression

Escape sequences

Used to show things in double quotes such as quotation marks, backslash, new line, tab. Will be added before \

Parameter Argument

Value that is "passed" to and used by a method

Return Value

Value that is passed back from a method to the method call

Data Type Keyword Reserved words

Variable declarative which denotes the Type and Amount of storable Data Words that are reserved for use by Java as having special meaning and purpose ex. public, static, void, class int x = 2; int is the data type or the keyword

Constants

Variables whose value the program cannot change ● Naming convention: All caps with underscores final int ALL_CAPS_WITH_UNDERSCORES = 5;

System.out.println();

Will print the string inside the parenthesis and then go to the next line

Math.pow

base to the exp power

Math.E

e value (2.718)

>=

greater that or equal to

Nested for loops

i is the rows j is the columns

Scanner class

import java.util.*; Scanner console = new Scanner(System.in);

%d

integer

==

is equal? boolean y = 5 == 4; System.out.println(y); output: false

Math.log10

logarithm, base 10

<var>.toUpperCase <var>.toLowerCase

makes everything uppercase makes everything lowercase

Math.random

picks a double between 0 and 1 multiply by max number to get a number between 1 and max

%f

real number

<var>.charAt(<index>);

returns the character at that particular index. Starts counting at 0. String c = "Raleigh"; System.out.print(c.charAt(1)); output: a

<variablename>.length();

returns the length of the string. Starts counting at 1. String str = new String("Hello World"); System.out.println(str.length()); output: 11

Math.sin Math.cos Math.tan

sine/cosine/tangent of an angle in radians

Math.min

smaller of two values

Math.sqrt

square root

%s

string

boolean

true or false statement for (int x = 0; x < 0; x++){} //x < 0 is boolean


संबंधित स्टडी सेट्स

Information Retention and Access

View Set

Study For AP World History Final

View Set