Showing posts with label oop. Show all posts
Showing posts with label oop. Show all posts

Saturday, February 19, 2022

Object Oriented Programming

 Advantages of OOP :

  • Reusability
  • OOPs is very helpful in solving very complex level of problems.
  • Highly complex programs can be created, handled, and maintained easily using object-oriented programming.
  • OOPs, promote code reuse, thereby reducing redundancy.
  • OOPs also helps to hide the unnecessary details with the help of Data Abstraction.
  • OOPs, are based on a bottom-up approach, unlike the Structural programming paradigm, which uses a top-down approach.
  • Polymorphism offers a lot of flexibility in OOPs.

Properties of OOP :

  • Encapsulation
  • Data abstraction
  • Polymorphism 
  • Inheritance 

Encapsulation vs Data Abstraction

Encapsulation is the packing of "data" and "functions operating on that data" into a single component and restricting the access to some of the object's components. Encapsulation means that the internal representation of an object is generally hidden from view outside of the object's definition.

Abstraction is a mechanism which represent the essential features without including implementation details.

Encapsulation:-- Information hiding.
Abstraction:-- Implementation hiding.


Polymorphism 

Polymorphism is composed of two words - “poly” which means “many”, and “morph” which means “shapes”. Therefore Polymorphism refers to something that has many shapes.

Types of Polymorphism 




Compile time polymorphism : method overloading

Runtime polymorphism : method overriding 


Reference :

Tuesday, September 12, 2017

Book - Core Java for Impatiens - Chapter 2 - Object Oriented Programming

* It is a good idea to run javac with the -d option. Then the class files are generated in a separate directory, without cluttering up the source tree, and they have the correct subdirectory structure

*By default, JAR files use the ZIP format. There is also an option for another compression scheme, called “pack200,” that is designed to compress class files more efficiently

*You can use JAR files to package a program, not just a library. Generate
the JAR file with jar cvfe program.jar com.mycompany.MainClass com/mycompany/*.class
Then run the program as  java -jar program.jar

*The javac and java programs have an option -classpath, which you can abbreviate
to -cp. For example,
java -classpath .:../libs/lib1.jar:../libs/lib2.jar com.mycompany.MainClass
This class path has three elements: the current directory (.), and two JAR files in
the directory ../libs.

*In Windows, use semicolons instead of colons to separate the path elements:
java -classpath .;..\libs\lib1.jar;..\libs\lib2.jar com.mycompany.MainClass

*If you have many JAR files, put them all in a directory and use a wildcard to
include them all:
java -classpath .:../libs/\* com.mycompany.MainClass

*Since the warningString variable is not private, the methods of all classes in the java.awt package can access it. Actually, no method other than those of the Window class itself does that, so it seems likely that the programmer simply forgot the private modifier.
This can be a security issue because packages are open ended. Any class can add itself to a package by providing the appropriate package statement.
The Java implementors protect themselves from such an attack by rigging the ClassLoader class so it will not load any class whose fully qualified name starts with java.
If you want to have a similar protection for your own packages, you need place them into a sealed JAR file. Provide a manifest, a plain text file containing entries
Name: com/mycompany/util/
Sealed: true
Name: com/mycompany/misc/
Sealed: true
Then run the jar command like this:
jar cvfm library.jar manifest.txt com/mycompany/*/*.class

* Static Import : A form of the import statement permits the importing of static methods and
variables. For example, if you add the directive
import static java.lang.Math.*;

*You cannot import static methods or fields from a class in the default package.

In order to buy book : Core Java for Impatiens