Java Certification I

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

char

1) Single, 16-bit Unicode character 2) Stored as tnsigned integer but can force, e.g., char c3 = (char)-122 3) Values: \u0000 (or 0) to \uffff (or 65,535) 4) Use single quotes: 'D'; double quotes for String not char 5) 122 is base 10 - z; \u0122 is base 16 (0-9; a-f) 6) Because stored as integer can be used in arithmetic expressions p. 78, 105

short data type

1) Size: 16 bits 2) Values: -32,768 to 32,767 p. 73

int data type

1) Size: 32 bits 2) Values: -2,147,483,648 to 2,147,483,647 3) Default type of a non-decimal number p. 73

Double data type

1) Size: 64 bits 2) Default decimal literal 3) d or D but not necessary because default for a decimal number 4) Cannot use to store integer p. 76

long data type

1) Size: 64 bits 2) Values: -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807 3) Add L or l to designate an integer literal value as a long value p. 73, 74

byte data type

1) Size: 8 bits 2) Values: -128 to 127 p. 73

Primitive data type

1) There are 8 primitive data types. 2) Primitive data types: char, byte, short, int, long, float, double, Boolean. p. 70

Import static

1) To import a static class member or all static members 2) Access all public static members: import static cerfification.ExamQuestion.* p. 36

Top level class

Defined using only default or Public access modifiers; isn't defined within another class; not a nested class p.37

Integer literal value types

The number systems are: binary, octal, decimal, hexadecimal p. 74

Keywords/ reserved words

abstract, assert, boolean, break, byte, case, catch, char, class, const, continue, default, do, double, else, enum, extends, false, final, finally, float, for, goto, if, implements, import, instanceof... p. 81

Non-access modifiers

abstract, static, final, synchronized, native, strictfp, transient, volatile p. 47

Object reference variable

Like a handle to an object that allows you to access its attributes p. 83

Reference variable

See object reference variable. p. 82

Class variable

Shared by all objects of the class. Same as static variable. p. 21

Comment Types

Single line and multi-line p. 17

Primitive variable

Variable defined as one of the primitive data types. p. 70

Assignment operator +=

1) First add and then assign 2) a += b means a = a + b p.87

Assignment operator /=

1) First divide and then assign 2) a /= b means a = a / b p. 87

Assignment operator *=

1) First multiple and then assign 2) a *= b means a = a * b p. 87

Assignment operator -=

1) First subtract and then assign 2) a -= b means a = a - b p. 87

Default package

1) If a class does not start with the name of a package it is part of the unnamed "Default package". 2) Automatically imported in classes and interfaces in the same directory 3) A class from a default package can't be used in a named package class whether in same directory or not p. 16, 36

Static variables and methods

1) If non-private, they are inherited by derived classes. 2) Cannot override static members in a derived class but can redefine them p. 52

Compile Failures - Import statement

1) Import statement appears before package statement. p.17

Abstract interface

1) Interface is abstract by default 2) Interface cannot be instantiated 3) No need to add "abstract" keyword to interface definition p. 49

Main method

1) It is a method that must accept an argument of a String array or a variable argument of type String 2) public static void main (String args []) 3) public status void main(String... args) p. 25, 26

Executable class

1) Jvm starts execution at Main method 2) ex. Database connection, gui display p. 25

Public access modifier

1) Least restrictive access modifier. 2) Access across all packages, including derived and unrelated classes p. 39

Float data type

1) Less space and smaller range of numbers than double; less precision 2) Size: 32 bits 3) f or F; use to distinguish from the default double for decimal numbers 4) Cannot use to store integer p. 76

Package/default access modifier

1) Members of class defined without using any explicit access modifier 2) These members are only accessible to classes and interfaces in the same package. p. 42-45

Private access modifier

1) Most restrictive 2) Members of private class are accessible only to classes and interfaces in which they are defined p. 45

Identifier

