Professional Documents
Culture Documents
Java Basics:
Compilation process:
Compilation verifies the syntax of the programming languages. Converts
the instruction into machine understandable format.
1
Java basics
3. Robust language:
Two main problems that cause program failures are memory management
mistakes and mishandled runtime errors. Java handles both of them
efficiently.
1) Memory management mistakes can be overcome by garbage collection.
Garbage collection is automatic de-allocation of objects which are no
longer needed.
1. Encapsulation
2. Inheritance
3. Polymorphism
4. Abstraction
2
Java basics
Encapsulation:
Inheritance:
Inheritance is the process by which one object acquires the properties of
another object.
Inheritance allows a class to use the properties and methods of another
class. In other words, the derived class inherits the states and behaviors
from the base class. The derived class is also called subclass and the base
class is also known as super-class. The derived class can add its own
additional variables and methods. These additional variable and methods
differentiates the derived class from the base class.
Polymorphism:
3
Java basics
Abstraction:
Note: 1) Abstract class can also have regular (or concrete) methods along
with abstract methods.
2) Abstract methods do not have body, they just have prototype (method
signature).
3) Abstract methods must be implemented in the child class (if the class is
not abstract) otherwise program will throw compilation error
Variable:
Argument variables These are the variables that are defined in the header
oaf constructor or a method. The scope of these variables is the method or
constructor in which they are defined. The lifetime is limited to the time for which
the method keeps executing. Once the method finishes execution, these
variables are destroyed.
Local Variables Similar to how an object stores its state in fields, a method
will often store its temporary state in local variables. The syntax for declaring a
local variable is similar to declaring a field (for example, int count = 0;). There is
no special keyword designating a variable as local; that determination comes
entirely from the location in which the variable is declared which is between
the opening and closing braces of a method. As such, local variables are only
visible to the methods in which they are declared; they are not accessible from
the rest of the class.
4
Java basics
Data Types:
5
Java basics
Access Specifiers:
Access specifiers are used to control the visibility of members like classes, variables and
methods. There are three access specifiers: public, private and protected. Protected
access specifier comes into picture when inheritance is implemented.
Following table shows what access specifiers may be assigned to different elements.
Note that all four levels may be applied to all elements except classes. Classes may be
declared with only public and private access specifiers
6
Java basics
The following table summarises the above said points regarding the accessibility of
entities.