Java Chapter 1

Pataasin ang iyong marka sa homework at exams ngayon gamit ang Quizwiz!

What is a compiler?

A compiler is a program that translates source code into an executable form

Describe what a compiler does with a program's source code.

A compiler translates source code into an executable form.

What is a compiler?

A compiler translates source code into an executable form.

What is pseudo code?

A cross between human language and a programming language. Pseudocode is especially helpful when designing an algorithm. Although the computer can't understand pseudocode, programmers often find it helpful to write an algorithm in a language that's "almost" a programming language, but still very similar to natural language.

Describe the difference between a key word and a programmer-defined symbol.

A key word has a special purpose, and is defined as part of a programming language. A programmer-defined symbol is a word or name defined by the programmer.

Describe the difference between a program line and a statement.

A line is a single line as it appears in the body of a program. A statement is a complete instruction that causes the computer to perform an action.

What is a runtime error?

A runtime error is an error that occurs while the program is running. These are usually logical errors, such as mathematical mistakes.

If you were to look at a machine language program, you would see

A stream of binary numbers

What is a memory address? What is its purpose?

A unique number assigned to each section of memory. The address is used to identify a location in memory.

Each byte is assigned a unique

Address

Computer Systems: Hardware and Software

All computer systems consist of similar hardware devices and software components.

What is an algorithm?

An algorithm is a set of well-defined steps for performing a task or solving a problem

What is the difference between an application and an applet?

An application is a stand-alone program that runs on your computer An applet refers to a small application. It is designed to be transmitted over the Internet from a Web server, and then executed in a Web browser

Why should an object hide its data?

An object hides it's data to protect from accidental corruption. Object's methods provide programming statements to access object's data.

What is the difference between operating system software and application software?

An operating system is a set of programs that manages the computer's hardware devices and controls their processes. Application software refers to programs that make the computer useful to the user. This software is use to solve specific problems or perform general operations that satisfy the needs of the user.

This type of program is designed to be transmitted over the Internet and run in a Web browser.

Applet

Programming Languages

Basic, Fortran, Cobol, pascal, C, C++, C#, Java, JavaScript, Perl, php, python, ruby, visual basic.

Why must programs written in a high-level language be translated into machine language before they can be run?

Because computers only understand the low-level languages that resemble the numeric machine language rather than the natural language of humans

Why is it easier to write a program in a high-level language than in machine language?

Because high level languages are more like natural language

Why is the computer used by so many different people, in so many different professions?

Because the computer can be programmed to do so many different tasks.

Why are variables called "variable"?

Because their contents may be changed.

What does it mean to "visualize a program running"? What is the value of such an activity?

Before you create a program on the computer, it is often a good idea to imagine what the computer screen will look like while the program is running. If it helps, draw pictures of the screen, with sample input and output, at various points in the program.

A byte is made up of eight

Bits

Why are Java applets safe to download and execute?

Browser executes them in a restricted enviroment

What does the Java compiler translate Java source code to?

Byte Code

The Java compiler generates

Byte code

This part of the computer fetches instructions, carries out the operations commanded by the instructions, and produces some outcome or resultant information.

CPU

List the five major hardware components of a computer system.

CPU, main memory, secondary storage devices, input devices, and output devices.

Punctuation is

Characters that serve specific purposes, marking the beginning, end of a statement, and separating items in a list

Assuming there are no syntax errors when it is compiled. What file will be produced?

Compiler translates it to byte code and produced as class file

Internally, the CPU consists of what two units?

Control unit, and arithmetic logic unit.

In procedural programming, what two parts of a program are typically separated?

Data and code that operates on the data

What is data hiding?

Data hiding refers to an object's ability to hide its data from code that is outside the object. Only the object's methods may then directly access and make changes to the object's data. An object typically hides its data, but allows outside code to access the methods that operate on the data.

The Programming Process

Define what the program is to do, visualize it running, use design tools to create a model, check model for logical errors, enter code and compile, correct errors, run with test data for input, correct run time errors, validate results of program.

Account Balance A program that calculates the current balance in a savings account must ask the user for the following: • The starting balance • The total dollar amount of deposits made • The total dollar amount of withdrawals made • The monthly interest rate Once the program calculate* the current balance, it should be displayed on the screen.

Display "What is the account's starting balance?" Input startingBalance. Display "What is the total amount of the deposits made?" Input deposits. Display "What is the total amount of the withdrawals made?" Input withdrawals. Display "What is the monthly interest rate?" Input interestRate. balance = startingBalance + deposits - withdrawals. interest = balance * interestRate. balance = balance + interest. Display balance.

Available Credit A program that calculate* a customer** available credit should ask the user for the following: • The customer's maximum amount of credit • The amount of credit used by the customer Once these items have been entered, the program should calculate and display the customer's available credit. You can calculate available credit by subtracting the amount of credit used from the maximum amount of credit.

Display "What is the customer's maximum amount of credit?" Input maxCredit. Display "What is the amount of credit used by the customer?" Input creditUsed. availableCredit = maxCredit - creditUsed. Display availableCredit.

Is encapsulation a characteristic of procedural or object-oriented programming?

Encapsulation is characteristic of object-oriented programming.

Is a syntax error (such as misspelling a key word) found by the compiler or when the program is running?

Found on the compiler

Explain why computers have both main memory and secondary storage.

Instructions and data are stored in main memory while operating. Main is volatile, and is reset when powered off. Secondary is able to hold data when off. When turned on memory can retrieve data from secondary storage device.

What does the term multitasking mean?

It means that an operating system is capable of running multiple programs at once.

What type of program do you use to write Java source code?

JVM

What must a computer have in order for it to execute Java programs?

