1.7. Summary

This chapter started with a look at the structure of a Java class. Although you should know how to work with Java classes, Java source code files (.java files), and Java bytecode files (.class files), the OCA Java SE 8 Programmer I exam will question you only on the structure and components of the first two—classes and source code—not on Java bytecode.

We discussed the components of a Java class and of Java source code files. A class can define multiple components, namely, import and package statements, variables, constructors, methods, comments, nested classes, nested interfaces, annotations, and enums. A Java source code file (.java) can define multiple classes and interfaces.

We then covered the differences and similarities between executable and non-executable Java classes. An executable Java class defines the entry point (main method) for the JVM to start its execution. The main method should be defined with the required method signature; otherwise, the class will fail to be categorized as an executable Java class.

Packages are used to group together related classes and interfaces. They also provide access protection and namespace management. The import statement is used to import classes and interfaces from other packages. In the absence of an import statement, classes and interfaces should be referred to by their fully qualified names (complete package name plus class or interface name).

Access modifiers control the access of classes and their members within a package and across packages. Java defines four access modifiers: public, protected, default, and private. When default access is assigned to a class or its member, no access modifier is prefixed to it. The absence of an access modifier is equal to assigning the class or its members with default access. The least restrictive access modifier is public, and private is the most restrictive. protected access sits between public and default access, allowing access to derived classes outside a package.

We covered the abstract and static nonaccess modifiers. A class or a method can be defined as an abstract member. abstract classes can’t be instantiated. Methods and variables can be defined as static members. All the objects of a class share the same copy of static variables, which are also known as class-level variables.

Finally, we covered the features and components of Java that make it a popular choice.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.145.179.35