>
Characteristics of Java PART 3 is HERE
Java Properties:
The Java programming language is a high-level language that can be characterized by all the following buzzwords:- Simple:
- Java is designed for easy and effective programming. If the concepts of object oriented programming are understood properly, the implementation of programs in Java becomes easy.
- Because Java inherits the syntax of C/C++ and many object-oriented features of C++, it is easy and simple to program.
- Object oriented:
- Java follows all the concepts of object oriented programming which includes three basic OOP features:
- Encapsulation:
- Encapsulation is the mechanism that binds together code and the data it manipulates, and keeps both safe from outside interference and misuse.
- Encapsulation is as a protective wrapper that prevents the code and data from being arbitrarily accessed by other code defined outside the wrapper. Access to the code and data inside the wrapper is tightly controlled through a well-defined interface or class.
- In java, encapsulation is supported by concept of classes and objects. A class defines the structure 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, as if it were stamped out by a mold in the shape of the class. For this reason, objects are referred to as instances of a class.
- For example:
class a
{
/* body of class a. the body contains methods and variables that are encapsulated by the wrapper ‘class’. These class members can be accessed only when an object is referenced to class a. */
} - Each method or variable in a class may be marked private or public. The public interface of a class represents everything that external users of the class need to know, or may know. The private methods and data can only be accessed by code that is a member of the class. Therefore, any other code that is not a member of the class cannot access a private method or variable.
- Inheritance:
- Inheritance is the process by which one object acquires the properties of another object.
- Inheritance is important because it allows extension and reuse of the existing code, without having to repeat or rewrite the code from search.
- It involves the creation of new classes known as derived classes from the existing base classes. The new derived class inherits the members of the base class and also adds its own methods and variables.
- For example, in a banking system, the class student_customer can be derived from customer_main class.
Eg.:
class student_customer extends customer_main {
// this is the derived class.
}
- Data Abstraction:
- Abstraction is a design technique that focuses on the essential attributes and behavior. It provides a named collection of essential attributes and behavior.
- Data abstraction is a process of abstracting common features from objects and procedures and creating a single interface to perform multiple tasks.
- For example, if the function of ‘print’ is used in many classes, the programmer may ‘abstract’ that function, creating a separate class that handles different types of printing.
- Encapsulation and abstraction are closely related to each other. Encapsulation is a concept embedded in abstraction. A good abstraction provides:
o Meaningful way of naming the attributes and methods.
o Minimum features
o Complete details.
- d. Polymorphism:
- Polymorphism is a feature that allows one interface or feature to be implemented in various different ways. It is the ability of different objects to respond to the same message in different ways.
- Polymorphism is expressed as “one interface, multiple methods”. It allows a single name or operator to be associated with different operations, depending upon type of data it has passed.
- For example, the operator ‘+’ can be used to add two integer variables if it is used with integer types, but it functions as a concatenation operator if used with strings.
Example:
System.out.println(“this is” + “java”); // will return the string concatenated output. “this is java” System.out.println(5+2); // will return the addition of numbers 5 and 2= 7
Characteristics of Java PART 3 is HERE
Comments
Post a Comment