ISYS 303 - Ch. 1-4 Flashcards

1
Q

The “if” statement

A
if (condition)
{ 
     statement(s);
}
else if(condition)
{
     statement(s);
}
else
{
     statement(s);
}
***condition is a Boolean expression (the statement is either true or false) 
The if statement only takes ONE statement after the if. That is why we use the curly braces. Then, the curly braces represent ONE statement but they can contain many statements
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

The “for” loop

A

for (initialization; condition; iteration)
{
statement;
}
**initialization - sets a loop control variable to an initial value
**
condition - is a Boolean expression that tests the loop control variable. If the outcome of that test is true, the for loop continues to iterate, but if it is false the loop terminates
***iterate - determines how the loop control variable is changed each time the loop iterates
The for loop consists of 3 parts and each is separated by a semi colon: initializing of the variable, the condition, and the update to the variable

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

code block

A
  • another key element of Java
  • it’s a group of two or more statements, it is done by enclosing the statements between opening and closing curly braces
  • the statements become a logical unit that can be used at any place that a single statement can, one statement cannot execute without the other also executing
  • The curly braces { } are used to create blocks of code. They are often used in if, for, while, and other java statements when you want more than one line to be connection to the if, while, for, etc.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

semicolon

A
  • is a separator that is used to terminate a statement, each individual statement must be ended with a semicolon, it indicates the end of one logical entity
  • a code block IS NOT terminated by a semicolon, the end of the block is indicated by the closing brace
  • java does not recognize the end of the line as a terminator, does not matter where on a line you put a semicolon
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What is bytecode? Why is it important to Java’s use for Internet programming?

A

Bytecode is a highly optimized set of instructions that is executed by the Java run-time system, which is called the Java Virtual Machine (JVM). Bytecode helps Java achieve both portability and security.
Java source code (the java statements) are compiled into Java Bytecode (set of highly optimized instructions) which is executed by the Java Virtual machine (JVM). Using bytecode makes the programs more portable and flexible since the JVM can be implemented for those environments.
***NOT EXECUTABLE CODE

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What are the three main principles of object-orientated programming?

A
  • Encapsulation
  • Polymorphism
  • Inheritance
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What is a variable?

A

-a named memory location
-the contents of a variable can be changed during the execution of a program
A variable is a holding spot (or a “pocket”) where you can tell the computer to set up a place in memory to hold a value for later use
Unlike VBA, Java requires you to tell the system what type of variable you will want to use
***CANNOT START WITH A NUMBER

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Scanner Class

A
Scanner iScan = new Scanner(System.in) 
then you create another variable to hold iScan: 
iNumInput = iScan.nextInt() 
***.nextInt can be anything from nextDouble, nextFloat, nextLine, and so on 
***make sure to initialize the variable holding the scanner variable
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Random Class

A
Random iRndNum = new Random();
then you create another variable to hold iRndNum: 
iGameScore = iRndNum.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Import

A

BEFORE setting up any type standard class, make sure use: import java.util.* after “package” to be able to use any standard class like Scanner or Random

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What is JVM?

A

Java Virtual Machine - designed as an interpreter for bytecode, only JVM needs to be implemented for each platform (although different on platforms all JVMs can understand the same bytecode)
-helps make it secure because JVM is in control, it can contain the program and prevent it from generating side effects outside of the system
Java programs are executed within a java environment making them more secure. If something goes wrong (i.e. virus, etc.) then the entire system will NOT be affected. The java execution environment can confine the program to the environment and not allow access to other parts of the computer

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

Java Buzzwords - Simple

A

Simple – Java has a concise, cohesive set of features that makes it easy to learn and use

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

Java Buzzwords - Secure

A

Secure – Java provides a secure means of crediting Internet applications

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

Java Buzzwords - Portable

A

Portable – Java programs can execute in any environment for which there is a Java run-time
system

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

Java Buzzwords - Object Oriented (OOP)

A

Object-orientated – Java embodies the modern, object orientated programming philosophy

OOP are organized around the data, with the key priniciple being "data controlling access to code." You define the data and the routines that are permitted to act on that data 
In an object oriented world, a class is a template or mold that determines what an object will look like and how it will performance through the use of attributes (they describe the object), methods (they do the work), and events (they respond to other objects)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

