C169 - WGU Scripting and Programming - Applications

Réussis tes devoirs et examens dès maintenant avec Quizwiz!

Example of a Expression

(a + b) / 2

When you call a method in Java, what do you need to specify?

1. Method you want to use. (System.out.println)' 2. Any values the method needs to carry out its task. ("Hello, World").

Exception for Run-time errors Example: System.out.println(1 / 0);

A class that signals a condition that prevents the program from continuing normally. When such a condition occurs, an object of the exception class is thrown. System.out.println(1 / 0); run-time error message "Division by zero"

What does every Java application contain?

A class w/ a main method. Application starts &instructions in the main method are executed.

Package

A collection of related classes. The import statement is used to access one or more classes in a package. Collection of classes with a related purpose.

What must every Java application contain?

A main method.

Debugger

A program that lets a user run another program one or a few steps at a time, stop execution, and inspect the variables in order to analyze it for bugs.

Method

A sequence of statements that has a name, may have parameter variables, and may return a value. A method can be invoked any number of times, with different values for its parameter variables.

What would this method print? System.out.print("00"); System.out.println(3 + 4);

A single line 007.

Prompt

A string that tells the user to provide input. Use print method not PrintIn, display the prompt.

Statements

A syntactical unit in a program. In Java a statement is either a simple statement, a compound statement, or a block. Each contains a (;).

Arguments

A value supplied in a method call, or one of the values combined by an operator.

What does this statement declare? int cansPerPack = 6

A variable named cansPerPack

What is required to write useful programs?

A vast set of library packages.

What 4 basic arithmetic operations does Java support?

Additions (+), Subtraction (-), Multiplication (*), & Division (/).

Why use quotation marks for Strings?

All text strings must be in QM so the compiler considers them plain text & doesn't try to interpret them as program instructions.

What is the technical term for a value?

