Object Oriented Programming - Course
Object Oriented Programming - Course
Introduction
2021
Java programming language
Java was developed by Sun Microsystems after a project started in 1991, led by
James Gosling. The project resulted in an object-oriented language, which the
Sun company called Java.
We can create in our programs each class and method that we need. However,
most developers use Java class collections in so-called predefined Java class
libraries known as Java APIs (Application Programming Interfaces)
Properties of Java
Step 1. Create the program. This step consist in editing one or more files
with a text editor. The file is stored on a storage device (hard disk) with the
extension .java.
Step 3. Loading the program in memory. At this stage, Java Virtual Machine
(JVM ) loads the program into memory to run. The class loader of the JVM takes
the .class files containing bytecode encoding the program and transfer them into
RAM . The class loader also loads all necessary .class files, provided by Java.
The .class files can be loaded from the local computer or a network (local or
Internet).
Java programs
(continuation)
Step 4. Checking the bytecode. At this stage, as the classes are loaded, the
bytecode verifier examines their bytecodes, to ensure they are valid and do not
violate Java 's security restrictions.
Java programs
(continuation)
In this phase, JVM executes the bytecodes of the program, such performing
the actions specified by the program.
In the initial versions of Java, JVM was a simple interpreter for bytecodes.
This made most Java programs to run slowly because JVM interpreted and
executed one bytecode at a time.
There is defined the class P01 which contains only the method main. The
file .java must have the same name with the public class, P01.java.
Each program consists of at least one class that must be defined. The
keyword class begins the class declaration and is immediately followed by the
class name (P01).
Keywords are reserved for use by Java and must be written in lowercase only.
Java programs
(continuation)
Normally, an identifier that does not start with a capital letter, is not a class
name.
The open bracket { marks the beginning of the class definition body . A
corresponding close brace } should close the class declaration.
The methods perform operations that can return information at the end of
these operations. The keyword void indicates that the method will not return
any information.
The call of the method specifies three arguments. When a method requires
several arguments, they are placed in the list with a comma as separator.