Java Buzzwords - Robust

A

Robust – Java encourages error-free programming by being strictly typed and performing run-time checks

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

Java Buzzwords - Multithreaded

A

Multithreaded – Java provides integrated support for multithreaded programming

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
18
Q

Java Buzzwords - Architecture-neutral

A

Architecture-neutral – Java is not tied to a specific machine or operating system architecture

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
19
Q

Java Buzzwords - Interpreted

A

Interpreted – Java supports cross-platform code through the use of Java bytecode

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
20
Q

Java Buzzwords - High performance

A

High performance – The Java bytecode is highly optimized for speed of execution

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
21
Q

Java Buzzwords - Distributed

A

Distributed – Java was designed with the distributed environment of the Internet in mind

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
22
Q

Java Buzzwords - Dynamic

A

Dynamic – Java programs carry with them substantial amounts of run-time type information that is used to verify and resolve accesses to objects at run time

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
23
Q

Java Buzzwords

A

We like java because it is simple, secure, portable, object oriented, multithreaded, has high performance due to the bytecode, and more

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
24
Q

Encapsulation

A

-programming mechanism that binds together code and the data it manipulates, and keeps it both safe from the outside interference and misuse
Encapsulation (or black box) hides the details from the world to make life easier. We don’t care how it works, we just want it to work
Code & data are found in the box, when code & data are linked together in this way, an object is created. An object is the device that supports encapsulation.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
25
Q

Private vs. Public

A

Within an object, code, data, or both may be private to that object or public.
The keyword public means something is visible to everyone and everything within the java program, other parts of your program can access it even thought it is defined within an object
Private code - known to and accessible by another part of the object. It cannot be accessed by a piece of program that exists outside the object

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
26
Q

Polymorphism

A
-is the quality that allows one interface to access a general class of actions. "one interface, multiple methods" 
Helps reduce complexity by allowing the same interface to be used to specify a general class of actions 

Polymorphism allows one interface (method) to be executed in many different ways depending on how you want to use it. For example, you can print a word doc, excel spreadsheet, jpg image, etc just by calling the print method. You only need to remember the one method and the system determines how the method will work

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
27
Q

Inheritance

A

process by which one object can acquire the properties of another object. Using inheritance, an object need only define those qualities that make it unique within its class and can inherit its general attributes from its parent.

is when one object (child) is based upon another object (parent). The child object can get everything (attributes, methods, etc.) that the parent wants to pass down to the child class (subclass).

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
28
Q

Javac

A
Javac is a special keyword that can be used at the command.com prompt (windows) to compile java source code (a file with the extension of .java and contains  java statements)
The result of compiling the java source code file is another file with the same name as the source code file but with an extension of .class
You can run the results of the compilation (the .class file) through the use of the java key word at the command prompt
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
29
Q

System.out.println vs. System.out.print

A

System.out.println is a method that prints something to the screen and then does a carriage return (drops to the next line and positions the cursos at the beginning of the line)
System.out.print is a method that prints something to the screen but does NOT do a carriage return. The cursor stays on the same line waiting to do something. If you print again it will pick up from the same spot where it left off.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
30
Q

Main

A

Main is a special method that tells java where to start the execution process within a java program
Java is case sensitive (meaning that a capital A is different from a lower case a)

31
Q

Class

A
Java's basic unit of encapsulation is the class. Class defines the form of an object, specifies both the data and the code that will operate on that data. Uses class to create objects (instances of a class)
Blueprint of how to build an object
32
Q

The arithmetic operators are:

A
\+ (add) 
- (subtract)
* (multiply) 
/ (divide) 
% (modulus - give the remainder) 
\++ (increments by 1) 
-- (decrements by 1)
33
Q

Some of the different data types are:

A

Integers: int, long, short, byte
Floating point: float (single precision), double(double precision)
Characters: char
Strings: String
Boolean (represents true or false, yes or no)

34
Q

String

A

Strings are created through the use of double quotes “ “. You can even have a string that has only one character but it is still a string.
For example, “A”
String variables are created through the use of the String key word. For example, String sName = “Greg”;

35
Q

Scope and Lifetime of Variables

A

