Shared Flashcard Set

Details

010 Basic Concepts & Variables
Cards on Oracle Java Tutorial, Basic OO Concepts & Variables
96
Software
Not Applicable
11/10/2013

Additional Software Flashcards

 


 

Cards

Term
What is an Object
Definition

An object is a software bundle of related state and behavior. Software objects are often used to model the real-world objects that you find in everyday life. 

Term
What is a Class
Definition

A class is a blueprint or prototype from which objects are created. 

Term
What is Inheritance
Definition

Inheritance provides a powerful and natural mechanism for organizing and structuring your software. A class which extends another class is a subclass of the class it extends, which is called the superclass. A subclass inherits all of the methods and fields of the superclass, as well as adding more of it's own.

Term
What is an Interface
Definition

An interface is a contract between a class and the outside world. When a class implements an interface, it promises to provide the behavior published by that interface. 

Term
What is a Package
Definition

A package is a namespace for organizing  a set of related classes and interfaces in a logical manner.

Term
What are the characteristics of real-world objects?
Definition
Real world objects have state and behavior.
Term
How does a Java object store it's state?
Definition
A Java object stores it's state in fields.
Term
How does a Java object expose its behavior?
Definition
A Java object exposes its behavior throught methods.
Term
What is data encapsulation?
Definition
Data encapsulation is the practice of hiding an object's internal state and requiring all interaction to be performed through an object's methods.
Term
Describe the benefit of Modularity
Definition

The source code for an object can be written and maintained independently of the source code for other objects. Once created, an object can be easily passed around inside the system.

Term
Describe the benefit of Information-hiding
Definition

By interacting only with an object's methods, the details of its internal implementation remain hidden from the outside world.

Term
Describe the benefit of Code Re-use
Definition

If an object already exists (perhaps written by another software developer), you can use that object in your program. This allows specialists to implement/test/debug complex, task-specific objects, which you can then trust to run in your own code.

Term
Describe the benefit of Pluggability and debugging ease
Definition

If a particular object turns out to be problematic, you can simply remove it from your application and plug in a different object as its replacement. This is analogous to fixing mechanical problems in the real world. If a bolt breaks, you replace it, not the entire machine.

Term
What is the syntax for creating a subclass?
Definition

At the beginning of the class definition, use the extends keyword immediately after the class name, followed by the name of the class to inherit from, e.g.:

class MySubbie extends MySuper {

// field declarations

// method declarations and definitions

}

Term
Which method must be defined in order to make a complete application?
Definition
The main() method
Term
Which method must be defined in order to create a complete application.
Definition
public static void main(String[] args)
Term
Describe an Interface
Definition

An Interface is a class which is defined with a group of related methods with empty bodies, using the keyword interface for the declaration. 

 

Another class can then be defined using the keyword implements and within this new class the methods identified in the interface class would then be defined. 

 

Furthermore, these implemented interface methods must be declared as public in the implementing method.

Term
What does the acronym API stand for?
Definition
Application Programming Interface
Term
What is an Instance Variable?
Definition

Instance variables are fields whose value is unique to each instance of a class (to each object, in other words). They are also known as non-static fields because they are declared without the static keyword.

Term
What is the difference between an Object and a Class?
Definition

A Class is a blueprint for the an Object. An Object is an instance of a Class.

Term
What is a Class Variable?
Definition

A class variable is any field declared with the static modifier; this tells the compiler that there is exactly one copy of this variable in existence, regardless of how many times the class has been instantiated. Class Variables are also known as Static Fields.

Term
What is a Local Variable?
Definition

A Local Variable is a variable which is declared and used within a single Method. There is no keyword for designating a variable as local.

Term
What is a Parameter?
Definition

A Parameter is a variable which is defined within the parenthesis of a method declaration. A Parameter can also be called an argument. It is not considered a field.

Term
When discussing a Java Class, to what does the term members refer?
Definition
Members refers to the fields, methods and nested classes of that class.
Term
Are variable names case-sensitive?
Definition
Yes.
Term
What is the length limit for a variable name?
Definition
There is no length limit for variable names.
Term
What characters can a variable name begin with?
Definition

Variable names can begin with any letter, a dollar sign or an underscore. 

 

By convention a variable name should only begin with a letter.

Term
What convention(s) should be used when choosing a name for a variable?
Definition
  • A variable name should only begin with a letter.
  • A variable name should contain full words, not abbreviations.
  • A variable name should describe the variable's utility.
  • For non-constants, use all lower case letters for variable names with the exception of the first letter of the second and any subsequent words, which should be upper case.
  • For constants, use all upper case letters throughout and separate words with an underscore.
Term
What does the term 'statically typed' mean?
Definition
The term statically typed is used to differentiate programming languages. When using a programming language which is statically typed, all variables must first be declared before they can be used.
Term
What is the alternative to 'static typing'?
Definition
The alternative to static typing is dynamic typing, where the variable type is determined at run-time. This is more typically seen in scripting languages like Perl and Javascript.
Term
What is a primitive data type?
Definition
A primitive data type is defined by the programming language and is named by a reserved keyword.
Term
What are the eight primitive data types within the Java programming language?
Definition