1) Names of packages, classes, interfaces, methods, variables. 2) Allowed: underscore (any position); unlimited length; a-z upper and lowercase; currency sign (any position); digit (not starting position) 3) Not allowed: hyphen; java reserved word; java keyword; digit in starting position; special characters except underscore p. 80

Floating point literal underscore

1) No underscore before D, d, F, f 2) No underscore adjacent to decimal point p. 77

Abstract modifier

1) Non-access modifier 2) Can use with classes, interfaces, methods 3) Cannot use with variables p. 48

Final modifier

1) Non-access modifier 2) Can use with classes, variables, methods 3) Cannot use with interfaces because interface is abstract by default p. 49

Static modifier

1) Non-access modifier 2) Can use with classes, variables, methods, interfaces p. 50

synchronized [method]

1) Non-access modifier 2) Cannot be accessed by multiple threads concurrently 3) To protect data integrity 4) Cannot use with classes, interfaces, variables p. 48

strictfp [class, interface, method]

1) Non-access modifier 2) Ensure calculations using floating-point number are identical across platforms 3) Can use with classes, interfaces, methods 4) Cannot use with variables p. 48

transient [variable]

1) Non-access modifier 2) Is not serialized when corresponding object is serialized 3) Cannot use with classes, interfaces, methods p. 48

native [method]

1) Non-access modifier 2) Uses libraries and methods implemented in other program languages, e.g., C++ 3) Cannot use with classes, interfaces, variables p. 48

volatile [variable]

1) Non-access modifier 2) Value can be safely modified by different threads 3) Cannot use with classes, interfaces, methods p. 48

Compile Failures - Package statement

1) Package statement at end of class definition; 2) package statement within class definition; 3) multiple package statements for class p. 16

Primitive variable vs. object reference variable

1) Primitive variables store actual values 2) Reference variables store addresses of objects they refer to 3) Use == operator to compare reference variables and primitive variable values 4) To compare objects use equals() method 5) Methods can change state or assign new object to reference variables; when assigning a new object, changes are not reflected back in the calling method 6) Reference variables have only null as literal value 7) Primitive literal values: boolean = false; integer=0; decimal=0.0; char = /u0000 (0) 8) Object referred to by reference variable is reclaimed by garbage collector when reference variable doesn't refer to it any more while primitives not marked for garbage collection 9) Reference variable doesn't work with all operators like arithmetic operators but primitives work with arithmetic, assignment, logical and relational operators p. 84

Static variable

1) Shared by all objects/instances of the class. 2) Same as class variable or a shared variable. 3) Exist and can be accessed when no instances of the class have been created 4) Can be accessed using the name or the reference variable or the name of the class, ex: emp1.bankVault or Emp.bankVault 5) Cannot access non-static/instance variables and methods 8) Can be accessed by non-static/instance variables and methods p. 21, 51, 52

Variable types

1) 2 types: primitive variables and reference variables 2) An object not referred to by a reference variable is liable to be garbage collected (removed from memory by the JVM) 3) Several objects can be referenced by multiple object reference variables p. 82

Class

1) A design to specify properties and behavior of an object. 2) Design from which an object can be created. Like: Design/specification (class definition) for a mobile phone (object); or a mold for objects p. 20

Final method

1) A final method in a base class cannot be overridden by a derived class p. 50

Object reference

1) A memory address that points to a memory area where an object's data is stored. 2) When an object is instantiated with the "new" operator, a heap-memory address value to the object is returned and the address is usually assigned to the reference variable. p. 82

Class declaration - components

1) Access modifiers - optional 2) Non-access modifiers - optional 3) "class" keyword - compulsory 4) Name of Class - compulsory 5) "extends" keyword - optional 6) Name of base class - if class extends another class (one) - optional 7) "implements" keyword - optional 8) Name of Implemented interfaces (one or more) - if class implements interfaces (one or more) - optional 9) {} - compulsory 10) Class body within {} - optional a. Fields b. Methods c. Constructors Example: public final class Runner extends Person implements Athlete {} p. 19-20