Each variable has scope and lifetime. Scope means where the variable can be seen within the program (i.e. package, method, for loop, etc.). Lifetime means how long the variable occupies memory until it dies and the garbage collector reclaims the memory for the system

  • Code block defines a scope
  • Variables declared inside a scope are not visible (aka accessible) to code that is defined outside that scope
  • Scopes can be nested: when this occurs, objects declared in the outer scope will be visible to code within the inner scope, but reverse not true
36
Q

Character Escape Sequences

A
\' = single quote 
\" = double quote 
\\ = backlash 
\r = carriage return 
\n = new line 
\f = form feed 
\t = horizontal tab 
\b = backspace 
\ddd = octal constant (where ddd is an octal constant)
\uxxxx = hexadecimal constant (where xxxx is a hexadecimal constant)
37
Q

Initializing a Variable & dynamic intialization

A

type var-Name = value;

when you initialize a value at run time

38
Q

increment and decrement

A

The increment and decrement have a pre and post method meaning that if you place the ++ before the variable it is a pre (++iCount) and if you place it after the variable it is a post (iCount++). The pre means that it will increment the variable before anything else is accomplished on that line. The post allows everything else to happen on that line before it increments the variable by 1. The decrement works the same way. You cannot increment or decrement by more than one using the ++ or –

39
Q

The logical operators are:

A

& (and)
| (or - also called the pipe sign)
^ (exponential - XOR exclusive OR)

40
Q

The logical operators also have short circuit operators:

A

&& (and)
|| (or)
! (not)

The short circuit operators say that if you can figure out the answer for an expression then you don’t have to keep checking. In other words, if you had a F and T, the system would see F AND, resulting in a False value and just stop. It would even keep checking the rest of the equation

41
Q

The truth table for the AND is:

A

T and T = T, T and F = F, F and T = F, F and F = F. IOW, everything must be true in order for an AND to return a true

42
Q

The truth table for the OR is:

A

T or T = T, T or F = T, F or T = T, F or F = F. IOW, at least one value must be T and the OR will return a true

43
Q

= vs. ==

A

The single = is the assignment operator. Be careful because many people try to use it as the compare operator. That will cause a lot of problems. Remember, the compare operator is the double ==

44
Q

shorthand assignments:

A

+= means to take a value and add it back to the value. IOW, x +=5 means x = x + 5.
This applies to all mathematical operators. It is like shorthand for doing assignments. However, it might also affect readability

45
Q

casting

A

We might also need to convert one value to another value depending on what we are trying to accomplish. The is done through the use of casting. In casting you take the new data type you wish to create and surround it by parentheses. For example, if you had a variable already declared as a double called dNumber, you could convert it to an integer by casting, iNumber = (int) dNumber. You would need to declare the target variable beforehand (i.e. int iNumber;)
Cast is needed when converting between imcompatible types or when a narrowing conversion is occuring.

46
Q

Switch statement

A
switch(expression)
{
     case constant1:
          statement sequence
          break;
     case constant2:
          statement sequence
          break;
     default:
          statement sequence
}
The switch statement is a glorified if statement. 
If you don't use a break statement within the case, then once one case evaluates to true, ALL of the cases are true and will execute.
The default part of the switch is lke the garbage collector. If none of the others are true, then the default executes
47
Q

while loop

A

while(condition)
{
statement;
}
the condition may be any valid Boolean expression. The loop repeats while the condition is true. When the condition becomes false, program control passes to the line immediately following the loop.
The while loop is a pre condition loop. It checks the condition BEFORE it enters the loop. The minimum number of times a for loop will execute is 0 because if the condition is false immediately, the for loop exits.

48
Q

do-while loop

A
do 
{
     statements;
} 
while(condition);
The do-while loop is a post condition loop. This means that it checks the condition after it has run through the loop's code at least one time
49
Q

What happens when you create a Java class?

A

Java creates a .java file with the same name as the class

50
Q

Why does Java strictly specify the range and behavior of its primitive types?

A

to ensure portability across platforms

51
Q

Char (character type), how does it differ from the character type used by some other programming languages?

A

Java characters (char) are Unicode rather than ASCII, which is used by some other computer languages

52
Q

What is wrong with the fragment?