Java Development Kit

JVM stands for

Java Virtual Machine

Introduction

Java is a powerful language that runs on practically every type of computer. It can be used to create large applications or small programs, known as applets, that are part of a Website.

These are words that have a special meaning in the programming language.

Key Words

What is a Program Made Of?

Key words, operators, punctuation, programmer-defined names, syntax.

What is the difference between machine language code and byte code?

Machine language code is executed directly by the CPU. It is platform-specific, if it is compiled in Windows, it will ONLY run in Windows. Byte code is executed by the JVM. It is platform independent, byte codes compiled by a compiler running in Windows will still run in Linux/Unix/MAC.

What type of memory is usually volatile?

Main Memory

Will the Java compiler translate a source file that contains syntax errors?

No

Object-Oriented Programming

OOP is a method of software development that has its own practices, concepts, and vocabulary.

What part of an object forms an interface through which outside code may access the object's data?

Object's method forms an interface through which outside code may access object's data.

These are symbols or words that perform operations on one or more operands.

Operators

Describe the difference between operators and punctuation symbols.

Operators perform operations on one or more operands. Punctuation symbols mark the beginning or ending of a statement, or separates items in a list.

These are words or names that are used to identify storage locations in memory and parts of the program that are created by the programmer.

Programmer-defined names

Why Program?

Programming is the most versatile tool ever made. Computers can do many different jobs because they are programmable.

These characters serve specific purposes, such as marking the beginning or ending of a statement, or separating items in a list.

Punctuation

Both main memory and secondary storage are types of memory. Describe the difference between the two.

RAM, the computer's main memory is a device that holds information. RAM is usually a volatile type of memory, used only for temporary storage. The secondary storage is a type of memory that can hold data for long periods of time - even when there is no power to the computer.

This type of memory can hold data for long periods of time--even when there is no power to the computer.

Secondary Storage

These are the rules that must be followed when writing a program.

Syntax

What is the difference between a syntax error and a logical error?

Syntax error occurs when the code isn't formatted or typed correctly Logical error occurs when there is a fallacy of reasoning

What is a syntax error?

Syntax errors are mistakes that the programmer has made that violate the rules of the programming language. These errors must be corrected before the compiler can translate the source code.

What is the JVM?

The Java Virtual Machine (JVM) is a program that reads Java byte code instructions and executes them as they are read. In other words, it interprets byte code instructions. You can think of the JVM as a program that simulates a computer whose machine language is Java byte code

What is byte code?

The Java compiler translates Java source code into byte code, which is an intermediate language. The Java Virtual Machine executes the byte code instructions.

What is encapsulation?

The combining of data and code into a single object

Describe the steps in the fetch/decode/execute cycle.

The control unit fetches from main memory next instruction, then instruction is encoded in form of a number, control unit decodes instruction and generates electronic signal, signal is routed to appropriate component of computer, signal causes the component to perform operation.

What will the file contain?

The file containing the byte code with .class extension

What is a source file?

The file the source code is saved under

What must be designed for any real-world computer program:

The logical flow of the instructions, mathematical procedures, layout of programming statements, appearance of the screens, way information is presented to the user, "user friendliness", manuals, help systems, and forms of written documentation.

What happens to a variable's current contents when a new value is stored there?

The original value is overwritten

What are an object's methods?

The procedures, or behaviors, that an object performs.

Programmer-Defined Names are

Unlike key words, words or names defined by programmer. Identify storage locations in memory and parts of program that are created. Also called identifiers.

This is a named storage location in the computer's memory.

Variable

What is the purpose of testing a program with sample data or input?

You can provide sample data and predict what the output should be. If the program does not produce the correct output, a logical error is present in the program.

What four items should you identify when defining what a program is to do?

You need to identify the purpose of the program, what data should be input, the process, and the output.

Operands are

an item of data, such as a number

The following pseudocode algorithm has an error. The program is supposed to ask the user for the length and width of a rectangular room, and then display the room's area. The program must multiply the width by the length in order to determine the area. Find the error.

area = width x length Display "What is the room's width?" input width. Display "What is the room's length?" input length. Display area.

Why are variables called "variable"?

data stored in variables may change while the program is running. A variable is a named storage location in the computer's memory for holding a piece of information. The information stored in variables may change while the program is running (hence the name).

Why does byte code make Java a portable language?

it is platform independent and it's compiled by a compiler running in Windows will still run in Linux/Unix/Mac.

What command would you type at the operating system command prompt to run the program?

java LabAssignment

// This is my first Java program. public class MyFirstProgram { public static void main(String[] args) { System.out.println("Hello World?"); } }

javac MyFirstProgram.java java MyFirstProgram

Assuming you arc using the Sun JDK, what command would you type at the operating system command prompt to compile the program LabAssignment.Java?

make sure you are in the directory that contains the file, and then type: javac LabAssignment.java

Syntax are

rules that must be followed and dictates how key words and operators may be used, and where punctuation symbols most appear.

Operators are

symbols or words that perform operations operands.

What are an object's attributes?

the data contained in an object

Key Words are

used for intended purpose only and know as reserved words


Kaugnay na mga set ng pag-aaral

Chapter 16: Care of Patients Experiencing Urgent Alterations in Health

View Set

Sensoriske receptormekanismer (excitable celler)

View Set

Hospital Unit Procedures 2 Test 1

View Set

FINC 315- Time Value of Money Assesment

View Set

ISYS EXAM 2: 7.3 (Wireless Network Categories)

View Set

HONORS CHEM Electron Configuration

View Set

Geography - Records, Longest Rivers by Continent & US

View Set

Chapter 17- Externalities & Public Goods

View Set