Sie sind auf Seite 1von 6

Java Programming – Basics

Course Objectives

 To revise Object Oriented Programming concepts

 To introduce Java architecture and the basic syntax of Java

 To introduce the implementation of object oriented concepts using Java

 To introduce the Java library

 To introduce exception handling in Java

 To introduce annotations in Java

Agenda

 Object Oriented Concepts

 The Java Architecture

 The basic constructs in Java

 Arrays

What is Java and where is Java being used?

 Java is a very powerful OO programming language developed by Sun


Microsystems

 Java is widely used for developing web applications

 Java is the programming language used for developing Enterprise


Applications using the JEE Platform

Expectations

 At the end of this course, the participants are expected to be proficient in


the following

 Object Oriented Programming using Java

Object Oriented Programming – A Quick Revision

Software Complexity

 There are two categories of software

 Software developed for individuals for their own use

 Industrial strength software normally used by many people

 Industrial strength software is very complex in nature because of several


reasons
 Numerous Business rules (Functional Requirements)

 Non-Functional Requirements like Usability, Performance, Reliability


etc

 Complexity due to development process

Notes

Industrial strength software is very complex in nature because of several


reasons. The software has to satisfy a number of functional and non functional
requirements. For example, a banking software may have to satisfy the following
functional and non functional requirements.

Functional Requirements

All accounts should maintain a minimum balance of Rs. 500/-

1. The minimum amount that can be withdrawn from an account should be


Rs. 10/-

2. The minimum deposit that can be made to an account should be Rs. 10/-

3. etc…

Non-Functional Requirements

Usability - The software should have a good graphical user interface so that bank
clerks and customers with minimum knowledge of computers should be able to
use the software easily

1. Performance - The software should give a response within 2 seconds to


any request even when 500 users are simultaneously logged in

2. Reliability - The software should be running 24 x 7 without any downtime

3. etc…

Ways to handle Software Complexity

 Unstructured Programming

 Use of goto statements

 Lengthy code with no modularity

 As size increases, code becomes more complex to maintain

 Procedural Programming or Structured Programming was introduced to


handle software complexity

 Brought in Modularity in coding, enhancing maintainability


 Complexity made manageable by hiding complexity inside functions
(Concept of APIs)

 Introduced the concept of structures (also known as data


structures)

Earlier, programmers used to write programs in an unstructured way. The


programs were not split into small modules and often were very lengthy. They
frequently used the “goto” statement to jump from one part of a program to
another. This made the physical sequence of the program entirely different from
the logical sequence. As the size increases, such programs were very difficult to
understand and maintain.

Structured Programming tried to address these problems by suggesting the


following.

1. Minimize and if possible eliminate the use of the goto statement

2. Write modular programs

3. Write readable programs

Structured Programming reduced the complexity of programs to an extend.

Limitations of Structured Programming

 In structured programming, focus is on the algorithm and importance is


given to the procedure (logic) and not to the data on which these
procedures operate

 The entire problem was divided into a number of smaller units

 Functions/Procedures

 All these units need to work on a data item to produce the result

 The data need to be global

 Global data made the code complex

 As the code size grows, maintaining code becomes difficult

Notes

Even though structured programming is a good style of programming compared


to the unstructured style, there are several problems in this style also. In
structured programming, the focus is on process rather than on data. Design
approach is “Top-Down” where the entire solution is divided into smaller units
(Functions and Procedures). All these smaller units need to work on a data item
to return the result. For this reason the data items used are global which could
be accessed by all modules. This increased the complexity of the program. If the
data is getting corrupted, it was difficult to pin point the faulty module that
corrupted the data.
 Object Oriented Programming

 The entire program is visualized as a number of objects interacting


with each other

 An object is a self-contained entity that contains attributes (data) and


behaviors (functions)

– Car, Telephone, Pen

 For using an object one needs to just invoke a method (function) on the
object

 No need to know the internal details (data) of the object

Notes

Object Oriented Programming solves the problems one faces with structured
programming. In OOP, the entire program is viewed as a number of objects
interacting with each other. Each object will have some data and functions. One
can use an object just by knowing the functions. There is no need to know about
the data for using an object. This reduces the complexity of an object.

For example, a Stack object will have a list as data and push and pop as
functions. The list could be made up of an array or a linked list. One need not
know this to use the Stack as long as one knows how to use the push and pop
functions. This makes the usage of Stack very simple.

Consider a banking application. In structured programming, the application will


contain a set of functions, arrays, structures and files. It would be difficult for
anyone to look at this and relate it with the activities of a bank. In OOP, the
application will contain objects like Customer, Account and Manager that interact
with each other. Since real life situations could be modeled well, this application
is very easy to understand and maintain.

 Example: Car object

 State

– Current Speed

– Current Gear

– Engine State (Running, Not Running)

 Behavior (Acts on the object and changes state)

– Slow down

– Accelerate

– Stop
– Switch Off Engine

– Start Engine

 Example: Dog Object

 State

– Color

– Breed

– Activity (Barking/Not barking)

– Tail Activity (Wagging/Not Wagging)

 Behavior

– Bark

– Wag Tail

– Eat

 A Class

 Is a blue print used to create objects.

 Is a software template that defines the methods and variables to be


included in a particular kind of Object.

 Examples

 Animal, Human Being, Automobiles, Bank Account, Customer

Notes

A class is a blue print used to create objects. Class is an idea whereas object is a
real thing. For example, Fruit is a class whereas apple and mango are objects of
that class. Class gives the general characteristics of all the objects that are
created from it. Once the objects required for an application are identified,
classes are designed from which these objects could be created.

For example, in a banking application, we have many objects called Customer.


Each Customer will have some data like Customer Number, Name, Address,
Account No and functions for setting and getting these data. First a class called
Customer is created. Any number of objects can now be created from this class,
each representing a real Customer of the bank.

 A class contains state and behavior

 State (Member Variables)

 Variables defined inside the class


 Not exposed to external world

 Behavior (Member Methods)

 Functions defined inside the class

 Behavior exhibited by the class to external world

 Exposed to external world

 An object is an instance of a class

Abstraction (1/2)

 The process of exposing the relevant details and hiding the irrelevant
details is called Abstraction

 Helps simplify the understanding and using of any complex system

 One does not have to understand how the engine works to drive a
car

 Similarly one does not have to understand the internal


implementation of a software object to use it

Notes

The process of exposing the relevant details and hiding the irrelevant details is
called Abstraction. Abstraction is not an entirely new concept introduced by OOP.
Structured Programming also supported abstraction with the help of data
structures and functions. For example, one need not know the internal details of
the printf function of C to use it. One need not know about how characters are
converted to ASCII code and stored in the memory for using a character array.

OOP provides better abstraction. While structured programming provides


abstraction at the level of data structures and function, OOP provides abstraction
at a higher level; that is at the level of objects. Higher the abstraction level
easier it is to understand.

Das könnte Ihnen auch gefallen