JAVA FINAL 14

Lakukan tugas rumah & ujian kamu dengan baik sekarang menggunakan Quizwiz!

Difference between & and &&

& is bitwise. && is logical. & evaluates both sides of the operation. && evaluates the left side of the operation, if it's true, it continues and evaluates the right side.

UML Notation

...

Constructor vs Method

A Constructor is a member function of a class that is used to create instances of that class. It has the same name of the class itself, has no return type and is invoked using the new operator. A method is an ordinary member function of a class. It has its own name, return type (which may be void), and is invoked using the dot operator.

abstract data type vs abstract class

A java abstract class is a class with at least one abstract method and no body. An abstract data type is a specification of a type's operations that could be implemented in any object oriented programming.

Nested Loop

A loop as one of the statements in the body of another loop. Random rnd = new Random(); while (true) { System.out.println(rnd) if(true){ } System.out.print(rnd) }

Truth Table

A means of listing all of the possible values of a Boolean expression ex: (based off of the code from page 246) Look up for more detail: Ex:

Combinatorial Explosion

A multiplicative growth. ex: If in A is introduced it has two possible states true or false. When B is introduced there are 4 possible states.

Output Assertion

A postcondition for a loop ex: As in a do-while loop, the while is post conditional, therefore the final value (if not instantiated correctly) will contain a off-by-one error. A do-while loop performs postcondition

What is a requirements document?

A precise specification of what the software should do.

Input Assertion

A precondition for a loop ex: int d; int j = 10; do{ d++ while }(int j<=20);

Nested "if" Statement

A selection statement used within another selection statements. ex: ex: if(j<=0) { System.out.println("Example"); if(m<10) System.out.println("Example"); else { System.out.println("Example"); } else { System.out.println("Example"); } } else { System.out.println("Example"); }

Complete Code Coverage

A set of test in which every line in a program is executed at least once. ex: { int a, b; a=2; b=5; if (a<0) && (b>2) { System.out.println("Example"); } else { System.out.println("Example"); } } this insures quality assurance

Arithmetic Overflow

A situation that arises when the computer's memory cannot represent the number resulting from an arithmetic operation. ex: when an error occurs when trying to do an arithmetic problem when the final result number is too large for the primitive storage type to store. Also, Data too large for the data type chosen

Unicode

A standardized 16-bit character set that represents the character sets of most major languages in the world. The letters entered have to be above 192.

Variable Declarations

A statement that typically specifies two things about a variable: The variable's name and the variable's data type. Must be done before it can be used in a program.

Class

A template in accordance to which objects are created. Includes a data specification and functions operating on these data and possibly on the data belonging to other class instances.

Boundary Condition

A value at which two equivalence classes meet. ex: (exsampleClassA >= 0 || > exsampleClassB)

Byte

A variable type that is a sequence of 8 bits (enough to represent one character of alphanumeric data) processed as a single unit of information, Range [-127,128]

What is an abstract class?

Abstract classes, unlike interfaces, are classes. There are more expensive to use because there is a lookup to do when you inherit from them. Abstract classes look a lot like interfaces, but they have something more : you can define a behavior for them.

Equivalence Class

All the sets of test data that exercise a program in the same manner ex: all data types listed.

Blocks

Also known as compound statement, are marked by delimiting with braces { }.

Logical Invariant

An assertion that expresses a relationship between variables that remains constant throughout all iterations of the loop. ex: for(int j=0;j<=10;j++ ) { J++ } J in this case would change and check a counter which will add 1 to J and check if J is less than or equal to 10.

Loop Variant

An assertion whose truth changes between the first and final execution of the loop. ex: During a loop when executed Such as a for loop when a value has matched the final requirement either by making a value true or proving it false.

Class method vs Instance method

An instance method is declared without the static modifier and is invoked using the name of the object to which it is bound.

What is an interface?

An interface is a special form of an abstract class which does not implement any methods. An interface is an empty shell, there are only the signatres of the methods. It can't do anything.

What is the difference between Assignment and Initialization?

Assignment can be done as many times as desired whereas initialization can be done only once.

What are Class, Constructor and Primitive data types?

Class is a template for multiple objects with similar features and it is a blue print for objects. It defines a type of object according to the data the object can hold and the operations the object can perform. Constructor is a special kind of method that determines how an object is initialized when created. Primitive data types are 8 types and they are: byte, short, int, long, float, double, boolean, char.

What is the difference between composition vs aggregation.

Composition, is when a type is composed of another type, the complete existence of that component type's objects is controlled by the composing type's object; The components are uniquely bound to it and cannot be changed by any outside object. Aggregation, the component elements exists outside the collection, can be changed by other classes, and may even be components of other aggregates.

What is the difference between constructor and method?

Constructor will be automatically invoked when an object is created whereas method has to be called explicitly.

Extreme Condition

Data at the limits of validity ex: When a data type is (almost) overwhelmed by the data value; an int hold (almost) or trying to hold past its 32 bit limit which it will succeed.

