APCS Quiz 1

Ace your homework & exams now with Quizwiz!

Statement

Each line in a method is called a statement. A statement is an executable snipped of code that represents a complete command.

Semicolon

Each statement is terminated by a semicolon. Semicolons are used to terminate statements in the same way that periods terminate sentences in English.

Bugs

Errors in a program are known more generally as bugs. The process of identifying bugs and eliminating them is called debugging.

Escape sequences

Escape sequences are two-character sequences used to represent special characters. All escape sequences begin with the backlash character \ followed by the character to be outputted. ex: \t //tab over \n //newline character \" //double quotation mark \' //single quotation mark \\ //backslash character

//

// in a comment means that the comment can extend to the end of the line but no further

Naming rules

1. All class and method names should be descriptive and in context of the program. 2. All method names should describe actions suggestive of what the method does, as in computeAverage. 3. Java is case sensitive, so the identifiers taft, Taft, TAFT, and tAFt are all considered different.

Capitalization Rules

1. All class names should begin with a capital letter. 2. All method names should begin with lowercase letters. 3. When you are putting several words together to form a class or method name, capitalize the first letter of each word after the first word. This is called camelcase, as in camelCase.

Three types of Errors

1. Syntax errors occur when you commit grammatical violations such as forgetting a semicolon or misspelling a reserved word. 2. Logic errors occur when your code is syntactically correct but does not perform as intended. 3. Runtime errors are logic errors that are so egregious that Java stops your program from executing.

Big Ideas

1. The basic building block in Java is the class. 2. Within a class, there are methods and statements. At a minimum, a complete program requires a special method called main. 3. Within a method, there can be a series of other methods and statements.

Comment

A comment is a piece of text that serves to increase the readability of a program. ex: //java code goes here

Main

A complete program requires a special method known as main. Main is the place where program execution begins and has visibility "public." Every program needs a main method. It has the following syntax: public static void main (String [ ] args) //method header of main { /* more methods and statements go here */ }

Method

A method is a package of functionality that represents a single action or calculation to be performed and is the next-smallest unit of code in Java. Methods are enclosed within curly braces and have names that sound like the actions they perform. ex: a method that computes the area of a circle could be called "computeCircleArea." Inside a class, you can define several different methods.

Compiler

A program that scrutinizes the entire code up and down for mistakes in grammar and logic during execution.

Reference

A reference is a memory address

Syntax template

Describes the basic form of a Java construct. Java has rules that determine its legal syntax, or grammar.

Concatenate

Java allows you to apply the + operator or join or concatenate strings. ex: String str2 = stri1 + " friend";

Reserved words

Java has a set of predefined words called reserved words that are set aside for particular uses. These words are off-limits to use as identifiers.

/* ... */

Multi-line comment that can span more than one line. ex: /* this is a comment. */

Identifiers

Symbolic words used to name parts of a program are called identifiers. An identifier is a fancy term for a variable name. Identifies must start with a letter and can be followed by any number of letters or digits. Java defines the set of letters to include the underscore _ and dollar-sign $ characters. All other special characters are illegal.

Brace characters

The code in a class is enclosed in a pair of outer curly braces { }. In all situations, where there is an opening curly brace {, there must be a corresponding closing curly brace }. These characters are used to group related blocks of code. The code in between the curly braces specifies the series of actions the computer should perform when it executes the method.

Body

The code within a method is called the body.

Method header

The first line of a method is known as a method header.

Class header

The first/opening line of the class is known as the class header. The word "public" in the header indicates that this class is accessible to other software entities.

String literal

The more technical term for a string is string literal.

String

The text that is sent to the console window as output is called a string because it is a sequence of characters that we string together. A string is not the primitive data type but rather an object from the String library class which is built into the language. Strings are best kept compact, not spanning more than one line. ex: "hello world"

String object

To create a new string object, we need the String data type and a variable name to store a reference to the object, as in: String str1 = new String ("Hi"); //create a new string object using the new operator String str1 = "Hi"; //create a String object without using the new operator Strings are so often created that the formal syntax of using the operator new is optional.

Class

Unit of code that serves as the basic building block of Java programs. In Java, nothing can exist outside of a class. Class names always begin with a capital letter for ease of identification. Java requires that the class name and the file name match.


Related study sets

IS 3003 Chapter 1: Business Information Systems in Your Career

View Set

Series 6: Investment Companies (Investment Company Overview)

View Set

Chapter 46: Nursing Care of the Child With an Alteration in Cellular Regulation/Hematologic or Neoplastic Disorder

View Set

Management 365 Connect Chapter 13 Test Questions

View Set

AP World History Exam Review (Excuse spelling/grammar mistakes)

View Set

Chapter 31 - The Nurse in Schools

View Set