Arguments(enclosed in parentheses. Multiple are separated by commas.

How do you protect yourself from data loss?

Back up your files & folders.

How is a method called?

By specifying the method & its arguments.

Java is Case sensitive

Careful about distinguishing between upper- & lowercase letters exactly as they appear in program listing.

Run-time error

Causes a program to take an action that the programmer did not intend. Program will run but output will be wrong. Logical flaws in program, often called logic errors.

Suppose you change println to printline in the HelloPrinter.java program. Is this a compile-time error or a run-time error?

Compile-time error. Compiler will complain that System.out does not have a method called printline.

Omit the "" characters around Hello, World! from the HelloPrinter.java program. Is this a compile-time error or a run-time error?

Compile-time error. Compiler will complain that it does not know the meanings of the words Hello and World.

What does Java need to do in order to achieve portability?

Compiled Java Programs contain instructions for Java virtual machine, program that stimulates a real CPU.

What was Java originally designed for?

Consumer devices, but it was 1st successfully used to write Internet applets.

What does a computer store?

Data & programs.

Result Variable

Declared in a separate method, & their scopes do not overlap.

How was Java designed?

Designed to be safe & portable, benefiting both internet users & students.

Library in Java

Designed to be safe & portable, benefiting both internet users & students.

What does a class & method contain?

Each class contains declarations of methods. Each method contains a sequence of instructions.

Running a program in IDE.

Editor-> Source File -> Compiler -> Class Files

Method Comments

Explain the purpose of the method, the meaning of the parameter variables and return value, as well as any special requirements.

Where do you store your programs?

Files->Folders or Directories Make separate folders for each program.

ENIAC (Electronic Numerical Integrator & Computer)

First usable electronic computer.

Classes

Fundamental building blocks of Java programs.

Applets

Graphical Java program that executes inside a web browser or applet viewer.

The System.out.println method prints a string or a number and then starts a new line. What would this print? System.out.println("Hello"); System.out.println("World!");

Hello World! 2 lines

What do the following statements print? System.out.println("Hello"); System.out.println(""); System.out.println("World");

Hello a blank line World

Pseudocode

Informal description of a sequence of steps for solving a problem.

The info a user enters for the computer by using a keyboard or a pointing device, mouse?

Input

Class files contains:

Instructions for Java Virtual Machine

How are Java programs distributed?

Instructions for a virtual machine, making them platform independent.

Type

Is how a variable stores data.

Who designed ENIAC?

J. Presper Eckert & John Mauchly at University of Pennsylvania & completed in 1946

What happens after the compiler translates your program into virtual machine?

Java virtual machine executes them.

Code-named "Green"

Language designed to be simple, secure, & usable for many ferent processor types.

Storage Devices include?

Memory & Secondary Storage

Primary Storage includes?

Memory chips, electronic circuits that can store data, provided they are supplied with electric power.

PrintTriangle

Method calls itself again with smaller & smaller side lengths. Eventually side length must reach 0, & method stops calling itself.

Recursion to Terminate

Must be special cases for the simplest inputs.

What does the following set of statements print? System.out.print("My lucky number is "); System.out.println(3 + 4 + 5);

My lucky number is 12

How long does it take to learn the entire Java library?

No one person can learn its too large.

Would the program continue to work if you replaced (System.out.println("Hello, World!");) with this statement? System.out.println(Hello);

No. The compiler would look for an item whose name is Hello. You need to enclose Hello in quotation marks: System.out.println("Hello");

What data variable types does Java use?

Numbers, Text Strings, Files, Dates & many others.

What is transmitted info from a computer to the user through a display screen, speakers, and printers?

Output

Name some types of library packages.

Packages for graphics User-Interface Design Cryptography Networking Sound Database Storage & many other purposes

What is a variable similar to?

Parking space in a parking garage. Parking space has an identifier (such as "J 053"), can hold a vehicle. A variable has a name (such as cansPerPack), and it can hold a value (such as 6). int cansPerPack = 6;

Scope

Part of a program in which a variable is defined.

Central Processing Unit (CPU)

Performs program control & data processing.

Why can't you test a program for run-time errors when it has compiler errors?

Program has compiler errors, no class file is produced & there is nothing to run.

Java Virtual Machine

Program that simulates a CPU that can be implemented efficiently on a variety of actual machines. A given program in Java bytecode can be executed by any Java virtual machine, regardless of which CPU is used to run the VM itself.

IDE (Integrated Development Environment)

Programming environment that includes an editor, compiler, & debugger. You can write & test your code.

High-level Programming Languages

Programming language that provides an abstract view of a computer & allows programmers to focus on their problem domain. Java

How is a value set or changed?

Remove the first and last character from the word.

Void Method

Returns no value, but it can produce output.

Change main to hello in the HelloPrinter.java program. Is this a compile-time error or a run-time error?

Run-time error. Virtual machine will look for a main method and won't find one.

When you used your computer, you may have experienced a program that "crashed" (quit spontaneously) or "hung" (failed to respond to your input). Is that behavior a compile-time error or a run-time error?

Run-time error. After all, the program had been compiled in order for you to run it.

Describing an Algorithm with Pseudocode.

STEP 1: Determine inputs & outputs. -purchase price1 and fuel efficiency1, the price and fuel efficiency (in mpg) of the first car -purchase price2 and fuel efficiency2, the price and fuel efficiency of the second car STEP 2: Break down problem into smaller tasks. Step 2: Break down problem into smaller task. -The total cost for each car is purchase price + operating cost. -The operating cost is 10 × annual fuel cost. The annual fuel cost is price per gallon × annual fuel consumed. -The annual fuel consumed is annual miles driven / fuel efficiency. For example, if you drive the car for 15,000 miles and the fuel efficiency is 15 miles/gallon, the car consumes 1,000 gallons. STEP 3: Describe each subtask in pseudocode. -total cost = purchase price + operating cost. STEP 4: Test pseudocode by working a problem.

What are the 2 most important benefits of Java language?

Safety & Protability

String

Sequence of characters enclosed in quotation marks.

What is a computer program ?

Sequence of instructions and decisions.

In order to write a computer program, you need?

Sequence of instructions that the CPU can execute.

Algorithm

Sequence of steps that are unambiguous, executable, and terminating specification of a way to solve a problem.

Initialization

Setting a variable to a well-defined value when it is created.

Resolves Computation

Solves a problem by using the solution of the same problem with simpler inputs.

What do you usually do when you declare a variable?

Specify the value that should be stored in the variable. Variable cansPerPack is initialized with the value 6.

What happens when a program runs?

Statements inside main method are executed one by one. System.out.println("Hello, World!");

Source code refers to:

Statements that you write into class files

4 Steps to follow for a Programming Environment

Step 1: Start Java development environment. Step 2: Write a simple program. Step 3: Run the program Step 4: Organize your work.

Variable

Storage location in a computer program with a name. Each one has a name and holds a value.

Expression

Syntactical contract that is made up of constants, variables, method calls, & operations combining them.

How would you modify the HelloPrinter program to print the word "Hello" vertically?

System.out.println("H"); System.out.println("e"); System.out.println("l"); System.out.println("l"); System.out.println("o");

Return Statement

Terminates a method call & yields the method result.

Javadoc

The documentation generator in the Java SDK. It extracts documentation comments from Java source files and produces a set of linked HTML files.

Return Value

The value returned by a method through a return statement.

Parameter variables

The values that are supplied to the method when it is called are the arguments of the call.

Printerwriter Class

To write output to file, construct object with the desired file name.

Compiler

Translate high-level instructions into more detailed instructions required by the CPU.

Java Compiler

Translate source code into class files that contain instructions for JVM.

Why is it important that pseudocode describes a sequence of steps?

Unambiguous Executable Teminating

Software Development Process: Existence of an algorithm is an essential prerequisite for programming a task.

Understand the problem Develop & describe an algorithm Test the algorithm w/ simple inputs Translate the algorithm into Java Compile & test your program

What was Code-Green used for ?

Use in consumer devices, such as set top boxes.

Scanner Class

Used for reading text files.

In Java how do you store values?

Using variables.

Secondary Storage includes?

Usually a hard drive, provides slower & less expensive storage that persists without electricity.

Local Variable

Variable whose scope is a block. Defined within a method.

Compile-time error

Violation of programming language rules that is detected by compiler. Sometimes called syntax errors. Wont translate the code

What type of operating systems can the Java program run on?

Windows, Unix, Linux, or Macintosh.

Example of a simple program.

public class HelloPrinter { public static void main(String[] args) { System.out.println("Hello, World!"); } }

What are the 2 key requirements to make sure that recursion is successful

• Every recursive call must simplify the task in some way. • There must be special cases to handle the simplest tasks directly.


Ensembles d'études connexes

Chapter 7: Followership (Leadership)

View Set

Abnormal psych final exam (chapter 16)

View Set

Chapter 14: Care of the Patient with a Neurologic Disorder

View Set

Missouri Restricted Permit Test Review

View Set