Chapter 3 : Basic concepts of object oriented programming using Java

In this chapter we will cover the basic concepts of object oriented programming using Java. We will discuss the language features that make Java an object oriented language and how to use these features to write effective Java code. By the end of this chapter you should have a good understanding of the basics of object oriented programming and be able to start writing your own Java programs.

 

Java is an object oriented programming language. This means that the language has been designed around the concept of objects. An object is a self-contained unit of code and data. Objects can communicate with each other by sending messages. In Java, a message is sent by calling a method on an object.

 

Objects are created from templates called classes. A class defines the variables and methods that an object will have. When you create an object from a class, you are said to instantiate the class. Once you have created an object, you can use it by calling its methods.

 

Java has a number of features that make it well suited for object oriented programming. These features include:

- Encapsulation: Encapsulation is the process of hiding the internals of an object from the outside world. In Java, this is accomplished by using access modifiers. Access modifiers control who can access a particular method or variable. By making methods and variables private, you can prevent them from being accessed by code that is outside of the object.

- Inheritance: Inheritance is the process of creating new classes from existing classes. When you create a new class that inherits from an existing class, you are said to subclass the existing class. The new class will inherit all of the methods and variables of the existing class. You can then add new methods and variables to the new class, or override existing ones.

- Polymorphism: Polymorphism is the ability of an object to take on many forms. In Java, this is accomplished by using method overloading and method overriding. Method overloading allows you to have multiple methods with the same name, as long as they have different signatures. Method overriding allows you to provide a different implementation of a method in a subclass than what is provided in the superclass.

 

These are just a few of the features that make Java an object oriented language. In this chapter we will cover these topics in more depth and learn how to use them to write effective Java code.

Comments