What is the difference between design state and the implementation stage in the development of software?

Design Stage : identifies the components(classes) to be used and the relationships among them. Implementation Stage: is where the computer program code is actually written.

Logical Operator

Either of the logical connective operators && (and), || (or), or ! (negation) ex: (in use) (exsampleClassA >= 0 || > exsampleClassB), or (exsampleClassA >= 0 && > exsampleClassB) or (exsampleClassA >= 0! > exsampleClassB)

What are Encapsulation, Inheritance and Polymorphism?

Encapsulation is the mechanism that binds together code and data it manipulates and keeps both safe from outside interference and misuse. Inheritance is the process by which one object acquires the properties of another object. Polymorphism is the feature that allows one interface to be used for general class actions.

What is an abstract data type?

I a specification of the type's operations: what an instance of that type can do.

What is meant by Inheritance and what are its advantages?

Inheritance is the process of inheriting all the features from a class. The advantages of inheritance are reusability of code and accessibility of variables and methods of the super class by subclasses.

Integer Literals

Integers embedded into Java source code, can be expressed as a decimal number by any sequence of digits 1-9. Are considered 32 bits long but can be converted by following them with a "L".

IPv4

Internet Protocol version 4, , Uses a header format that is 20 octets and combined with the TCP segment forms an IP PDU or IP Datagram or IP Packet. The source and destination address field is 32 bits. Is now actually obselete.

IPv6

Internet Protocol version 6, IPv6 An extended scheme of IP addresses, using 128-bit IP addresses, that allows for more IP addresses than current system, IPv4, which uses 32-bit IP addresses.

Java Program

Is a sequence of statements(smallest executable unit) that have to be formed in accordance with a predefined syntax.

What is a package?

It is a namespace, a name for a group of classes, interfaces and enum types that can be used to distinguish those from other classes, interfaces and enum types of the same name.

Overloading Polymorphism : ad-hoc

It means integer addition when used in form 22 + 33; it means floating point addition when used in the form 2.2 + 3.3; and it means string concatenation when used in the form + ", esq."

Inclusion Polymorphism

It refers to the ability an object to invoke a method that it inherits; public class TestRatio{} Ratio x = new Ration(); x.hashCode(); <--- inheritated

What is method overloading and method overriding?

Method overloading: When a method in a class having the same method name with different arguments is said to be method overloading. Method overriding : When a method in a class having the same method name with same arguments is said to be method overriding.

Methods

Name for functions that are defined in a class..

Class scope variables

Name for variables that are used in a class.

Extended "if" Statement

Nested selection in which additional "if-else" statements are used in the else option. ex: if(j<=0) { System.out.println("Example"); } else { System.out.println("Example"); if(m<10) System.out.println("Example"); else { System.out.println("Example"); } }

Coercion Polymorphism : ad-hoc

Occurs when a value of one type is implicitly converted to a value of another type when the context requires that other type. ie: 22 + 3.3 it interprets the plus operator as a floating point addition, requiring both operands to be either type float or type double. So it "coerces" the 22 into being 22.0 and then performs the operation

Parametric Polymorphism

Occurs with generic methods, where an actual type is substituted in for a type parameter. static <T> void print(T[] a) { for(T t : a) { System.out.printf("%s", t); } System.out.println(); }

Difference between public, protected and private?

Public: are globally accessible. Protected: are accessible by classes and subclasses. Private: are accessible only from its own class.

What is the result of the conditional expression above?

Result is the conditional expression is EXPRESSION1 if BOOLEAN-EXPRESSION is true; otherwise the result is EXPRESSION2