for( i = 0; i

A
  1. sum is created each time the block defined by the for loop is entered and destroyed on exit. Thus, it will not hold its value between iterations. Attempting to use sum to hold a running sum of the iteration is pointless.
  2. sum will not be known oustide of the block in which it is declared. Thus, the reference to it in the println() statement is invalid
53
Q

Show how a short-circuit AND can be used to prevent a divide by zero error?

A

if( b != 0) && (val / b)) …

54
Q

Does the use of redundant parenthesis affect program performance? Does a block define a scope?

A

No, Yes

55
Q

Read input from the keyboard

A

System.in.read()

56
Q

General form of a class (creates a new data type)

A
class classname 
{
     //declare instance variables
     type variName1;
     type variName2;
     //declare methods 
     type method1(parameters)
     {
          //body of method
     }
}
57
Q

Methods

A

subroutines that manipulate that data defined by the class and, in many cases, provide access to that data

ret-type name(parameter-list) 
{
     //body of method
} 
***ret-type = specifies that type of data returned by the method
***if the method doesn't return a value, it's ret-type is "void"
58
Q

parameters

A

variables that receive the value of the arguments passed to the method when it is called. If the method has no parameters the parameter list will be empty

59
Q

“for” loop example

A

for( iCount = 0; iCount

60
Q

The relational operators are:

A

== (compare)
!= (not equal)
> (greater than)
>= (greater than or equal to)

61
Q

What is the difference between a class and an object?

A

A class is a logical abstraction that describes the form and behavior of an object. An object is a physical instance of the class.

62
Q

How is class defined?

A

A class is defined by using the keyword class. Inside the class statement, you specify the code and data that comprise the class.

63
Q

What does each object have its own copy of?

A

own copy of instance variables

64
Q

How must a method return if it returns a value?

A

A method that returns a value must return via the return statement, passing back the return value in the process

65
Q

What name does a constructor have?

A

Same name as the class

66
Q

What does NEW do?

A

the NEW operator allocates memory for an object and initializes it using the object’s constructor

67
Q

What is the “this” keyword?

A

The “this” keyword is a reference to the object on which a method is invoked. It is automatically passed to a method.

68
Q

How objects are created?

A
NameClass VariName = new NameClass();
EX: 
Vehicle minivan = new Vehicle();
***the new operator dynamically allocates memory for an object and returns a reference to it. This reference is more or less the address in memory of the object allocated by new. This reference is then stored in a variable.
Vehicle minivan; //declare reference to object 
minivan = new Vehicle(); //allocate a Vehicle object
69
Q

Reference vs. Value

A
  • **the new operator dynamically allocates memory for an object and returns a reference to it. This reference is more or less the address in memory of the object allocated by new. This reference is then stored in a variable. When you assign one object reference variable to another, the situation is a bit more complicated because you are changing the object that the reference variable refers to
  • **when you assign one primitive type variable to another, the variable on the left receives a COPY of the VALUE of the variable on the right.

Objects and arrays are passed by reference meaning that their memory location is passed. This means that if you change a value in the array or object in the receiving method, the change will automatically be seen in the array or object when you leave that method and return to where it was called.
Strings, ints, etc. are passed by value meaning that a copy of the data is passed. This means that if you change the value in the receiving method, the change is NOT reflected back in the calling method

70
Q

Method Overloading

A

-2+ methods within the same class can share the same name, as along as their parameter declarations are different.
-to overload a method, simply declare different versions of it
Methods can be overloaded. This means that you can have multiple methods in a class with the same name as long as the signature (or the number and types of parameters) is different
-Return types (Return & Void) cannot be used to differentiate overloaded methods, will return an error

71
Q

Constructor Overloading

A

You can also overload constructors the same way as overloading methods
Remember that once you write your own constructor, Java backs out of the picture and does not provide a default (or empty) constructor

72
Q

Understanding Static

A
When a member is declared "Static" it can be accessed before any objects of its class are created, and without reference to any object. You can declare both variables and methods to be static 
Static means that you do not need an object from the class to acess the static attribute or method. You instead use the class name. For example, if the Student class had a static variable called StudCount, you could access it by using the class name and the attribute
Static method is called using the class name
Static variables are shared
73
Q

Static Example

A
class Student
{
   static int StudCount;
   other code
}

{
back in another method
Student.StudCount++;
}