OOP in Java Slide
OOP in Java Slide
• Procedural/Structural Programming
– Conventional programming using high level languages such as COBOL,
Fortran, Pascal and C
– Problem is viewed as a sequence of things to be done such as Input—
Process---Output
– A number of functions are written to accomplish these tasks
– Data structures are designed such that they characterize the object
• Class
– Generalizes/ represents a collection of similar objects and is effectively a
template from which to create objects
– Definition of data and code for creating objects
– Once a class has been defined we can create any number of Objects belonging
to that class
Features of OOP
• Abstraction
– Process of Identifying the relevant qualities and behaviors an object
should possess
– Is a process that involves identifying the critical behavior of an object
and eliminating irrelevant and complex details.
• Encapsulation
– The wrapping up of data and functions in to a single unit called class.
– Data is not accessible to the outside world and only those functions
which are wrapped in the class can access it.
– This insulation of data from direct access by the program is called
Data/Information hiding.
Features of OOP
• Inheritance
– Is the process by which object of one class acquires the properties of an
other class.
– It supports the concept of hierarchical classification
• Polymorphism
– Ability to make more than one form
– The behavior depends upon the type of data and number of arguments
Features of Java
• Simple
– Java inherits the C/C++ syntax and many of the object-oriented features of C++,
most programmers have little trouble learning Java
– To write and more readable and eye catching
– In Java, there are a small number of clearly defined ways to accomplish a given task
• Secure
– Can’t harm Other system
– When you use a Java-compatible Web browser, you can safely download Java
applets without fear of viral infection or malicious intent.
– Java achieves this protection by confining a Java program to the Java execution
environment and not allowing it access to other parts of the computer
– Enables the construction of various free and tamper free system
Features of Java
• Portable
• Object Oriented
– The object model in Java is simple and easy to extend, while simple
• Multithreaded
– The Java run-time system comes with an elegant yet sophisticated solution
• Robust
– Knowing that what you have written will behave in a predictable way
Java is robust, consider two of the main reasons for program failure:
• Architecture neutral
– One of the main problems facing programmers is that no guarantee
exists that if you write a program today, it will run tomorrow—even
on the same machine. Operating system upgrades, processor
upgrades, and changes in core system resources can all combine to
make a program malfunction. The Java designers made several hard
decisions in the Java language and the Java Virtual Machine in an
attempt to alter this situation. Their goal was “write once; run
anywhere, any time, forever.”
Features of Java
• Dynamic
– Java programs carry with them substantial amounts of run-time type
information that is used to verify and resolve accesses to objects at
run time. This makes it possible to dynamically link code in a safe
and convenient manner.
– This is crucial to the robustness of the applet environment, in which
small fragments of byte code may be dynamically updated on a
running system
Architecture of JVM
Architecture of JVM
• Java is developed with the concept of WORA (Write Once
Run Anywhere).
3. Execution Engine
Interpreter, JIT, GC, JNI and Java Method Libraries
Basics in Java Programming
– Compile the source file into a byte code file using the compiler, javac
– Run the program contained in the byte code file using The Java interpreter
– The file name should be the same as the name of the class containing our main-
method
– A program can contain one or more class definitions but only one public class
definition. This class is called main-class because it contains the main method.
– If a file contains multiple classes, the file name must be the class name of the class
– System and String classes are directly used, because they are found in the
– public (access modifier) makes the item visible from outside the class. static
indicates that the main() method is a class method not an instant method. It
of the class.
Basics in Java Programming
• Java Tokens
– Tokens are meaningful words and symbols used by a programming language. They are the
smaller individual units inside a program the compiler recognizes when building up the
program.
– There are five types of Tokens in Java: Reserved keywords, Identifiers, Literals, operators,
separators. abstract Float public
• Reserved keywords boolean For return
Break If short
Byte Implements static
• These reserved words are Case Import super
words with special catch Instanceof switch
Char Int synchronized
meaning to the compiler.
class Interface this
• They could not be used as continue Long throw
– Constants: often written in all capital and use underscore if you are using more than
one word.
Basics in Java Programming
• Literals
– Operators are a symbol that take one or more arguments (operands) and operates
2. Logical operators
3. Relational operators
4. Assignment operators
5. Conditional operators
8. Special operators
Basics in Java Programming
• Separators
– Separators are symbols used to indicate where groups of codes are
divided and arranged. They define the shape and function of our code.
Some of them are: Parenthesis ( ), braces { }, brackets [ ], semicolon ;,
comma,, period .
• Java Comments
– Java allows putting our comments for making clarifications to our java
codes. The compiler skips comments during compiling. These comments
can be written using three ways.
Start End Purpose
/** */ The enclosed text is treated as a comment by the compiler but is used by JavaDoc
to automatically generate documentation.
Basics in Java Programming
• White space
– Java white spaces include: space, tab, newline.
• Java Statements
– Statements are roughly equivalent to sentences in natural languages. A
statement is terminated using a semi colon. It forms a complete unit of
execution. Java statements are categorized as follows
Java statements
Selection Iteration/loop
Jump statement
statement statement