OOP1
OOP1
Senior-lecturer
[email protected]
Astana IT University
▪ Java is an object-oriented programming language
▪ Everything is implemented using classes and objects, which include
attributes and methods
▪ Object has its state and behavior
▪ A class is a blueprint from which individual objects are created.
▪ It represents the set of common properties and methods for all
objects of the same type
▪ An object is an instance of class
▪ Java programs are running on JVM, which has its own GC
▪ JetBrains IDEA Ultimate (recommended) – you can get free student license by
filling this application https://www.jetbrains.com/shop/eform/students
▪ NetBeans 11.3
▪ Eclipse IDE
▪ Java basics (Data types, variables, conditions, loops, arrays)
▪ Classes and Objects
▪ Methods and Fields
▪ Constructors
▪ Getter and Setter
The Java programming
language is statically-
There are only 2 types of variables: typed, which means that
all variables must first be
▪ Primitive types (8): declared before they can
▪ byte, short, int, long, float, double, boolean, char be used.
▪ Reference types:
▪ All other non-primitive compound types (i.e. int[], Integer, String, Double, etc.)
▪ Variable is an arbitrary name that is used to store values.
▪ Each variable must have definite type.
▪ Variable names can consist of letters, digits and underscore(_) symbols,
nevertheless, digits cannot be used as first symbol.
▪ Reserved words of java cannot be used as variable names
▪ A value of any variable can be changed in a runtime, unless constant variable.
There are 3 types of condition statements:
▪ if (condition) { some instructions }
▪ switch (expression) {
case value1: some instructions; break;
case value2: another instructions; break;
default: default instructions;
}
There are four repetition statements in java:
▪ while ( condition ) statement;
▪ do { // do-while structure executes a statement at least one time
statement;
} while( condition );
▪ for ( init-statement ; condition ; increment )
statement;
▪ for ( value-variable : iterable-type ) // enhanced for (the same as “foreach”)
statement;
▪ One-dimensional arrays
▪ Multi-dimensional arrays
▪ Classes are structures to create your own compound data types.
▪ They consist of three parts:
▪ Constructors
▪ Methods
▪ Fields
▪ With help of classes you can create structures of any complexity, that can be used
to simplify the logic of solution.
▪ Method structure:
▪ Methods and fields can be:
▪ non-static – belongs to object of class
▪ static – belongs to class itself
▪ Non-static fields and methods defined in a class can be used only when an object
of that class type has been created
▪ Static fields and methods can be used directly using a class type
▪ main() method must always be static, since it is an entry point for all java
applications. It does not need any object creation in order to be called.
▪ Constructor is similar to a method but it is called implicitly by the new operator to
initialize an object’s instance variables when the object is created
▪ Compiler identifies that the given method is a constructor by its name and return
type: the constructor has the same name as the class and it does not have any
return type
▪ A class can have more than one constructor with different signature
▪ If a constructor was not implemented, a Java compiler inserts a default constructor
which has no arguments and empty body
▪ The reason to use private for any field is to disallow a direct access to an attribute
▪ Getters and setters are public methods which are used if there is a need to provide
an indirect access to private fields.
▪ In order to define package name in your class you need to write following line at
the beginning of its file:
▪ Each dot(.) separated value will create corresponding folder in your file system,
and classes will be stored inside them.
Java: How to Program (Early Objects), 11th Edition, by Paul Deitel and Harvey Deitel,
Pearson
▪ Chapter 2.1 - 2.8
▪ Chapter 3.1 - 3.5