Protected access modifier

1) Accessible to a) classes/interfaces in same package; b) derived classes in separate packages 2) A derived class can inherit and access protected members of its base class regardless of the package in which it's defined; but a derived class in a separate package can't access protected members of its base class using reference variables, e.g., Book book=new Book() p. 40

Arithmetic operators

1) Add, subtract, multiply, divide and modulus primitives 2) +, -, *, /, %, ++, -- p. 87

Unicode character/value

1) All existing scripts and languages 2) Base 16; u for Unicode, e.g., \u0122 3) Use single quotes, e.g. char c2 = '\u0122' p. 79

Abstract method

1) An abstract method doesn't have a body; this means no {} after the method even if {} is empty 2) An abstract method is typically implemented by a derived class p. 49

Logical operators

1) Apply NOT, AND, or OR logic to primitives 2) |, &&, || 3) Return boolean value p. 87

Assignment operators

1) Assign value to a variable 2) =, +=, -=, *=, /= p. 87

Decimal numbering system

1) Base-10 system 2) Only uses digits 0-9 (10 digits) p. 74

Hexadecimal numbering system

1) Base-16 system 2) 16 digits and letters 3) Uses digits 0-9 4) Uses letters A-F 5) 10 = A; 11=B; 12=C; 13=D; 14=E; 15=F 6) Remember to write the remainder in hex 7) Literal prefix: 0x or 0X p. 74

Binary numbering system

1) Base-2 system 2) Uses digits 0 and 1 (2 digits) 3) Literal prefix: 0b or 0B p. 74

Octal numbering system

1) Base-8 system 2) Uses digits 0-7 (8 digits) 3) Decimal 8 = Octal 10 4) Decimal 9 = Octal 11; 10=12, 11=13; 12=14; 13=15; 14=16; 15=17; 16=20 5) Keep dividing by 8 and record the remainder in reverse order 6) int intValue = 034; // 28 in decimal int six = 06; // Equal to decimal 6 int seven = 07; // Equal to decimal 7 int eight = 010; // Equal to decimal 8 int nine = 011; // Equal to decimal 9 7) Literal prefix: 0 p. 74

Final variable

1) Can be assigned a value only once. 2) Cannot re-assign a new value, e.g., name = new StringBuilder() 3) Can call a method on it. p. 50

Class definition

1) Can only use Public or Default access modifiers for top level class p. 37

Literal decimal value

1) Can use scientific notation, e.g., 1.201762e2 p. 77

Static method

1) Can use to manipulate static variables. 2) Can use to define utility methods that may manipulate parameters to compute and return a value but does not always manipulate parameters 3) Same as class method. 4) Not associated with an object 5) Cannot use instance variable of a class 6) Can be accessed with name of the object reference variable and or name of the class but proper to use the name of the class and not the object reference variable name 7) Cannot access non-static/instance variables and methods 8) Can be accessed by non-static/instance variables and methods p. 21, 52

Literal numeric value underscore

1) Can't come before L or l in long 2) Can't start or end the string 3) Can't come after 0b, 0B, 0x or 0X 4) Can't use in position where string of digits expected, e.g., int i = Integer.parseInt("45_98") 5) Can use after 0 for octal value p. 75

Final class

1) Cannot be extended by another class p. 50

Abstract class

1) Class that cannot be instantiated 2) Modifier makes abstract class 3) Abstract class but need not have abstract method but concrete class cannot have abstract method p. 48-49

Relational operators

1) Compare primitives 2) <, <=, >, >=, ==, != 3) Used to determine whether a primitive value is equal to, less than or greater than another value 4) The result is always true or false 5) Can't compare incomparable values p. 87, 92, 93

Access modifier

1) Control accessibility of class/interface and its members (methods and variables) 2) Can apply to class, interface and their members - instance and class variables and methods 3) Cannot apply to local variables 4) Cannot apply to method parameters 5) 4 access modifiers: public, protected, default, private p. 37-38

