Docsity

OCA Java SE 8 Programmer Certification Exam Study Guide Class Structure, Package Rules, an, Exams of Information Technology

Toggle sidebar
bg1
OCA Java SE 8 Programmer Certification Exam Study
Guide Class Structure, Package Rules, and Access Modifiers
Review
Package statement
Import statements
Comments
Class declaration {
Variables
Comments
Constructors
Methods
Nested classes
Nested interfaces
Enum
} - Structure of a Java class
public final class Runner extends Person implements Athlete {} - Components of a
class declaration using an example
- Per Java naming conventions, package names should all be in lowercase.
- The package and subpackage names are separated using a dot (.).
- Package names follow the rules defined for valid identifiers in Java.
pf3
pf4
pf5
pf8
pf9
pfa

Partial preview of the text

Download OCA Java SE 8 Programmer Certification Exam Study Guide Class Structure, Package Rules, an and more Exams Information Technology in PDF only on Docsity!

Guide Class Structure, Package Rules, and Access Modifiers

Review

Package statement Import statements Comments Class declaration { Variables Comments Constructors Methods Nested classes Nested interfaces Enum } - Structure of a Java class public final class Runner extends Person implements Athlete {} - Components of a class declaration using an example

  • Per Java naming conventions, package names should all be in lowercase.
  • The package and subpackage names are separated using a dot (.).
  • Package names follow the rules defined for valid identifiers in Java.

Guide Class Structure, Package Rules, and Access Modifiers

Review

  • For classes and interfaces defined in a package, the package statement is the first statement in a Java source file (a .java file). The exception is that comments can appear before or after a package statement.
  • There can be a maximum of one package statement per Java source code file (.java file).
  • All the classes and interfaces defined in a Java source code file are defined in the same package. They can't be defined in separate packages. - RULES TO REMEMBER Here are a few of important rules about packages Public Protected Default Private - Access modifiers
  • Derived/Same pkg
  • Derived/Separate pkg
  • Unrelated/Same pkg
  • Unrelated/Separate pkg - Public access modifiers

Guide Class Structure, Package Rules, and Access Modifiers

Review

final synchronized native strictfp transient volatile - Nonaccess modifiers A synchronized method can't be accessed by multiple threads concurrently. You can't mark classes, interfaces, or variables with this modifier - Synchronized nonaccess modifier 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 - Native nonaccess modifier A transient variable isn't serialized when the corresponding object is serialized. The transient modifier can't be applied to classes, interfaces, or methods - Transient nonaccess modifier A volatile variable's value can be safely modified by different threads. Classes, interfaces, and methods can't use this modifier. - Volatile nonaccess modifier

Guide Class Structure, Package Rules, and Access Modifiers

Review

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. - Strictfp nonaccess modifier 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 attributes exist independently of any instances of a class and may be accessed even when no instances of the class have been created. You can compare a static variable with a shared variable. A static variable is shared by all the objects of a class - Static variables Static methods aren't associated with objects and can't use any of the instance variables of a class. It's a common practice to use static methods to define 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; }

Guide Class Structure, Package Rules, and Access Modifiers

Review

Java lets you abstract objects and include only the required properties and behavior in your code. - Abstraction Java enables its classes to inherit other classes and implement interfaces. The interfaces can inherit other interfaces - Inheritance Java enables instances of its classes to exhibit multiple behaviors for the same method calls - Polymorphism Java emulates real-life object definition and behavior. It uses classes, interfaces, or enums to define all its code - Object orientation The state or the fields of a class are protected from unwanted access and manipulation - Encapsulation In Java, you must declare a variable with its data type before you can use it - Type safety

Guide Class Structure, Package Rules, and Access Modifiers

Review

Java uses garbage collectors for automatic memory management. They reclaim memory from objects that are no longer in use. - Automatic memory management Java defines classes and interfaces to enable developers to develop multithreaded code - Multithreading andconcurrency A variable defined as one of the primitive data types is a primitive variable - Primitive variable char byte short int long float double boolean - Java defines the following eight primitive data types int baseDecimal = 267;

Guide Class Structure, Package Rules, and Access Modifiers

Review

IndexOutOfBoundsException ClassCastException IllegalArgumentException ArithmeticException NullPointerException NumberFormatException - Runtime exceptions ExceptionInInitializerError StackOverflowError NoClassDefFoundError OutOfMemoryError - Errors