• Object Oriented Programming: The major objective of object oriented approach is to enhance some of the flaws encountered in the procedural approach. OOP treats data as a critical element in the program and does not allow it to flow freely around the system. It ties data more closely to the functions that operate on it and protect it from unintentional modification by other functions. OOP allows us to decompose a problem into a number of entities called objects and then build data and functions around these entities. The combination of data and methods make up an object.

Some features of Object oriented paradigm are:

  1. Emphasis is on data rather than procedure.
  2. Programs are divided into what are known as objects.
  3. Data is hidden and cannot be accessed by external functions
  4. Objects may communicate with each other through methods
  5. New data and functions can be easily added whenever necessary
  6. Follows bottom up approach in program design
  • Procedure oriented Paradigm: In procedure oriented approach, the problem is viewed as a sequence of things to be done such as reading, calculating and printing. A number of functions are written to accomplish these tasks. The primary focus is on the functions. In multi-function program, many important data items are placed as global so that they may be accessed by all the functions. Each function may have its own local data. Global data are more vulnerable to inadvertent change by a function. Another serious drawback with the procedural approach is that it does not model real world problems very well. Some characteristics exhibited by procedure oriented programming are:
  1. Emphasis is on doing things (algorithms)
  2. Large programs are divided into smaller programs known as functions.
  3. Most of the functions share global data.
  4. Data move openly around the system from function to function.
  5. Function transform data from one from to another
  6. Employs top down approach design.

 

Abstraction: Abstraction refers to the act of representing essential features without including the background details or explanations.  It is an essential element in object oriented programming. Programmers manage complexity through abstraction. For example, we do not think of a car as a set of tens of thousands of individual parts. We think of it as a well-defined object with its own unique behavior. We ignore the details of how the engine, transmission, and braking system work. Instead, we are free to utilize the object as a whole.

A powerful way to manage abstraction is through the use of hierarchical classification. This hierarchical classification is also used to computer programs. The data from a traditional process oriented program can be transformed into its component objects. A sequence of process steps can become a collection of messages between these objects. Thus, each of these objects describes its own unique behavior. These objects respond to messages telling to do something. This is essential in OOP. OOP is a powerful and natural paradigm for creating programs that survive the inevitable changes accompanying the life cycle of any major software project.

The Three OOP Principles

All object oriented programming languages provide mechanism to implement the object oriented model. They are encapsulation, inheritance and polymorphism.

 Encapsulation: Encapsulation is the mechanism that binds together code and the data it manipulates, and keeps both safe from outside interference and misuse. One way to think about the encapsulation is a protective wrapper that prevents the code and data from being arbitrarily accesses by other code defined outside the wrapper. Access to the code and data inside the wrapper is tightly controlled through a well-defined interface.

In Java, the basis of encapsulation is the class. A class defined the structures and behavior (data and code) that will be shared by a set of objects. Each object of a given class contains the structure and behavior defined by the class. A class contains methods and variables. Each method and member in a class can me marked as private or public. The private methods and data can only be accessed by code that is a member of the class and not by any other code. But public members can be accessed by outside code.

Inheritance: Inheritance is the process by which object of one class acquires the properties of objects of another class. This provides the concept of reusability. This is important because it supports the concepts of hierarchical classification. Without the use of hierarchical classification, each object would need to define all its characteristics explicitly. However, by the use of inheritance, each object would need to define those activities that make it unique with its class. It can inherit its general attributes from its parent. Let us take the following hierarchical relationship.

Polymorphism: Polymorphism (Greek term meaning many form) is the quality that allows one interface to access a general class of actions.. This specific action is determined by the exact nature of the situation. Polymorphism means ability to take more than one form. It is the mechanism in which an operation may exhibit different behavior depending on different instances. The behavior depends upon the types of data used in the operation. Let us consider the example of addition. For two numbers, the operation will generate a sum, for two strings it concatenates two strings

Polymorphism plays an important role in allowing objects having different internal structures to share the same external interfaces. This means that a general class of operations may be accessed in the same manner even though specific actions associated with each operation may differ. Polymorphism is extensively used in implementing inheritance.

 

Lexical Issues: Java programs are collection of whitespaces, identifiers, literals, comments, operators, separators and keywords.

Whitespace: Java is a free form language. This means that we do not need to follow any special indentation rules. In Java, whitespace is a space, tab, or newline

Identifier: Identifiers are used for class names, method names and variable names. An identifier may be any descriptive sequence of uppercase letters, numbers or the underscore and dollar sign characters. They must not begin with a number. Again, Java is case sensitive, so VALUE is a different identifier than a Value.

Literals: Literals in Java are a sequence of characters such as digits, letters and other characters that represent constant values. Java language specifies five major types of literals namely integer, floating point, character, string and Boolean.

7 is an integer literal

3.45 is a floating point literal

‘X’ is a character literal

“Programming” is a string literal

true is a boolean literal

Comments: The comments are not part of Java program but these are part of documentation. Java permits both the single line comments and multi-line comments. The single line comments begin with // and end at the end of the line. For longer comments, we can create long multi line comments by starting with a /* and ending with a */. Java also supports third type of comments called a documentation comment. This type of comment is used to produce an HTML file that documents your program. The documentation comment begins with a /** and ends with a */

Separators: In Java, there are few characters that are used as separators. The most commonly used separators in Java is the semicolon. It is used to terminate statements. The separators are shown in the following table.

Symbol Name Purpose
() Parenthesis Used to contain lists of parameters in method definition and location. Also used for defining precedence in expressions, containing expressions in control statements, and surrounding cast types.
{} Braces Used to contain the values of automatically initialized arrays. Also used to define a block of code, for classes, methods and local scopes.
[] Brackets Used to declare arrays types. Also used when dereference array values.
; Semicolon Terminates the statements.
, Comma Separates consecutive identifiers in a variable declaration. Also used to chain statements together inside a for loop.
. Period Used to separate package names from sub packages and classes. Also used to separate a variable or method from  a reference variable

The Java Keywords: Keywords are words that have distinct and special meaning in Java language and treated in special way by Java compiler. So we cannot use keywords as identifier. There are 50 reserved keywords currently defined in Java language. These keywords, combined with the syntax of the operators and separators, form the foundation of the Java language. The few Java keywords are listed below:

abstract class extends import private switch
assert const final instanceof protected synchronized
boolean continue finally int Public this
break default float interface Return throw ,throws
byte do for long Short transient
case double goto native Static try
catch else if new strictfp void
char enum implements package Super volatile, while


Didn't Find Any Subjects/Contents?

Click on the contribute button to contribute subjects materials on Study Notes Nepal.

Contribute

Leave a Reply

Your email address will not be published. Required fields are marked *


Join Our Facebook Community Group

Study Notes Nepal