Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 3

The important features of Object Oriented programming are: 1.Encapsulation, 2.

Inheritance,
3.Abstraction, 4.Polymorphism, 5.Data Hiding, 6.Overloading, 7.Reusability
Class: A class is a group of objects which have common properties. It is a template or blueprint from
which objects are created.
Objects: object is an instance of a class.
Reusability: As the name specifies, reusability is a mechanism which facilitates you to reuse the
fields and methods of the existing class when you create a new class. You can use the same fields
and methods already defined in the previous class.
CLASS OBJECT

Class is a data type Object is an instance of Class.

It generates OBJECTS It gives life to CLASS

Does not occupy memory It occupies memory location.


location
It cannot be manipulated because it is not It can be manipulated.
available in memory (except static class)
Encapsulation: Encapsulation is defined as the wrapping up of data under a single unit. It is the
mechanism that binds together code and the data it manipulates. Other way to think about
encapsulation is, it is a protective shield that prevents the data from being accessed by the code
outside this shield.
Inheritance: Inheritance in Java is a mechanism in which one object acquires all the properties and
behaviours of a parent object. The idea behind inheritance in Java is that anyone can create new
classes that are built upon existing classes.
Sub Class/Child Class: Subclass is a class which inherits the other class.
Super Class/Parent Class: Superclass is the class from where a subclass inherits the features.
Abstraction: Abstraction means displaying only essential information and hiding the details.
Data abstraction refers to providing only essential information about the data to the outside world,
hiding the background details or implementation.
Polymorphism: Polymorphism in Java is a concept by which we can perform a single action in
different ways.
Data Hiding: In encapsulation, the variables of a class will be hidden from other classes, and can be
accessed only through the methods of their current class. Therefore, it is also known as data hiding.
Overloading: Methods overloading is a feature that allows a class to have more than one method
having the same name, if their argument lists are different. It is similar to constructor overloading in
Java that allows a class to have more than one constructor having different argument lists.
Reusability: Reusability means the reuse of properties of the base class in the derived classes.
Reusability permits the reuse of members of the previous class.

Java C++
Java does not support pointers, unions, operator C++ supports pointers, unions, operator
overloading and structure. overloading and structure.
Java supports garbage collection. C++ does not supports garbage collection.
Java is platform independent. C++ is platform dependent.
Java supports inheritance except for multiple C++ supports inheritance including multiple
inheritance inheritances
Java is interpreted. C++ is compiled.
Java does not support destructor C++ supports destructors.
Advantages of OOP: 1.Code reuse & recycling, 2.Improved software-development productivity,
3.Improved software maintainability, 4.Faster development, 5.Lower cost of development, 6.Higher-
quality software, 7.Encapsulation
Disadvantages of OOP: 1.Steep learning curve, 2.Could lead to larger program sizes, 3.Could produce
slower programs

Section Description

Documentation Section one can write a comment in this section.

Package statement one can create a package with any name. A package is a group of classes that
are defined by a name. package package_name;

Import statements This line indicates that if one want to use a class of another package, then he
can do this by importing it directly into his program.
Example:
import calc.add;

Interface statement Interfaces are like a class that includes a group of method declarations.

Class Definition A Java program may contain several class definitions. Classes are the main and
essential elements of any Java program.

Main Method Class Every Java stand-alone program requires the main method as the starting
point of the program. This is an essential part of a Java program. There may be
many classes in a Java program, and only one class defines the main method.
Methods contain data type declaration and executable statements.
Keyword: In Java, a keyword is a word with a predefined meaning in Java programming language
syntax.
Identifier: Identifiers are the names of variables, methods, classes, packages and interfaces.
Rules for identifiers in java:
1. Keywords cannot be used as identifiers.
2. Identifier must not start with any numeric or it is always recommendable to starts some of the
identifiers with small case.
3. It must not contain any special symbol other than (_ or $).
4. Identifier must not contain any blank space in between.
5. Identifiers may contain numeric but it should not be in starting.
Constant: A constant is a variable whose value never changes.
Primitive Data Types: A primitive data type specifies the size and type of variable values, and it has
no additional methods
Non Primitive Sata Type: Non-primitive types are created by the programmer and is not defined by
Java (except for String).
Type Casting: We can convert one data types into another data type using casting when narrowing
happens in case widening happens, no casting is required.
Increment operator: It is used to increment a value by 1. There are two varieties of increment
operator:
Post-Increment : Value is first used for computing the result and then incremented.
Pre-Increment : Value is incremented first and then result is computed.
Decrement operator: It is used for decrementing the value by 1. There are two varieties of
decrement operator.
Post-decrement : Value is first used for computing the result and then decremented.
Pre-decrement : Value is decremented first and then result is computed.
Conditional operator: The conditional operator is also known as the ternary operator. This operator
consists of three operands and is used to evaluate Boolean expressions. The goal of the operator is
to decide; which value should be assigned to the variable. The operator is written as:
variable x = (expression)? value if true: value if false
Precedence: If more than one operators are involved in an expression, Programming language has a
predefined rule of priority for the operators. This rule of priority of operators is called operator
precedence. In C, precedence of arithmetic operators (*, %, /, +, -) is higher than relational operators
(==, !=, >, <, >=, <=) and precedence of relational operator is higher than logical operators(&&, ||
and !).
Example of precedence: (1 > 2 + 3 )
This expression is equivalent to: (1 > (2 + 3))
i.e, (2 + 3) executes first resulting into 5
Then, first part of the expression (1 > 5) executes resulting into 0 (false)
Output: 0
Associativity: If two operators of same precedence (priority) is present in an expression,
Associativity of operators indicate the order in which they execute.
Example of associativity: 1 == 2 != 3
((1 == 2) != 3)
i.e, (1 == 2) executes first resulting into 0 (false)
hen, (0 != 3) executes resulting into 1 (true)
Output: 1
BASIS FOR
IF-ELSE SWITCH
COMPARISON

Basic Which statement will be executed Which statement will be executed is


depend upon the output of the decided by user.
expression inside if statement.

Expression if-else statement uses multiple switch statement uses single expression for
statement for multiple choices. multiple choices.

Testing if-else statement test for equality switch statement test only for equality.
and logical expression.

Evaluation if statement can test integer, switch statement can test only character or
character, pointer or floating-point integer value.
type or boolean type.

Sequence of Either if statement will be executed switch statement execute one case after
Execution or else statement is executed. another till a break statement is appeared
or the end of switch statement is reached.

Editing It is difficult to edit the if-else It is easy to edit switch cases as, they are
statement, if the nested if-else recognized easily.
statement is used.

You might also like