Test 1 Flashcards
platform dependent
Executable files created from most high-level language source code files are platform dependent. Since such executables are actually machine language files, each can be run only on a certain kind of computer with a particular operating system.
Java bytecode
Java compilers do not create machine language files. Instead, they create files of Java bytecode.
Java Virtual Machine
To run a Java program, you must translate the Java bytecode into machine language through a program called the Java Virtual Machine (or Java VM for short). The Java VM is an interpreter, taking the Java bytecode and executing it directly as it translates it into the machine language of the execution platform.
portable.
Java bytecode is the same on all computers. Bytecode produced by a Java compiler on a Mac can be run on UNIX or Windows systems, and vice versa! That means Java programs are portable. As long as a machine has a Java VM, it can run Java bytecode produced on a completely different kind of system.
Java API
The Java language comes with a large library of code
packages
The Java API is organized into packages. Each Java API package consists of related classes that provide all sorts of things from graphical user interface components to code for handling security
The name of each package in the Java API is in the form
java. or javax.
JRE
Java runtime environment. You must have a copy of the JRE on your system to run Java applications and applets. The JRE contains the JavaVM and the runtime libraries required to execute java programs.
JDK
Java Development Kit (formerly known as the SDK). To develop Java applications and applets, you need the JDK, which includes the JRE.
applets
Java applets are special applications that must be run through a web browser or a special “applet viewer.” When a web page with an embedded applet is downloaded, the local Java VM executes the applet.
servlets
Java servlets are special applications that run on the server side of a client/server architecture. They are often part of interactive Web programs.
Control flow diagrams
Control flow diagrams are graphs that use the following notations:
Rectangles represent statements (the statement goes inside the rectangle).
Diamonds represent decisions, including loops (the condition goes inside the diamond).
The connections between rectangles and diamonds, rectangles and rectangles, and diamonds and diamonds indicate the flow of control of execution.
Software metrics
Metrics are quantitative measures (applying a metric gives an actual number). They are supposed to be objective, consistent, and reproducible. There are ongoing attempts to make them relevant to management of software projects. Numerous software metrics cover a variety of properties from lines of code to number of lines of customer requirements!
Cyclomatic complexity
(also called conditional complexity) is a software metric that measures the number of execution paths through a method. Cyclomatic complexity was developed in 1976 by Thomas McCabe.
Cyclomatic complexity has a formula:
Cyclomatic complexity = #decisions + 1
Code coverage
Code coverage is a software testing metric. It measures how much of a program’s source code has been tested.
Method coverage. Did you execute each method?
Statement coverage. Did you execute each statement?
Condition/Decision coverage. Was each part of each condition tested with true values and false ones?
Static analysis
means analyzing your code without executing it.
Static analysis includes:
Code inspections and walkthroughs
Identification of code that is likely to cause errors
version control system (VCS)
is a software application that enables users to collaborate on authoring and files.
The VCS does version tracking by automatically recording changes to each file in the repository. The record of changes is called the revision history.
Index (or Staging area)
A file that keeps information on which files will be committed as part of your next revision.
Working directory
The folder that holds the actual files that you do your work on. This is your workspace.
HEAD
A file that points to the most recent versions of the files.
interface
An interface spells out the services that classes must provide by declaring methods but not defining them. Any concrete class that implements an interface defines all of the methods that the interface declares. An interface is essentially a development contract. It ensures that a particular object provides a given set of methods.
characteristics of interfaces
An interface is declared with the keyword interface. Interface methods can be abstract (not defined), default (must be called by an instance of a class that implements the interface), or static (must be called by the interface name). Interface methods that are abstract, static, or default are automatically public. Methods canot be defined in the interface (no method body) unless they are declared as static, default, or private. Static interface methods are defined, and they must be invoked via the interface name rather than via any implementing class. If an interface declares a data member, it is automatically public, static, and final. Interfaces do not have constructors. Interfaces are documented exactly like classes.
Implementing interface without defining methods
If a class implements an interface without defining all of the methods declared in the interface, then the class must be abstract.
declaring interface
You can declare a variable as an interface type.
ForSale x; // declaration
But you cannot instantiate it with the interface. x = new ForSale(); // DOES NOT WORK
You can instantiate it with a concrete implementing class. x = new AirplaneTicket("LHR", "RDU", 988.0);
You can call any of the interface methods on it directly.
if (x.isExpensive()) …
You must cast to its runtime class type before using methods not declared in the interface. System.out.println(((AirlineTicket)x).print());
Static and default interface members
Static interface methods are defined in the interface itself. That is, a static interface method has a body that defines its actions. These methods are called without an instance. They are public.
Default interface methods are also defined in the interface. These methods are also public and they provide a default implementation that the implementing classes can optionally override.
You should call static interface methods with the interface name.
base class
In program design, a base class enables you to factor out what is common and customize what is different among objects with related shapes and behaviors.
child
create a new base class, then extend that base class to create other classes. A class that extends the base class is called a child of the base.
Null constructors in parents
If you do not declare any constructor in a class, Java provides a default null constructor. If you declare a non-null constructor in a parent class but no null constructor, then constructors of its children must make explicit calls to super.
class hierarchy
A class hierarchy consists of a superclass and its descendants.
Everything is an Object
Every Java class that does not extend another class is considered to be a child of Object, which is a class in the java.lang package. Every class is part of the Object class hierarchy.
overloaded
When two methods in the same class have the same name, then the method is said to be overloaded. There are several examples of overloading in the Vehicle class hierarchy:
overrides
When one method in a child class has the same signature (the same name and formal parameter list) as a method in the base class, then the child class method overrides the base class. There are some restrictions on overriding.
Static. If a method is declared static in the base, only another static method can override it.
If a method is declared static in the child, any method it overrides must be declared static.
Access control. A method that overrides a base class method cannot have more restrictive access than what was declared in the base.
hidden
If a subclass declares a field (data member) with the same name as one declared in the base, the base class data member is said to be hidden.
substitution principle
Inheritance in Java follows the substitution principle – whenever a base class type is expected, a child (or descendent) will suffice.
downcasting
casting down a class hierarchy (from ancestor to descendent, and it is called downcasting.
Polymorphism
means that objects respond to messages according to their actual types at runtime rather than their declared types. Polymorphism is also called runtime binding or late binding. That is because you cannot always tell what type of object a reference actually points to until the program is executing.
Note: Polymorphism occurs in the contexts of inheritance and interfaces.
Polymorphism with interfaces
Interfaces are the primary feature of Java that supports polymorphism. With polymorphism, you don’t have to know how a class defines a particular operation, you simply need to know that it does provide it.
Interfaces cannot be instantiated. But you can declare a variable to be an interface type. That variable can reference an instance any class that implements the interface.
Casting
Casting is required when you attempt to call a method for an object that is not declared in the object’s declared type. The first section of this lesson described casting in the context of an inheritance hierarchy. But it can also be used with interfaces. Again, you need to be careful. Attempts to cast to improper types generate ClassCastExceptions.
abstract method.
A method that is declared but that does not have a body is an abstract method. You must declare such a method with the keyword abstract, like this:
public abstract String instructions();