boolean 

byte 

char 

double 

float 

int 

long 

 

short 

 

Term
What is a signed two's complement integer?
Definition

A signed two's complement integer is a whole number value data type which contains positive and negative values. The range of values is determined by the maximum value of a binary number that is one bit smaller. The first bit of a signed two's complement integer identifies whether the value is positive or negative. In the Java programming language, the maximum negative value of a signed two's complement integer is one greater than the maximum positive value.

Term
What is the value range of the byte primitive in the Java language?
Definition
-128 to 127
Term
How many bits are used to store a byte primitive in the Java language?
Definition
8 bits.
Term
What are the four integer primitive data types in the Java programming language?
Definition
byte, short, int and long.
Term
How many bits are used to store a short primitive in the Java language?
Definition
16 bits.
Term
What is the value range of the short primitive in the Java language?
Definition
-32768 to 32767
Term
How many bits are used to store the int primitive in the Java language?
Definition
32 bits
Term
What is the value range of the int primitive in the Java language?
Definition

-231 to 231 - 1

or

-2,147,483,648 to 2,147,483,647

Term
How many bits are used to store the long primitive in the Java language?
Definition
64 bits
Term
What is the value range of the long primitive in the Java language?
Definition

-263 to 263 - 1

or

9,223,372,036,854,775,808 to 9,223,372,036,854,775,807

OR 

negative 9 quintillion, 223 quadrillion, 372 trillion, 36 billion, 854 million, 775 thousand and 808 to 9 quintillion, 223 quadrillion, 372 trillion, 36 billion, 854 million, 775 thousand and 807

