JAVA chap 1

Ace your homework & exams now with Quizwiz!

Package

A group of classes

static

A reserved keyword , Means the method is accessible and usable even though no objects of the class exist

Method

A self-contained block of program code that carries out an action Similar to a procedure

Development environment

A set of tools used to write programs

Computer program

A set of written instructions that tells the computer what to do

Java Development Kit (JDK)

A software development kit (SDK) of programming tools Free to download

Javadoc comments

A special case of block comments Begin with a slash and two asterisks (/**) End with an asterisk and a forward slash (*/) Use to generate documentation

Syntax

A specific set of rules for the language

Summary 1

Access specifier A word that defines circumstances under which a class can be accessed All Java applications must have a method named main() Program comments Nonexecuting statements Add to a file for documentation javac A compile command

High-level programming language

Allows you to use a vocabulary of reasonable terms

Logic errors

Also called semantic errors Incorrect order or procedure The program may run but provide inaccurate output

Java API

Also called the Java class library Provides prewritten information about Java classes

Inheritance

An important feature of object-oriented programs Classes share attributes and methods of existing classes but with more specific features Helps you understand real-world objects

Access specifier

Defines how a class can be accessed

Java

Developed by Sun Microsystems An object-oriented language General-purpose Advantages Security features Architecturally neutralCan be run on a wide variety of computers Does not execute instructions on the computer directly Runs on a hypothetical computer known as a Java Virtual Machine (JVM)

Attributes

Differentiate objects of the same class The value of attributes is an object's state Characteristics that define an object

Don't Do It

Don't forget the file's name must match the class name Don't confuse these terms: Parentheses, braces, brackets, curly braces, square brackets, and angle brackets Don't forget to end a block comment Don't forget that Java is case sensitive Don't forget to end every statement with a semicolon Do not end class or method headers with a semicolon Don't forgot to recompile when making changes

Analyzing a Java Application that Produces Console Output

Even the simplest Java application involves a fair amount of confusing syntax Print "First Java application" on the screen

Understanding the First Class

Everything used within a Java program must be part of a class Define a Java class using any name or identifier Requirements for identifiers Must begin with one of the following: Letter of the English alphabet Non-English letter (such as α or π) Underscore Dollar sign Cannot begin with a digit

Debugging

Freeing program of all errors

Procedures

Individual operations grouped into logical units

Java applicationsConsole applicationsWindowed applications

Java applications Called Java stand-alone programs Console applications Support character output Windowed applications Menus Toolbars Dialog boxes

Polymorphism

Means "many forms" Allows the same word to be interpreted correctly in different situations based on context

Reasons for error messages

Misspelled the command javac A misspelled filename Not within the correct subfolder or subdirectory on the command line Improper installation of Java

Syntax error

Misuse of language rules A misspelled programming language word

Modifying a Compiled Java Class

Modify the text file that contains the existing class Save the file with changes using the same filename Compile the class with the javac command Interpret the class bytecode and execute the class using the java command

Variables

Named computer memory locations that hold values

Program comments

Nonexecuting statements added to a program for documentation Use to leave notes for yourself or others Include the author, date, and class's name or function

Run-time error

Not detected until execution Often difficult to find and resolve

Arguments

Pieces of information passed to a method

Object-oriented programming differs from traditional procedural programming

Polymorphism Inheritance Encapsulation

Source code

Programming statements written in high-level programming language

Applets

Programs embedded in a Web page

System class

Refers to the standard output device for a system

Method

Requires information to perform its task

Running a Java Application and Correcting Logical Errors

Run the application from the command line Type java First Shows the application's output in the command window The class is stored in a folder named Java on the C drive

Saving a Java class

Save the class in a file with exactly the same name and .java extension For public classes, class name and filename must match exactly

Procedural programming

Sets of operations executed in sequence

Program statements

Similar to English sentences Commands to carry out program tasks

Objects

Specific, concrete instances of a class

Block comments

Start with a forward slash and an asterisk (/*) End with an asterisk and a forward slash (*/)

Line comments

Start with two forward slashes (//) Continue to the end of the current line Do not require an ending symbol

Bytecode

Statements saved in a file A binary program into which the Java compiler converts source code

Compile-time error

The compiler detects a violation of language rules Refuses to translate the class to machine code

Machine language

The most basic circuitry-level language A low-level programming language

The first line of the error message displays:

The name of the file where the error was found The line number The nature of the error

Next lines identify:

The symbol The location

Logic error

The syntax is correct but incorrect results were produced when executed

Compiler or interpreter

Translates language statements into machine code

Comment out a statement

Turn it into a comment The compiler does not translate, and the JVM does not execute its command

void

Use in the main() method header Does not indicate the main() method is empty Indicates the main() method does not return a value when called Does not mean that main() doesn't produce output

Indent Style

Use whitespace to organize code and improve readability For every opening curly brace ( { ) in a Java program, there must be a corresponding closing curly brace ( } ) Placement of the opening and closing curly braces is not important to the compiler Allman style used in text

Literal string

Will appear in output exactly as entered Written between double quotation marks

Class

everything in java is a class Describes objects with common properties A definition An instance

Requirements for identifiers

Can only contain: Letters Digits Underscores Dollar signs Cannot be a Java reserved keyword Cannot be true, false, or null

Java interpreter

Checks bytecode and communicates with the operating system Executes bytecode instructions line by line within the Java Virtual Machine

Define basic programming terminology Compare procedural and object-oriented programming Describe the features of the Java programming language Analyze a Java application that produces console output

Compile a Java class and correct syntax errors Run a Java application and correct logic errors Add comments to a Java class Create a Java application that produces GUI output Find help

Parsing

Compiler divides source code into meaningful portions

Compiling a Java Class and Correcting Syntax Errors

Compiling a Java class Compile the source code into bytecode Translate the bytecode into executable statements Using a Java interpreter Type javac First.java Compilation outcomes javac is an unrecognized command Program language error messages No messages indicating successful completion

Summary

Computer program A set of instructions that tells a computer what to do Object-oriented programs Classes Objects Applications Java Virtual Machine (JVM) A standardized hypothetical computer Everything in a Java program must be part of a class

Object-oriented programming was used most frequently for two major types of applications

Computer simulations Graphical user interfaces (GUIs) Not all object-oriented programs are written to use a GUI

Encapsulation

Conceals internal values and methods from outside sources Provides security Keeps data and methods safe from inadvertent changes

Object-oriented programs

Create classes Blueprints for an object Create objects from classes Create applications


Related study sets

9) The Axial Skeleton: The Vertebral Column

View Set

Crisis 1 Final Practice Questions

View Set

*IMPORTANT* Valvular Heart Disorders 34Qw/exp

View Set

Accounting 200 -- Chart of accounts

View Set