Import statement

1) Use a class or interface in another package without the fully qualified name, p.16 2) Follows package statement and precedes class declaration 3) applies to all classes/interfaces in source file 4) cant use to access classes/interfaces of same name from different packages, e.g., java.util.Date and java.sql.Date. 5) can import single class/interface or all. 6) use asterisk to import all public members, classes, interfaces 7) asterisk doesn't recursively import classes from subpackage package university; import certification.ExamQuestion; class AnnualExam { ExamQuestion eq; } p. 34-36

Constants

1) Use final and static to define variables whose values cannot change 2) Defining them as static allows them to be used across classes and objects p. 52

Assignment operator =

1) Used to initialize variables with values 2) Used to reassign new values to variables p. 87

Class definition components

A class definition can include: 1) attributes or instance variables; 2) methods (with optional arguments; 3) constructors; 4) comments p. 20

Default access

Access when class, interface, method or variable is defined without an explicit access modifier. p. 38

Package

All java classes are part of a package. 1) It must be the first statement in a class. 2) Classes and interfaces in the same package can use each other without prefixing their names with the package name. 3) To use a class or interface from another package must use a full, qualified name (unless imported). 4) Should be the first line of a class file unless preceded by a Comment 4) applies to all classes/interfaces in class file 5) lower case names 6) separated from subs by dot 7) one package statement per java source file 8) only comment can precede p. 16, 23, 31

Comment - Multi-line

Begin: /* End: */ Notice asterisk in the middle and forward slash on outsides p. 17

Comment Location

Can appear anywhere in code, including: 1) before package statement; 2) after package statement; 3) before class definition; 4) after class definition; 5) before method definition; 6) after method definition; 7) within method definition p. 17

Boolean variable

Can only have literal values of true or false. p. 72

Class state

Class state (instance/data for object) is defined using attributes or instance variables p. 20

Constructor

Create and initialize objects of a class p. 21 A class can have multiple constructors with different method parameters

Literal

Fixed value that doesn't need further calculations in order to be assigned to a variable. p. 72

Casting

Forceful conversion of one data type to another data type. p. 79

Interface

Group of related methods and constants but no implementation; contract for class to implement p. 21

Overridden method

Has same signature as base class method. p. 50

Class methods

Implement behavior of an object. Include optional argument list. p. 20

Class variables

Implement properties of an object p. 20

Class members

Instance and class methods and variables of the class p. 38

Object

Instance of a class, predefined or user-defined. p. 82

Class declaration - simple

Most simple is keyword "class" followed by class name. p. 19

Java application

Multiple source code files; one contains executable class p. 25

Public class

Name must match source file name. One public interface/class per source file. p. 23

Public interface

Name must match source file name. One public interface/class per source file. p. 23

Literal value of object reference value

Null by default, but can also explicitly assign null, e.g. Person person = null p. 83

Compile errors - Public interface/class

Only public interface/class per source file p. 23

Comment - End-of-line

Start with // p. 18

Subpackages

Use for GUIs, database access, networking, etc. p. 29

Instance method

Used to manipulate instance variables. p. 21

Class method

Used to manipulate static variables. Same as static method. p. 21

Instance variables

Used to store object state; same as instance attributes. Defined in the class but are outside of the class methods. Each object has its own copy - not shared. p. 20

Instance attributes

Used to store object state; same as instance variables. Defined in the class but are outside of the class methods. Each object has its own copy - not shared p. 20


Set pelajaran terkait

Nevada Statutes and Codes Common to All Lines

View Set

Independent/dependent variable and control group

View Set

Managerial Finance Exam 3 - Kyle Wells

View Set

455 Ch 13 Motivating for Performance

View Set

Digital Marketing Content After Midterm

View Set

Unidad 3, Lección 3: Una lección de geografía

View Set