[03] Java Foundations 1Z0-811 - Basic Java Elements

- 6 mins

This is the third installment of my Java Foundations Exam series. In this post, I delve into essential concepts like Java conventions, identifiers and reserved words, package creation and importation, the structure of a Java class, advanced compilation and execution, as well as the crucial java.lang package and other standard Java packages.

Conventions in Java

As programmers, adhering to conventions is vital for code readability. Java, being a community-driven language, follows specific conventions:

Cases

Naming

Java Identifiers and Reserved Words

Understanding identifiers and reserved words is crucial in Java programming:

Keyword Keyword Keyword Keyword Keyword
abstract assert boolean break byte
case catch char class const
continue default do double else
enum extends final finally float
for goto if implements import
instanceof int interface long native
new null package private protected
public return short static strictfp
super switch synchronized this throw
throws transient try void volatile
while        

Create and Import Packages

Creating and importing packages are fundamental to organizing and reusing code:

Import statements are optional; you can use Fully Qualified Class Names (FQCN) directly in the code.

Structure of a Java Class

Understanding the structure of a Java class is pivotal:

Within a class, you can have various members such as fields, methods, constructors, and initializers.

Advanced Compilation and Execution

Compiling and executing Java programs involve understanding dependencies and package structures:

Compilation Error vs. Exception at Runtime

Differentiating compilation errors and runtime exceptions is essential:

Exploring the java.lang package and other standard packages is crucial:

Package Name Purpose Important Classes
java.lang Provides classes that are critical for the functioning of any Java program. Object, Math, System, Runtime, wrapper classes
java.io Provides classes for performing input and output (I/O) activities involving files and other I/O devices. InputStream, OutputStream, FileReader, FileWriter
java.net Provides classes for performing network communication. Socket, ServerSocket
java.sql Provides classes for dealing with Databases. Connection, Statement, ResultSet
java.util Provides tools and utility classes for creating commonly used data structures, internationalization, date handling. Collection, List, ArrayList, HashSet, HashMap, Date, Locale
java.awt and java.swing Provides classes for building Graphical User Interfaces (GUI). Frame, Dialog, Button, ActionEvent, LayoutManager

The java.lang.Object class

PRIMITIVE WRAPPER
boolean Boolean
byte Byte
char Character
short Short
int Integer
long Long
float Float
double Double

Example:

int i= 10; //10 is a primitive value and int is a primitive type

Integer iW = 10; //assigning a primitive value 10 to a reference variable iW

iW = i; //assigning a primitive variable to reference variable

i = iW;//assigning a reference variable to a primitive variable

The java.lang.System class

The java.lang.Math class

The java.lang.Random class

Lais Ziegler

Lais Ziegler

Dev in training... 👋