Suppose that, when you run the following program, you enter input 2 3 6 from the console. What is the output? public class Test { public static void main(String[] args) { java.util.Scanner input = new java.util.Scanner(System.in); double x = input.nextDouble(); double y = input.nextDouble(); double z = input.nextDouble(); System.out.println((x < y && y < z) ? "sorted" : "not sorted");

Sorted

Variable names

Strings of any length of letters, digits, underscores, and dollar signs that begin with a a letter, underscore, or dollar sign.

What is the purpose of declaring a field private and declaring a mutator method that allows the public to change it.

The advantage of forcing the public to use a mutator method to change a field is that you can control how the field is changed.

what is an enum type.

The enum type is a type defined with the enum keyword that list by name each possible value for the type.

What is the difference between exception and error?

The exception class defines mild error conditions that your program encounters. Exceptions can occur when trying to open the file, which does not exist, the network connection is disrupted, operands being manipulated are out of prescribed ranges, the class file you are interested in loading is missing. The error class defines serious error conditions that you should not attempt to recover from. In most cases it is advisable to let the program terminate when such an error is encountered.

Octal

The numbering system using 8 as its base, using the numerals 0-7 as its digits. In programs written in the Java programming language, octal numbers must be preceded with 0.

Quality Assurance

The ongoing process of making sure that a software product is developed to the highest standards possible subject to the ever present constraints of time and money. ex: The Maintenance part of a program's lifetime. As time goes on software companies try and fix bugs or problems with programs. This can be seen with java. When it was first created it had many security hole many of which have been patched up, making the product closer to perfection.

Data encapsulation

The separation of the representation of data from the applications that use the data at a logical level; a programming language feature that forces information hiding.

Robust

The state in which a program is protected against most possible crashes from bad data and unexpected values. ex: This is part of the maintenance process of a program. There is no such thing as a perfect bug free program, but programs can be created to the best of their own ability. This can be seen with a theoretical perfect program. It should also include valid error messages for invalid data input

What is the difference between the state and the behavior of a class?

The state of a class consists of the values of its fields. The behavior of a class is defined by its methods.

Hexadecimal

These digits operate on a base-16 number These numbers use the letters A, B, C, D, E, and F along with the numbers 0 to 9 to create their 16 different digits, where A represents 10 and F represents 15. In programs written in the Java programming language must be preceded with 0x.

Data Fields

These fields (46 to 1500 bytes) contain the encapsulated data from a higher layer, which is a generic Layer 3 PDU, or more commonly, an IPv4 packet. , variables you declare with a class, but outside of any method.

Create a math program that generates to random numbers to be added together .

This shows how the use of boolean or true/false is used in the answer

What are Transient and Volatile Modifiers?

Transient: The transient modifier applies to variables only and it is not stored as part of its object's Persistent state. Transient variables are not serialized. Volatile: Volatile modifier applies to variables only and it tells the compiler that the variable modified by volatile can be changed unexpectedly by other parts of the program.

Float

Variable type of 32 bits and a range of [-3.4E38,3.4E38]

Double

Variable type of 64 bits and a range of [-1.7E308, 1.7E308]

Long

Variable type of 64 bits and with a range of [-9223372036854775808, 9223372036854775807]

Boolean

Variable type used to represent a single true or false value. Size of 1 bit.

int

Variable type with 32 bits and a range of [-2147483648 to 2147483647] = 4 bytes of storage

Short

Variable type with a size of 16 bits and a range [-32768,32767 ]

Char

Variable type with a size of 16 bytes whose range is all Unicode characters. It has a minimum value of '\u0000' (or 0) and a maxiumum value of '\uffff' (or 65,534 inclusive)

What is Garbage Collection and how to call it explicitly?

When an object is no longer referred to by any variable, java automatically reclaims memory used by that object.

What is the difference between an argument and a parameter?

While defining method, variables passed in the method are called parameters. While using those methods, values passed to those variables are called arguments.

Can you have an inner class inside a method and what variables can you access?

Yes, we can have an inner class inside a method and final variables can be accessed.

What is the difference between procedural and object-oriented programs?

a) In procedural program, programming logic follows certain procedures and the instructions are executed one after another. In OOP program, unit of program is object, which is nothing but combination of data and code. b) In procedural program, data is exposed to the whole program whereas in OOPs program, it is accessible with in the object and which in turn assures the security of the code.

Boxing

converting a primitive value to a wrapper obj.

Polymorphism

describes the way an object or variable my be treated in different contexts as though it was a different type. For example: inheritance allowes an argument of type B to be passed to a parameter of type A if B extends A. It is an object oriented programming feature that allow types to be treated as their parents or extending object.

What is the format of System.out.printf("%3d#%2s#%3.2f\n", 1234, "Java", 51.6653);

displays 1234#Java#51.67

What is a conditional expression ?

evaluates a condition based on an expression

If 1 of the operands of an && is false then the expression is _____?

false--- this is also known as the short-circuit AND operator

What is final, finalize() and finally?

final : final keyword can be used for class, method and variables. A final class cannot be subclassed and it prevents other programmers from subclassing a secure class to invoke insecure methods. A final method can't be overridden. A final variable can't change from its initialized value. finalize() : finalize() method is used just before an object is destroyed and can be called just prior to garbage collection. finally : finally, a key word used in exception handling, creates a block of code that will be executed after a try/catch block has completed and before the code following the try/catch block. The finally block will execute whether or not an exception is thrown. For example, if a method opens a file upon exit, then you will not want the code that closes the file to be bypassed by the exception-handling mechanism. This finally keyword is designed to address this contingency.

What is the code to generate a random number between 0-9?

int math=(int)(Math.random() *10); System.out.print(math)

ad hoc polymorphism

overloading and coercion are two special kinds of ad-hoc polymorphism

access modifiers?

public: Any thing declared as public can be accessed from anywhere. private: Any thing declared as private can't be seen outside of its class. protected: Any thing declared as protected can be accessed by classes in the same package and subclasses in the other packages. default modifier : Can be accessed only to classes in the same package.

Statements

smallest executable unit in Java, each one ends in a semicolon.

If 1 of the operands of an || is false then the expression is _____?

true -- this is also known as the short-circuit OR operator


Set pelajaran terkait

Chapter 5-7 hw and iclicker questions

View Set

Xcel Chapter 3 Legal Concepts of the Insurance Contract

View Set