Prev Next

Introduction

Four kinds of programming paradigms

  • Imperative: First do this, then do that (Algol, C, Pascal)
  • Functional: Declarative, originates from mathematical discipline (Scheme, Lisp, Scala)
  • Logic: Based on axioms, inference rules and queries (Prolog)
  • Object oriented: Supports encapsulation and logical grouping of program aspects (SmallTalk, Java, C++)

OO programming = OO thinking + programming

  • There is literally nothing an OO program can do which an imperative program cannot. Just a way of thinking and organizing.
  • Centered around the concept of objects that contain (i) data, referred to as fields or attributes and (ii) code in the form of procedures, referred to as methods, that manipulate the data.
  • An object's procedures can access and often modify the data fields of the object with which they are associated.
  • Features include encapsulation, data hiding, composition, inheritance, delegation, polymorphism, dynamic dispatch.
  • Helps in better comprehensibility, safety, reusability, extensibility and maintainability.

Java

  • A general-purpose computer programming language that is concurrent, class-based, object-oriented.
  • Specifically designed to have as few dependencies as possible. Write once, run anywhere (WORA).
  • Java applications are typically compiled to bytecode that can run on any Java virtual machine (JVM) regardless of computer architecture.
  • Originally developed by James Gosling at Sun Microsystems (which has since been acquired by Oracle Corp.)
  • The language derives much of its syntax from C and C++, but it has fewer low-level facilities than either of them.
  • The latest version is Java 9.

Java's main strength: Libraries -- that spans length and breadth of technologies:

  • Core programming, GUI development, Event driven programming,
  • Networking, Web development, Enterprise development,
  • Concurrency, Parallel and Distributed programming, Big data,
  • Embedded, Mobile, ...... the list never ends

Writing Java programs

  • You can use any editor: vi, emacs, textedit, notepad.
  • Source files are saved with .java extension
  • javac Hello.java at command prompt/terminal for compilation
  • java Hello at command prompt/terminal for execution

An Example: Sigma.java

    public class Sigma {
       public static void main(String[] args) {
          Sigma f = new Sigma();
          int sum = f.findSum(10);
          System.out.println("sum = " + sum);
       }

       public int findSum(int num) {
          int sum = 0;
          for (int i=1; i<=num; i++)
             sum += num;
          return sum;
       }
    }
    

cmd> javac Sigma.java => Creates Sigma.class
cmd> java Sigma
sum = 55
cmd>

Please note: File name should be same as the class name.

We will use Eclipse - an Integrated Development Environment (IDE)

  • Enables faster development and easier debugging.
  • JUnit - a unit testing framework integrated with Eclipse.
  • JIVE - an add-on to Eclipse, for visualizing program execution.

About the course

1. This course is on object oriented programming and Java is used as the vehicle to expose the OO paradigm.

2. Most of the object oriented concepts are centered around a single example to develop a better intuition. The expectation is that one grasps the principles of object orientation and apply them in developing medium to large applications.

3. The emphasis will be on the object oriented concepts during the initial part of this course. I have kept the discussion on Java features to bare minimum in the initial part of the lectures since it can take the attention away from OO concepts.

  • For example, mundane things such as doing I/O, working with files, string manipulations involve use of Java libraries, which if introduced before can affect your understanding OO paradigm. Hence none of the Java library calls, barring System.out.println(), is used until we complete an overview of OO features such as encapsulation, data hiding, polymorphism, inheritance, reusability and exception handling.
  • Similarly, setting up the environment such as PATH, CLASSPATH, etc., and running the program at command-prompt are dealt later.

Hence, try this series of lessons before you plunge into any Java book.

4. Adopting object orientation principles is extremely valuable if you are developing application with large code base with heterogeneous functionality. For writing simple programs (that you learnt in an C programming course), you may find little value in using OO principles.

5. While most of the material can be understood without much difficulty, it is possible that you develop a better/deeper grasp if you attended the lectures.

6. I assume you have some background on programming language like C and comfortable with basic concepts, such as input, output, primitive and user-defined data types, arrays, branching, loops and functions.

Resources

Java Complete Reference McGraw Hill.
Thinking In Java Prentice Hall.
Java Tutorial Tutorial Point.
Java Errors Explained.
Oracle Java 8 Docs (online).
Oracle Java 8 Tutorials (online).
Oracle Java 8 Docs (local copy).
Oracle Java 8 Tutorials (local copy).
... and countably infinite stuff on the web.