MIS301 Quiz 1 Terms

Ace your homework & exams now with Quizwiz!

characters

A char variable stores a single character Character literals are delimited by single quotes: 'a' 'X' '7' '$' ',' '\n' Example declarations: char topGrade= 'A'; char terminator = ';', separator = ' '; Note the difference between a primitive character variable, which holds only one character, and a String object, which can hold multiple characters

class libraries

A class library is a collection of classes that we can use when developing programs The Java standard class library is part of any Java development environment Its classes are not part of the Java language per se, but we rely on them heavily Various classes we've already used (System, Scanner, String) are part of the Java standard class library

pixels

A picture is represented in a computer by breaking it up into separate picture elements, or pixels

expressions

An expression is a combination of one or more operators and operands Arithmetic expressions compute numeric results and make use of the arithmetic operators: Addition + Subtraction - Multiplication * Division / Remainder % If either or both operands are floating point values, then the result is a floating point value

division and remainder

If both operands to the division operator (/) are integers, the result is an integer (the fractional part is discarded) 14 / 3 = 4 8 / 12 = 0 if either or both operands to the division operator (/) are floating point values, the result is a floating point value (the fractional part is kept) 14.0 / 3 = 4.67 8 / 12.0 = 0.67 The remainder operator (%) returns the remainder after dividing the first operand by the second 14 % 3 = 2 8 % 12 = 8

machine language

In order for a program to run on a computer, it must be expressed in that computer's machine language. Each type of CPU has its own language. Each machine language instruction can accomplish only a simple task. For example, a single machine language instruction might copy a value into a register or compare a value to zero. It might take four separate machine language instructions to add two numbers together and to store the result. Machine language code is expressed as a series of binary digits and is extremely difficult for humans to read and write. Ex: 01100001

garbage collection

Java performs automatic garbage collection. When the last reference to an object is lost, the object becomes a candidate for garbage collection. Occasionally, behind the scenes, the Java environment executes a method that "collects" all the objects marked for garbage collection and returns their memory to the system for future use. The programmer does not have to worry about explicitly reclaiming memory that has become garbage.

Byte

On many computers, each memory location consists of eight bits, or one byte, of information. If we need to store a value that cannot be represented in a single byte, such as a large number, then multiple, consecutive bytes are used to store the data. A kilobyte (KB) is 1024, or 210, bytes. Some larger units of storage are a megabyte (MB), a gigabyte (GB), a terabyte (TB), and a petabyte (PB)

syntax

The syntax rules of a language define how we can put together symbols, reserved words, and identifiers to make a valid program

Quick check:

Write a single println statement that produces the following output: "Thank you all for coming to my home tonight," he said mysteriously. System.out.println ("\"Thank you all for " +"coming to my home\ntonight,\" he said " +"mysteriously.");

command line applications

interact with the user using simple text prompts text-based

classes

*An object is defined by a class. A class is the model or blueprint from which an object is created. multiple objects can be created from one class definition. a class contains one or more methods Each class declares ◦Instance variables: descriptive characteristics or states of the object ◦Methods: behaviors of the object, i.e., what it can do Each object made from the class has its own (different) values for the instance variables of that class

java program structure

1. // comments about the class public class MyProgram { } "MyProgram" is the class header { } is the class body comments can be placed almost anywhere 2. // comments about the class public class MyProgram { // comments about the method public static void main (String[] args) { } } "main" = method header or signature { } after args is the method body

eight primitive data types

4 of them represent integers: -byte (8 bits, -128 - 127) -short (16 bits, -32,768 - 32,767) -int (32 bits, -2,147,483,648 - 2,147,483,647) -long (1, -5, 1024) 2 of them represent floating point numbers: -float -double (2.14159, -6., 6.0) 1 of them represents a single character: -char ('A', ' ', ':') 1 of them represents boolean values: -boolean (true, false)

boolean data type

A boolean value represents a true or false condition The reserved words true and false are the only valid values for a boolean type boolean done = false; A boolean variable can also be used to represent any two states, such as a light bulb being on or

character strings

A character string is an object in Java, defined by the class String. Because strings are so fundamental to computer programming, Java provides the ability to use a string literal, delimited by double quotation characters, as we've seen in previous examples. A string literal is represented by putting double quotes around the text. (A literal is an explicit data value used in a program) Examples: "This is a string literal." "123 Main Street" "X" Every character string is an object in Java, defined by the String class Every string literal represents a String object

