Save
Busy. Please wait.
Log in with Clever
or

show password
Forgot Password?

Don't have an account?  Sign up 
Sign up using Clever
or

Username is available taken
show password


Make sure to remember your password. If you forget it there is no way for StudyStack to send you a reset link. You would need to create a new account.
Your email address is only used to allow you to reset your password. See our Privacy Policy and Terms of Service.


Already a StudyStack user? Log In

Reset Password
Enter the associated with your account, and we'll email you a link to reset your password.
focusNode
Didn't know it?
click below
 
Knew it?
click below
Don't Know
Remaining cards (0)
Know
0:00
Embed Code - If you would like this activity on your web page, copy the script below and paste it into your web page.

  Normal Size     Small Size show me how

Java 8 OCA 1

Java 8 OCA 1z0-808

QuestionAnswer
source code .java
bytecode .class
class components package; import; classes and interfaces comments annotations class declaration { variables constructors methods nested classes nested interfaces enum }
Unified Modeling Language class diagram represents the static view of an application. shows entities like packages, classes, interfaces, and their attributes (fields and methods)
declaration of a class is composed of the following parts ■ Access modifiers ■ Nonaccess modifiers ■ Class name ■ Name of the base class, if the class is extending another class ■ All implemented interfaces ■ Class body (class fields, methods, constructors), included within a pair of curly braces, {}
mandatory class declaration components Keyword class Access modifier, such as public Class body, marked by the opening and closing curly braces, {}
optional class declaration components Access modifier, such as public Nonaccess modifier, such as final Keyword extends together with the name of the base class Keyword implements together with the names of the interfaces being implemented
instance variable store state of an object
class / static variable shared by all the objects of a class
main rules ■ The method must be public ■ The method must be static ■ The name of the method must be main ■ The return type of this method must be void ■ The method must accept a method argument of a String array or a variable argument (varargs) of type String.
acceptable main declaration and array and vararg public static void main(String... args) public static void main(String[] arguments) public static void main(String minnieMouse[]) static public void main(String[] args)
java <class> arg1 arg2 command-line parameters/values class A { public static void main(String[] args) { Syso(args[0]); syso(args[1]); } }
import java.util.Date; import java.sql.Date; class AnnualExam { } compile error
use library import with same class names import java.util.Date; class AnnualExam { Date date1; java.sql.Date date2; }
static public int marks; public static void print() { System.out.println(100); } static members
import static certification.ExamQuestion.marks; class AnnualExam { AnnualExam() { marks = 20; } static imports access variable
Java access levels ■ public (least restrictive) ■ protected ■ default ■ private (most restrictive)
nonaccess modifiers ■ abstract ■ static ■ final ■ synchronized ■ native ■ strictfp ■ transient ■ volatile
synchronized method —A synchronized method can’t be accessed by multiple threads concurrently. You can’t mark classes, interfaces, or variables with this modifier
native method —A native method calls and makes use of libraries and methods implemented in other programming languages such as C or C++. You can’t mark classes, interfaces, or variables with this modifier.
transient variable isn’t serialized when the corresponding object is serialized. The transient modifier can’t be applied to classes, interfaces, or methods
volatile variable value can be safely modified by different threads. Classes, interfaces, and methods can’t use this modifier
strictfp —Classes, interfaces, and methods defined using this keyword ensure that calculations using floating-point numbers are identical on all platforms. This modifier can’t be used with variables
An abstract class may or may not define an abstract method. T
a concrete class can’t define an abstract method. T
An abstract class can contain concrete methods T
An interface is an abstract entity by default. T The Java compiler automatically adds the keyword abstract to the definition of an interface. Thus, adding the keyword abstract to the definition of an interface is redundant.
An abstract method doesn’t have a body T
A method with an empty body isn’t an abstract method T
ABSTRACT VARIABLES None of the different types of variables (instance, static, local, and method parameters) can be defined as abstract. T EXAM TIP Don’t be tricked by code that tries to apply the nonaccess modifier abstract to a variable. Such code won’t compile.
final modifier can be used with the declaration of a class, variable, or method. It can’t be used with the declaration of an interface
FINAL CLASS A class that’s marked final can’t be extended by another class
FINAL INTERFACE An interface can’t be marked as final. An interface is abstract by default and marking it with final will prevent your interface from compiling:
FINAL VARIABLE A final variable can’t be reassigned a value. It can be assigned a value only once. final long MAX_AGE; MAX_AGE = 99; final StringBuilder name = new StringBuilder("Sh"); name.append("reya"); name = new StringBuilder(); <-- COMPILE ERROR
A final method a base class can’t be overridden by a derived class
static modifier The nonaccess modifier static can be applied to the declarations of variables, methods, classes, and interfaces.
static variables 1 of 3 static variables belong to a class. They’re common to all instances of a class and aren’t unique to any instance of a class.
static variables 2 of 3 static attributes exist independently of any instances of a class and may be accessed even when no instances of the class have been created.
static variables 3 of 3 You can compare a static variable with a shared variable. A static variable is shared by all the objects of a class.
static int bankVault; Emp emp1 = new Emp(); Emp emp2 = new Emp(); emp1.bankVault = 10; emp2.bankVault = 20; System.out.println(emp1.bankVault); System.out.println(emp2.bankVault); System.out.println(Emp.bankVault); System.out.println(emp1.bankVault); <=20 System.out.println(emp2.bankVault); <=20 System.out.println(Emp.bankVault); <=20
you can use an object reference variable to access static members T it’s not advisable to do so. Because static members belong to a class and not to individual objects, using object reference variables to access static members may make them appear to belong to an object.
What is the preferred way to access static variables? The preferred way to access them is by using the class name. The static and final nonaccess modifiers can be used together to define constants (variables whose value can’t change).
you can define a constant as a non-static member T class Emp { public static final int MIN_AGE = 20; static final int MAX_AGE = 70; } it’s common practice to define constants as static members, because doing so allows the constant values to be used across objects and classes.
static methods aren’t associated with objects and can’t use any of the instance variables of a class. You can define static methods to access or manipulate static variable
utility methods which are methods that usually manipulate the method parameters to compute and return an appropriate value: static double interest(double num1, double num2, double num3) { return(num1+num2+num3)/3; }
The following utility (static) method doesn’t define input parameters. The method averageOfFirst100Integers computes and returns the average of numbers 1 to 100: static double averageOfFirst100Integers() { int sum = 0; for (int i=1; i <= 100; ++i) { sum += i; } return (sum)/100; }
You can’t override the static members in a derived class, but you can redefine them. T The nonprivate static variables and methods are inherited by derived classes. The static members aren’t involved in runtime polymorphism.
Neither static methods nor static variables can access the non-static variables and methods of a class. T
non-static variables and methods can access static variables and methods T the static members of a class exist even if no instances of the class exist. static members are forbidden from accessing instance methods and variables, which can exist only if an instance of the class is created.
class MyClass { static int x = result(); static int result() { return 20; } int nonStaticResult() { return result(); } } T
Because static variables and methods belong to a class and not to an instance, you can access them using variables, which are initialized to null. T Watch out for such questions in the exam. Such code won’t throw a runtime exception (NullPointerException to be precise).
class Emp { String name; static int bankVault; static int getBankVaultValue() { return bankVault; } Emp emp = null; System.out.println(emp.bankVault); System.out.println(emp.getBankVaultValue()); T
You can access static variables and methods using a null reference. T
static classes and interfaces are types of nested classes and interfaces T
You can’t prefix the definition of a top-level class or an interface with the keyword static. T
class Person { static class Address {} static interface MyInterface {} } T you can define a class and an interface as a static member of another class. Also known as static nested class
features and components of Java PLATFORM INDEPENDENCE OBJECT ORIENTATION ABSTRACTION ENCAPSULATION INHERITANCE POLYMORPHISM TYPE SAFETY AUTOMATIC MEMORY MANAGEMENT MULTITHREADING AND CONCURRENCY SECURITY
Packages are used to group together related classes and interfaces. They also provide access protection and namespace management.
The absence of an access modifier is equal to assigning the class or its members with default access.
class-level variables All the objects of a class share the same copy of static variables
A comment can appear before or after a package statement, before or after the class definition, and before, within, or after a method definition.
components of a Java class Class declarations and class definitions
A class may define an instance variable before or after the definition of a method and still use it.
A Java source code file (.java file) can define multiple classes and interfaces.
A public class can be defined only in a source code file with the same name
package and import statements apply to all the classes and interfaces defined in the same source code file (.java file).
You can import an individual static member of a class or all its static members by using a static import statement.
The members of a class defined using the protected access modifier are accessible to classes and interfaces defined in the same package and to all derived classes, even if they’re defined in separate packages.
default accessibility The members of a class defined without using an explicit access modifier are defined with package accessibility
A class defined using default access can’t be accessed outside its package.
When a non-abstract class extends a class with an abstract method, it must implement the method.
A variable can’t be defined as an abstract variable. T
The static modifier can be applied to inner classes, inner interfaces, variables, and methods
A method can’t be defined as both abstract and static. T
static attributes are also known as class fields or class methods
A static variable or method can be accessed using the name of a reference object variable or the name of a class.
Java isn’t a single-threaded language. T
a primitive variable. A variable defined as one of the primitive data types
primitive data types primitive numeric boolean (true/false) unsigned signed char floating-point integer float double byte short int long
variable components name literal
literal fixed value that doesn’t need further calculations in order for it to be assigned to any variable
char values 0-65_535, \u0000 - \uffff
char c3 = -122; F fails to compile can cast char c3 = (char)-122;
Identifier can use a currency sign (at any position): ¤, $, £, ¢, ¥, and others
Identifier can use an underscore (at any position)
Identifier can starts with a letter ( a–z, upper- or lowercase), a currency sign, or an underscore
Java keywords 1 of 2 abstract default goto package this assert do if private throw boolean double implements protected throws break else import public transient byte enum instanceof return true
Java keywords 2 of 2 case extends int short try catch false interface static void char final long strictfp volatile class finally native super while const float new switch continue for null synchronized
Reference variables are also known as object reference variables or object references.
The literal value for all types of object reference variables is null.
The basic difference primitive variables and reference variables is that primitive variables store the actual values, whereas reference variables store the addresses of the objects they refer to
What is the one literal value for all types of reference variables null
Primitive values are not marked for garbage collection T
Created by: wahoo99
Popular Computers sets

 

 



Voices

Use these flashcards to help memorize information. Look at the large card and try to recall what is on the other side. Then click the card to flip it. If you knew the answer, click the green Know box. Otherwise, click the red Don't know box.

When you've placed seven or more cards in the Don't know box, click "retry" to try those cards again.

If you've accidentally put the card in the wrong box, just click on the card to take it out of the box.

You can also use your keyboard to move the cards as follows:

If you are logged in to your account, this website will remember which cards you know and don't know so that they are in the same box the next time you log in.

When you need a break, try one of the other activities listed below the flashcards like Matching, Snowman, or Hungry Bug. Although it may feel like you're playing a game, your brain is still making more connections with the information to help you out.

To see how well you know the information, try the Quiz or Test activity.

Pass complete!
"Know" box contains:
Time elapsed:
Retries:
restart all cards