Term
How many bits does a float primitive data type use in the Java programming language?
Definition
32 bits
Term
Is the float data type an integer?
Definition
No, the float data type is a single-precision floating point.
Term
Should the float data type be used for calculating precise values? Why or why not?
Definition
No, because of rounding rules supported by the IEEE 754 floating poing technical standard. java.math.BigDecimal is recommended for calculating precise values.
Term
How many bits are used to store the double primitive data type in the Java programming language?
Definition
64 bits
Term
Is the double primitive data type an integer?
Definition
No. The double data type is a double-precision 64-bit IEEE 754 floating point.
Term
Should the double data type be used for calculating precise values? Why or why not?
Definition
No, because of rounding rules supported by the IEEE 754 floating poing technical standard. java.math.BigDecimal is recommended for calculating precise values.
Term
How many bits are used to store a boolean primitive data type in the Java programming language.
Definition
The number of bits used to store a boolean is not precisely defined.
Term
How many possible values can a boolean primitive data type contain in the Java programming language?
Definition
Only two: true or false.
Term
How many bits are used to store a char primitive data type in the Java language?
Definition
16 bits
Term
What sort of data is stored by the char primitive data type?
Definition
char can only contain a single 16 bit Unicode character.
Term
Is a String considered a primitive data type in the Java programming language?
Definition
Not technically. It is actually an object.
Term
How does one change the value of a String object?
Definition
Trick question. String objects are immutable, which means that once created their values cannot be changed.
Term
Is it necessary to assign a value when a field is declared?
Definition
No.
Term
What is the default value assigned to a field of the byte data type?
Definition
0
Term
What is the default value assigned to a field of the short data type?
Definition
0
Term
What is the default value assigned to a field of the int data type?
Definition
0
Term
What is the default value assigned to a field of the long data type?
Definition
0L
Term
What is the default value assigned to a field of the float data type?
Definition
0.0f
Term
What is the default value assigned to a field of the double data type?
Definition
0.0d
Term
What is the default value assigned to a field of the char data type?
Definition
'\u0000'
Term
What is the default value assigned to a field of the boolean data type?
Definition
false
Term
What is the default value assigned to a field of the String data type?
Definition
A String is technically an object and not a data type. The default value for ALL objects is null.
Term
What is the default value assigned to a local variable of the byte data type?
Definition
There is no default value assigned to any local variable, regardless of type.
Term
What is the default value assigned to a local variable of the short data type?
Definition
There is no default value assigned to any local variable, regardless of type.
Term
What is the default value assigned to a local variable of the int data type?
Definition
There is no default value assigned to any local variable, regardless of type.
Term
What is the default value assigned to a local variable of the long data type?
Definition
There is no default value assigned to any local variable, regardless of type.
Term
What is the default value assigned to a local variable of the float data type?
Definition
There is no default value assigned to any local variable, regardless of type.
Term
What is the default value assigned to a local variable of the double data type?
Definition
There is no default value assigned to any local variable, regardless of type.
Term
What is the default value assigned to a local variable of the char data type?
Definition
There is no default value assigned to any local variable, regardless of type.
Term
What is the default value assigned to a local variable of the boolean data type?
Definition
There is no default value assigned to any local variable, regardless of type.
Term
What is the default value assigned to a local variable of the String data type?
Definition
First of all, a String is technically an object and not a data type. Second of all, there is no default value assigned to any local variable, regardless of type.
Term
Do primitive data types require the new keyword when they are initialized? Why or why not?
Definition
Primitive data types do not require the new keyword because they are special data types that are built into the language, they are not objects which are created from a class.
Term
Can a literal value be assigned to an object at instantiation in the Java programming language?
Definition
No. A literal value is the source code representation of a fixed value which cannot be assigned to an object at instantiation (unless there is a constructor method in the object's class definition which contains parameter variables, i.e. arguments). Conversely, a literal value can be assigned to a primitive data type upon instantiation.
Term
What is the syntax for assigning an integer literal to the long primitive data type?
Definition

An integer literal is of type long if it ends with the letter L or l; otherwise it is of type int. It is recommended that you use the upper case letter L because the lower case letter l is hard to distinguish from the digit 1.

Term
What are the three numbering systems that an integer literal can be expressed as?
Definition
  • Decimal (base 10) (most common)
  • Hexidecimal (base 16)
  • Binary (base 2)
Term
What is the syntax for assigning a hexidecimal integer literal?
Definition
A prefix of '0x' indicates hexidecimal
Term
What is the syntax for assigning a binary integer literal?
Definition
A prefix of '0b' indicates binary
Term
What is the syntax for assigning an floating-point literal to the float primitive data type?
Definition
A floating-point literal is of type float if it ends with the letter F or f.
Term
What is the syntax for assigning an floating-point literal to the double primitive data type?
Definition
A floating-point literal is of type double if it ends with the letter D or d.
Term
Can float or double be assigned a value with any other syntax? If yes, which of these primitive data types can and what is the required syntax?
Definition

Both of the floating point types (float and double) can also be expressed using E or e (for scientific notation). 

 

By way of example here is the same value being assigned to a double:

double d1 = 123.4;

double d2 = 1.234e2;

Term
What are the different kinds of literal assignments.
Definition
Integer Literals, Floating-Point Literals, Character and String Literals, the Null and the Class literals.
Term
Describe and differentiate the null literal.
Definition
The null literal that can be used as a value for any reference type. null may be assigned to any variable, except variables of primitive types.
Term
What is the syntax and function of a class literal?
Definition
A class literal is formed by taking a type name and appending ".class"; for example, String.class. This refers to the object (of type Class) that represents the type itself.
Term
When assigning a numeric literal, is there any character which can be used for the programmer's benefit to show breaks in the number being assigned? If so, what is it?
Definition

Yes, underscore characters can be employed when assigning a numeric literal in order to improve the readability of the assignment. Underscore characters can be thought of as the commas used to differentiate between thousands and millions, for example, but unlike those commas, an underscore character can be placed ALMOST anywhere within the number being assigned as a literal. You can place underscores only between digits; you cannot place underscores in the following places:

  • At the beginning or end of a number
  • Adjacent to a decimal point in a floating point literal
  • Prior to an F or L suffix
  • In positions where a string of digits is expected
Term
Describe an array
Definition
An array is a container object that holds a fixed number of values of a single type.
Term
When is the length of an array established?
Definition
The length of an array is established when the array is created. After creation, its length is fixed.
Term
What is the numeric index of the first element in an array?
Definition
The first element in an array is always zero.
Term
What are the acceptable syntax variations for declaring an array? What is the encouraged version?
Definition

An array can legally be declared in the following ways:

 

//example 1

int[] myIntegerArray;

 

//example 2

int myIntegerArray[];

 

Although both will compile, the convention is to place the brackets immediately after the type (example 1)

Term
What is the syntax for creating an array?
Definition

One way to create an array is with the new operator, followed by the array type and a number in brackets which determines the array size. E.g:

 

myIntegerArray = new int[10];

 

Alternatively an array can be created using a shortcut syntax which consists of the variable type, followed by empty brackets, followed by the variable name, followed by an equal sign, followed by a comma delimited list of valid values enclosed within curly brackets. E.g.:

int[] myIntegerArray = { 100, 200, 300, 400 };

Term
Is it possible to have an array that is more than one dimensional? If so, what is the syntax for defining it?
Definition
Yes, it is possible to declare an array of arrays (also known as a multidimensional array) by using two or more sets of brackets at the time the variable is being declared. It is possible to instantiate multidimensional arrays in the same way that regular arrays are created.
Term

What is the command to determine the size of an array and what is the syntax for using it?

Definition

Use the built-in length property to determine the size of any array. E.g.:

 

System.out.println(myIntegerArray.length);

Term
What is the method used for copying elements of one array to another? To which class does it belong? What is the syntax for using it?
Definition

The System class has an arraycopy() method that you can use to efficiently copy data from one array into another:

 

public static void arraycopy(Object src, int srcPos,

                           Object dest, int destPos, int length)

 

The two Object arguments specify the array to copy from and the array to copy to. The three int arguments specify the starting position in the source array, the starting position in the destination array, and the number of array elements to copy.

Term
What is the class provided in the Java programming language for performing common array related tasks besides arraycopy()?
Definition
Java SE provides several methods for performing array manipulations (common tasks, such as copying, sorting and searching arrays) in the java.util.Arrays class.
Supporting users have an ad free experience!