representing colors

A color in Java is represented by a Color object A color object holds three numbers called an RGB value, which stands for Red-Green-Blue Each number represents the contribution of that color This is how the human eye works Each number in an RGB value is in the range 0 to 255 The following call creates a maroon color based on 60% red, 10% green, and 0% blue: Color maroon = Color.color(0.6, 0.1, 0.0); A color with an RGB value of 255, 255, 0 has a full contribution of red and green, but no blue, which is a shade of yellow The static rgb method in the Color class returns a Color object with a specific RGB value: Color purple = Color.rgb(183, 44, 150); The color method of the Color class uses percentages, so the following call creates a maroon color based on 60% red, 10% green, and 0% blue: Color maroon = Color.color(0.6, 0.1, 0.0); For convenience, several Color objects have been predefined, such as: Color.BLACK (0, 0, 0) Color.WHITE (255, 255, 255) Color.CYAN (0, 255, 255) Color.PINK (255, 192, 203) Color.GRAY (128, 128, 128)

constants

A constant is an identifier that is similar to a variable except that it holds the same value during its entire existence As the name implies, it is constant, not variable The compiler will issue an error if you try to change the value of a constant In Java, we use the final modifier to declare a constant Ex: final int MIN_HEIGHT = 69; Constants are useful for three important reasons 1. they give meaning to otherwise unclear literal values ◦Example: MAX_LOAD means more than the literal 250 2. they facilitate program maintenance ◦If a constant is used in multiple places, its value need only be set in one place 3. they formally establish that a value should not change, avoiding inadvertent errors by other programmers

run time error

A problem can occur during program execution, such as trying to divide by zero, which causes a program to terminate abnormally

logical error

A program may run, but produce incorrect results, perhaps using an incorrect formula

creating objects with new

A variable holds either a primitive value or a reference to an object A class name can be used as a type to declare an object reference variable String title; No object is created with this declaration An object reference variable holds the address of an object; initially that value is null The object itself must be created separately Generally, we use the new operator to create an object Creating an object is called instantiation An object is an instance of a particular class: title = new String ("Java Software Solutions"); "new String ("Java Software Solutions");" calls the String constructor, which is a special method that sets up the object

variables

A variable is a name for a location in memory that holds a value ◦a variable is a cup, a container. It holds something. Variables come in two flavors: primitive and reference ◦primitive: integers (such as 1, 2,...), real numbers (such as 1.2, 3.5, etc.) ◦reference: "address" of an object that resides in memory (later) A variable declaration specifies the variable's name and the type of information that it will hold Ex: int total; int count, temp, result; int = data type total = variable name multiple variables can be created in one declaration

encapsulation

An object should be encapsulated, which means it protects and manages its own information. That is, an object should be self-governing. The only changes made to the state of the object should be accomplished by that object's methods. We should design objects so that other objects cannot "reach in" and change their states.

casting

Casting is the most general form of conversion in Java. If a conversion can be accomplished at all in a Java program, it can be accomplished using a cast. A cast is a Java operator that is specified by a type name in parentheses. It is placed in front of the value to be converted. For example, to convert money to an integer value, we could put a cast in front of it: dollars = (int) money; The cast returns the value in money, truncating any fractional part. If money contained the value 84.69, then after the assignment, dollars would contain the value 84. Both widening and narrowing conversions can be accomplished by explicitly casting a value To cast, the type is put in parentheses in front of the value being converted: double money = 84.69; intdollars =(int) money; // dollars = 84 Be cautious: you might lose something in narrowing casting: long y = 40002; // 40002 exceeds the 16-bit limit of a short short x =(short) y; // x now equals -25534!

inheritance

Classes can be created from other classes by using inheritance. That is, the definition of one class can be based on another class that already exists. Inheritance is a form of software reuse, capitalizing on the similarities between various kinds of classes that we may want to create. One class can be used to derive several new classes. Derived classes can then be used to derive even more classes. This creates a hierarchy of classes, where the attributes and methods defined in one class are inherited by its children, which in turn pass them on to their children, and so on.

comments

Comments should be included to explain the purpose of the program and describe processing steps The first few lines of the program are comments, which start with the // symbols and continue to the end of the line. Comments don't affect what the program does but are included to make the program easier to understand by humans. Programmers can and should include comments as needed throughout a program to clearly identify the purpose of the program and describe any special processing. Any written comments or documents, including a user's guide and technical references, are called documentation. Comments included in a program are called inline documentation. They do not affect how a program works Two forms of Java comments: // this comment runs to the end of the line /* this comment runs to the terminating symbol, even across line breaks */

delimiters

Delimiters or white space characters (space, tabs, new line) are used to separate the elements of the input -called tokens The next method of the Scanner class reads the next token as a string If the input consists of a series of words separated by spaces, a call to next will return the next word Methods such as nextInt and nextDouble read data of particular types (int and double)

multiple ways to create a string objects

How to create objects once a class is established? How to "hold" those created objects? For primitive types (such as byte, int, double), we use a variable of that particular type as a cup to store its actual value Objects are different ◦There is actually no such thing as an object variable ◦There is only an object reference variable ◦An object reference variable holds something like a pointer or an address that represents a way to get to the object

identifiers

Identifiers are the "words" in a program A Java identifier can be made up of letters, digits, the underscore character ( _ ), and the dollar sign Identifiers cannot begin with a digit Java is case sensitive: Total, total, and TOTAL are different identifiers By convention, programmers use different case styles for different types of identifiers, such as ◦title case for class names (Lincoln) ◦camel case for compound words (HelloWorld) ◦upper case for constants (MAXIMUM) Valid examples: -grade -quizGrade -NetworkConnection -frame2 -MAXIMUM -MIN_CAPACITY Invalid examples: -3rdTestScore (can't begin with a digit) -student# (can't contain #) -Shelves1&2 (can't contain &) -name of a class: Dog, MyFirstApp, and Lincoln -name of method: bark -name of variable: total

compile time error (syntax errors)

If compile-time errors exist, an executable version of the program is not created (simple as a missing bracket)

primitive variable vs reference variable

In Java, a variable name represents either a primitive value or an object. Like variables that hold primitive types, a variable that refers to an object must be declared. The class used to define an object can be thought of as the type of an object. The declarations of object variables have a similar structure to the declarations of primitive variables. When a reference is made to a variable, such as when it is printed, the value of the variable is not changed. Since an object reference variable holds the address of the object, it can be thought of as a pointer to the location in memory where the object is held. A class name can be used as a type to declare an object reference variable: Dog myDog; (Dog is the class type & myDog is the object name) No Dog object is created with this declaration The object itself must be created separately using the new operator, but the object itself does not go into the variable a primitive variable contains the value itself, but an object variable contains the address of the object An object reference can be thought of as a pointer to the location of the object

main method

Inside the class definition are some more comments describing the purpose of the main method, which is defined directly below the comments. A method is a group of programming statements that is given a name. In this case, the name of the method is "main" and it contains only two programming statements. Like a class definition, a method is also delimited by braces. All Java applications have a main method, which is where processing begins. Each programming statement in the main method is executed, one at a time in order, until the end of the method is reached. Then the program ends, or terminates. The main method definition in a Java program is always preceded by the words public, static, and void. The use of String and args does not come into play in this particular program. The two lines of code in the main method invoke another method called println (pronounced print line). We invoke, or call, a method when we want it to execute. The println method prints the specified characters to the screen. The characters to be printed are represented as a character string, enclosed in double quote characters ("). When the program is executed, it calls the println method to print the first statement, calls it again to print the second statement, and then, because that is the last line in the main method, the program terminates. The code executed when the println method is invoked is not defined in this program. The println method is part of the System.out object, which is part of the Java standard class library.

string indices

It is occasionally helpful to refer to a particular character within a string This can be done by specifying the character's numeric index The indexes begin at zero in each string In the string "Hello", the character 'H' is at index 0 and the 'o' is at index 4

enumerated types

Java allows you to define an enumerated type, which can then be used to declare variables An enumerated type declaration lists all possible values for a variable of that type The values are identifiers of your own choosingThe following declaration creates an enumerated type called Season enum Season {winter, spring, summer, fall}; Any number of values can be listed Once a type is defined, a variable of that type can be declared: Season time; And it can be assigned a value: time = Season.fall; The values are referenced through the name of the type Enumerated types are type-safe-you cannot assign any value other than those listed The declaration of an enumerated type is a special type of class, and each variable of that type is an object The ordinal method returns the ordinal value of the object The first value in an enumerated type has an ordinal value of 0, the second 1, and so on The name method returns the name of the identifier corresponding to the object's value

object oriented programming

Java is an object-oriented (OO) language. As the name implies, an object is a fundamental entity in a Java program. This book is focused on the idea of developing software by defining objects that interact with each other. One of the most attractive characteristics of the object-oriented approach is the fact that objects can be used quite effectively to represent real-world entities. We can use a software object to represent an employee in a company, for instance. We'd create one object per employee, each with behaviors and characteristics that we need to represent. In this way, object-oriented programming allows us to map our programs to the real situations that the programs represent. Object-oriented programming helps us solve problems, which is the purpose of writing a program.

objects

Java is an object-oriented programming language As the term implies, an object is a fundamental entity in a Java program Objects can be used effectively to represent real-world entities For instance, an object might represent a particular employee in a company Each employee object handles the processing and data management related to that employee An object has: -state: descriptive characteristics -behaviors: what it can do or what can be done to it The state of a bank account includes its account number and its current balance The behaviors associated with a bank account include the ability to make deposits and withdrawals Note that the behavior of an object often changes its state An object is defined by a class A class is the blueprint of an object The class uses methods to define the behaviors of the object The class that contains the main method of a Java program represents the entire program A class represents a concept, and an object represents the embodiment of that concept Multiple objects can be created from the same

JavaFX

JavaFX has replaced older approaches (AWT and Swing) JavaFX programs extend the Application class, inheriting core graphical functionality A JavaFX program has a start method The main method is only needed to launch the JavaFX application The start method accepts the primary stage (window) used by the program as a parameter JavaFX embraces a theatre analogy

basic shapes

JavaFX shapes are represented by classes in the javafx.scene.shape package A line segment is defined by the Line class, whose constructor accepts the coordinates of the two endpoints: Line(startX, startY, endX, endY) For example: Line myLine= new Line(10, 20, 300, 80); A rectangle is specified by its upper left corner and its width and height: Rectangle(x, y, width, height) Rectangle r = new Rectangle(30, 50, 200, 70); A circle is specified by its center point and radius: Circle(centerX, centerY, radius) Circle c = new Circle(100, 150, 40); An ellipse is specified by its center point and its radius along the x and y axis: Ellipse (centerX, centerY, radiusX, radiusY) Ellipse e = new Ellipse(100, 50, 80, 30); Shapes are drawn in the order in which they are added to the group The stroke and fill of each shape can be explicitly set Groups can be nested within groups Translating a shape or group shifts its position along the x or y axis A shape or group can be rotated using the setRotate method

object-oriented software principles

Object-oriented programming ultimately requires a solid understanding of the following terms: -object -attribute -method -class -encapsulation -inheritance -polymorphism

assignment operators

Often we perform an operation on a variable, and then store the result back into that variable Java provides assignment operators to simplify that process For example, the statement: num+= count; is equivalent to: num= num+ count;

string methods

Once a String object has been created, neither its value nor its length can be changed Therefore we say that an object of the String class is immutable However, several methods of the String class return new String objects that are modified versions of the origin Because strings are so common, we don't have to use the new operator to create a String object: String title = "Java Software Solutions"; *title = new String ("Java Software Solutions"); String title; title = "Java Software Solutions"; This is special syntax that works only for strings *Each string literal (enclosed in double quotes) represents a String object

operator precedence

Operators can be combined into larger expressions result = total + count / max - offset; Operators have a well-defined precedence which determines the order in which they are evaluated Multiplication, division, and remainder are evaluated before addition, subtraction, and string concatenation Arithmetic operators with the same precedence are evaluated from left to right, but parentheses can be used to force the evaluation order

polymorphism

Polymorphism is the idea that we can refer to multiple types of related objects over time in consistent ways. It gives us the ability to design powerful and elegant solutions to problems that deal with multiple objects.

steps in problem solving

Problem solving consists of multiple steps: 1. Understanding the problem. 2. Designing a solution. 3. Considering alternatives to the solution and refining the solution. 4. Implementing the solution. 5. Testing the solution and fixing any problems that exist. The key to designing a solution is breaking it down into manageable pieces An object-oriented approach lends itself to this kind of solution decomposition -put a class in a source file -put methods in a class -put statements in a method Object-Oriented Programming: -Classes are the fundamental building blocks of an objected-oriented program ◦Each class is an abstraction of similar objects in the real world, e.g., dogs, songs, houses, etc. -Once a class is established, multiple objects can be created from the same class ◦Each object is an instance (a concrete entity) of a corresponding class, e.g., a particular dog, a particular song, a particular house, etc.

interactive programs

Programs generally need input on which to operate The Scanner class provides convenient methods for reading input values of various types A Scanner object can be set up to read input from various sources, including the user typing values on the keyboard Keyboard input is represented by the System.in object

promotion

Promotion happens automatically when operators in expressions convert their operands Example: int count = 12; double sum = 490.27; double result = sum / count; The value of count is converted to a floating point value to perform the division calculation

assignment conversion

Sometimes it is convenient to convert data from one type to another For example, in a particular situation we may want to treat an integer as a floating point value These conversions do not change the type of a variable or the value that's stored in it -they only convert a value as part of a computation Data Conversion: Widening conversions are safest because they tend to go from a small data type to a larger one (such as a short to an int) Narrowing conversions can lose information because they tend to go from a large data type to a smaller one (such as an int to a short) In Java, data conversions can occur in three ways: ◦assignment conversion ◦promotion ◦casting Assignment conversion: occurs when a value of one type is assigned to a variable of another Only widening conversions can happen via assignment Ex: int dollars = 20; double money = dollars; // OK long y = 32; int x = y; //won't compile

white space

Spaces, blank lines, and tabs are called white space White space is used to separate words and symbols in a program Extra white space is ignored A valid Java program can be formatted many ways Programs should be formatted to enhance readability, using consistent indentation

The + Operator in string concatenation

The + operator is also used for arithmetic addition The function that it performs depends on the type of the information on which it operates If both operands are strings, or if one is a string and one is a number, it performs string concatenation If both operands are numeric, then it adds them The + operator is evaluated left to right, but parentheses can be used to force the order

decimalformat class

The DecimalFormat class can be used to format a floating point value in various ways For example, you can specify that the number should be truncated to three decimal places The constructor of the DecimalFormat class takes a string that represents a pattern for the formatted number DecimalFormat fmt = new DecimalFormat ("0.###"); 0 means output a digit in that position # means output any nonzero digits with leading and trailing digits shown as absent. . (period) is the decimal separator , (comma) is the grouping separator

bytecode

The Java compiler translates Java source code into a special representation called bytecode Java bytecode is not the machine language for any traditional CPU

math class

The Math class is part of the java.lang package The Math class contains methods that perform various mathematical functions These include: ◦absolute value ◦square root ◦exponentiation ◦trigonometric functions The methods of the Math class are static methods (also called class methods) Static methods are invoked through the class name -no object of the Math class is needed value = Math.cos(90) + Math.sqrt(delta); Common methods in the Math class: Math.abs(num) x = Math.abs(num); Math.sqrt(num) x = Math.sqrt(discriminant); Math.pow(num, power) x = Math.pow(b, 2);

numberformat class

The NumberFormat class allows you to format values as currency or percentages It is part of the java.text package The NumberFormat class has static methods that return a formatter object getCurrencyInstance() getPercentInstance() NumberFormat fmt1=NumberFormat.getCurrencyInstance(); NumberFormat fmt2=NumberFormat.getPercentInstance(); Each formatter object has a method called format that returns a string with the specified information in the appropriate format System.out.println ("Subtotal: " + fmt1.format(subtotal));

random class

The Random class is part of the java.util package It provides methods that generate pseudorandom numbers A Random object performs complicated calculations based on a seed value to produce a stream of seemingly random values ◦nextFloat() generates a random number [0, 1) ◦nextInt() generates a random integer (positive or negative) ◦nextInt(n)generates a random integer [0, n-1]

scanner class

The Scanner class, which is part of the Java API, provides convenient methods for reading input values of various types. The input could come from various sources, including data typed interactively by the user or data stored in a file. The Scanner class can also be used to parse a character string into separate pieces. The Scanner class provides methods for reading input of various types from various sources.

reading input

The System and String classes are part of the Java.lang package (whose classes can be thought of as basic extensions to the Java language). These classes can be invoked without explicitly importing them, so we can just use: System.out.println( ); The Scanner class is part of the java.util class library and must be imported into a program that is using it by using the statement: import java.util.Scanner; The import statement precedes the class statement The following line creates a Scanner object that reads from the keyboard: Scanner scan = new Scanner (System.in); The new operator creates the Scanner object by calling a special method called a constructor Once created, the Scanner object can be used to invoke various input methods, such as: answer = scan.nextLine(); The nextLine method reads all of the input until the end of the line is found

more about System.out print vs. printin

The System.out object represents a destination (the monitor screen) to which we can send an output Ex: System.out.printIn ("Whatever you are, be a good one."); -System.out. = object -printIn = method name -("Whatever you are, be a good one."); = information provided to the method (parameters) The System.out object provides another service in addition to println The print method is similar to the println method, except that it does not advance to the next line Therefore anything printed after a print statement will appear on the same line The println method is a service that the System.out object performs for us. Whenever we request it, the object will print a character string to the screen. We can say that we send the println message to the System.out object to request that some text be printed. The System.out object also provides another service we can use: the print method. The difference between print and println is small but important. The println method prints the information sent to it, then moves to the beginning of the next line. The print method is similar to println but does not advance to the next line when completed. The print and println methods represent two services provided by the System.out object.

dot operator for invoking methods

The dot operator (.) gives you access to an object's instance variables (states) and methods (behaviors) Dog myDog = new Dog(); myDog.bark(); ◦It says: use the Dog object referenced by the variable myDog to invoke the bark() method ◦Think of the myDog reference variable as a remote control ◦When you use the dot operator on an object reference variable, it is like pressing a button on the remote control for that object System.out.println revisited ◦There is a class called System, which contains an object reference variable "out" ◦The object referenced by out has a method called "println" We've seen that once an object has been instantiated, we can use the dot operator to invoke its methods: numChars= title.length() A method may return a value, which can be used in an assignment or expression A method invocation can be thought of as asking an object to perform a service

increment and decrement operators

The increment(++) and decrement(--) operators use only one operand The statement: count++; is functionally equivalent to: count = count + 1; The increment and decrement operators can be applied in: ◦postfix form: count++; count--; ◦prefix form: ++count; --count; When used as part of a larger expression, the two forms can have different effects. Assume the value of count is 12 in both cases. ◦postfix form: total = count++;−count has value 13 and total has a value 12, equivalent to: total = count; count = count + 1; ◦prefix form: total = ++count;−count has value 13 and total has a value 13, equivalent to: count = count + 1; total = count;

semantics

The semantics of a program statement define what that statement means (its purpose or role in a program A program that is syntactically correct is not necessarily logically (semantically) correct

high level language

Today, most programmers use a high-level language to write software. A high-level language is expressed in English-like phrases, and thus is easier for programmers to read and write. A single high-level language programming statement can accomplish the equivalent of many—perhaps hundreds—of machine language instructions. The term high-level refers to the fact that the programming statements are expressed in a way that is far removed from the machine language that is ultimately executed. Java is a high-level language. Ex: a + b

turning machine

Turing's greatest contribution to the development of the digital computer were: 1. The idea of controlling the function of a computing machine by storing a program of symbolically, or numerically, encoded instructions in the machine's memory 2. His proof that, by this means, a single machine--a universal machine--is able to carry out every computation that can be carried out by any other Turing machine whatsoever

escape sequences

What if we wanted to print the quote character? The following line would confuse the compiler because it would interpret the second quote as the end of the string: System.out.println ("I said "Hello" to you."); An escape sequence is a series of characters that represents a special character An escape sequence begins with a backslash character (\): System.out.println ("I said \"Hello\" to you."); = I said "Hello" to you. Java defines several escape sequences to represent special characters. An escape sequence begins with the backslash character (\), which indicates that the character or characters that follow should be interpreted in a special way. More escape sequences: \b = backspace \t = tab \n = newline \r = carriage return \" = double quote \' = single quote \\ = backslash

string concatenation

When we want to print a string that is too long to fit on one line in a program, we can rely on string concatenation to append one string to the end of another. The string concatenation operator is the plus sign (+). The following expression concatenates one character string to another, producing one long string: Strings can be concatenated with numbers. Note that the numbers in those lines are not enclosed in double quotes and are therefore not character strings. In these cases, the number is automatically converted to a string, and then the two strings are concatenated. A string literal cannot be broken across two lines in a program Ex: //The following statement won't compile System.out.print("The only stupid question is the one that is not asked"); The string concatenation operator(+) is used to append one string to the end of another Ex: "Peanut butter " + "and jelly" New string: "Peanut butter and jelly" It can also be used to append a number to a string. The number is automatically converted to a string, and then is concatenated with another string Ex: "Speed of car:" + 80+ "mph" New string: "Speed of car: 80 mph"

methods

a method contains program statements (often called "main") *a method is a group of programming statements that is given a name. When a method is invoked, its statements are executed. A set of methods is associated with an object. The methods of an object define its potential behaviors. To define the ability to make a deposit into a bank account, we define a method containing programming statements that will update the account balance accordingly.

program

a program is made up of one or more classes A program is a series of instructions that the hardware executes one after another.

compiler

a software tool which translates source code into a specific target language

reserved words

abstract, assert, boolean, break, byte, case, catch, char, class, const, continue, default, do, double, else, enum, extends, false, final, finally, float, for, goto, if, implements, import, instanceof, int, interface, long, native, new, null, package, private, protected, public, return, short, static, strictfp, super, switch, synchronized, this, throw, throws, transient, true, try, void, volatile, while

Binary code

all information is stored in memory in digital form using the binary number system a single binary digit (0 or 1) is called a bit devices that store and move information are cheaper and more reliable if they have to represent only two states A single bit can represent two possible states, like a light bulb that is either on (1) or off (0) Permutations of bits are used to store value At any point, the voltage of a digital signal is considered to be either "high," which represents a binary 1, or "low," which represents a binary 0.

object

an object is a fundamental element in a program. A software object often represents a real object in our problem domain, such as a bank account. Every object has a state and a set of behaviors. By "state" we mean state of being—fundamental characteristics that currently define the object. For example, part of a bank account's state is its current balance. The behaviors of an object are the activities associated with the object. Behaviors associated with a bank account probably include the ability to make deposits and withdrawals *Each object has its own state, defined by its attributes, and a set of behaviors, defined by its methods.

assembly language

assembly language, which replaced binary digits with mnemonics, short English-like words that represent commands or data. It is much easier for programmers to deal with words than with binary digits. However, an assembly language program cannot be executed directly on a computer. It must first be translated into machine language. Generally, each assembly language instruction corresponds to an equivalent machine language instruction. Therefore, similar to machine language, each assembly language instruction accomplishes only a simple operation. Although assembly language is an improvement over machine code from a programmer's perspective, it is still tedious to use. Both assembly language and machine language are considered low-level languages. Ex: 1d [%fp-20], %o0

assignment statement

changes the value of a variable the assignment operator is the = sign total = 55; the value that was in total is overwritten Quick Check: What output is produced by the following? System.out.println ("X: " + 25); System.out.println ("Y: " + (15 + 50)); System.out.println ("Z: " + 300 + 50); Answers: X: 25 Y: 65 Z: 3005

bit permutations

each permutation represents a particular item there are 2^N permutations of N bits therefore, N bits are needed to represent 2^N unique items 1 bit = 2^1 = 2 items 2 bits = 2^2 = 4 items 3 bits = 2^3 = 8 items 4 bits = 2^4 = 16 items 5 bits = 2^5 = 32 items

GUIs

graphical user interfaces supported by JavaFX

interpreter

translates bytecode into machine language (machine code) and executes it statement by statement Therefore the Java compiler is not tied to any particular machine Java is considered to be architecture-neutral

creating objects: 3 steps

•Step 1: allocate space for a Dog reference variable and name it myDog •Step 2: allocate space for a new Dog object on the heap (a dynamic pool of memory) •Step 3: link the Dog object and the Dog reference via assignment operator Dog myDog = new Dog(); 1. Dog myDog 2. new Dog(); 3. =


Related study sets

AP Chemistry: Unit 3 College Board Questions

View Set

Ch 02: The Chemical Context of Life

View Set

Staffing Chapter 3--The Legal Context

View Set

R REVIEW MUSCULO-KNEES, HIPs, FOREARM & WRIST

View Set

Mandatory Quiz - Geometry Part 2

View Set

TORT/TORS (Latin Root): to twist

View Set

Final Exam Engine Performance week 1-5

View Set