Skip to content

Commit a1d229b

Browse files
authored
Update README.md
1 parent 5e840b7 commit a1d229b

File tree

1 file changed

+56
-14
lines changed

1 file changed

+56
-14
lines changed

README.md

Lines changed: 56 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Object-Oriented-Programming-in-Java
22

3-
Resources: [Geeksforgeeks](https://www.geeksforgeeks.org/java/) , [javabeginnerstutorial](https://javabeginnerstutorial.com/core-java-tutorial/)
3+
References: [Geeksforgeeks](https://www.geeksforgeeks.org/java/) , [javabeginnerstutorial](https://javabeginnerstutorial.com/core-java-tutorial/)
44

55

66
**JAVA IS A PLATFORM-INDEPENDENT LANGUAGE**
@@ -58,7 +58,7 @@ An object is an instance of a class.Technically, Class is a template which descr
5858

5959
When an object of a class is created, the class is said to be **instantiated**. All the instances share the attributes and the behavior of the class. But the values of those attributes, i.e. the state are unique for each object. A single class may have any number of instances.
6060

61-
**FOLDER:[Class and objects](https://github.com/disha2sinha/Object-Oriented-Programming-in-Java/tree/master/Classes%20and%20objects):**
61+
**PACKAGE:[Class and objects](https://github.com/disha2sinha/Object-Oriented-Programming-in-Java/tree/master/Classes%20and%20objects):**
6262

6363
**Code1:[CreatingObjects1.java](https://github.com/disha2sinha/Object-Oriented-Programming-in-Java/blob/master/Classes%20and%20objects/Creatingobjects1.java):** Shows the creation of object using 'new' keyword.The new operator instantiates a class by allocating memory for a new object and returning a reference to that memory.
6464

@@ -106,7 +106,7 @@ Methods calls are implemented through stack. Whenever a method is called a stack
106106

107107
**Java is strictly pass by value**:
108108

109-
**FOLDER:[Methods](https://github.com/disha2sinha/Object-Oriented-Programming-in-Java/tree/master/Methods):**
109+
**PACKAGE:[Methods](https://github.com/disha2sinha/Object-Oriented-Programming-in-Java/tree/master/Methods):**
110110

111111
**Code1:[PassByValue1.java](https://github.com/disha2sinha/Object-Oriented-Programming-in-Java/blob/master/Methods/PassByValue1.java):** We pass an int to the function “change()” and as a result the change in the value of that integer is not reflected in the main method.Java creates a copy of the variable being passed in the method and then do the manipulations. Hence the change is not reflected in the main method.
112112

@@ -213,7 +213,7 @@ The **java.lang.System.exit()** method exits current program by terminating runn
213213

214214
Constructors are used for initializing new objects. Constructors does not return any values but implicitly it returns the object of the class. Fields are variables that provides the state of the class and its objects, and methods are used to implement the behavior of the class and its objects.
215215

216-
**Folder:[Constructors](https://github.com/disha2sinha/Object-Oriented-Programming-in-Java/tree/master/Constructors)**
216+
**PACKAGE:[Constructors](https://github.com/disha2sinha/Object-Oriented-Programming-in-Java/tree/master/Constructors)**
217217

218218
**Constructors cannot be Inherited:**
219219

@@ -344,17 +344,17 @@ Packages can be of two types:
344344
**Built-in Packages:**
345345

346346
These packages consist of a large number of classes which are a part of Java API.Some of the commonly used built-in packages are:
347-
1) java.lang: Contains language support classes(e.g classed which defines primitive data types, math operations). This package is automatically imported.
347+
1) **java.lang:** Contains language support classes(e.g classed which defines primitive data types, math operations). This package is automatically imported.
348348

349-
2) java.io: Contains classed for supporting input / output operations.
349+
2) **java.io:** Contains classed for supporting input / output operations.
350350

351-
3) java.util: Contains utility classes which implement data structures like Linked List, Dictionary and support ; for Date / Time operations.
351+
3) **java.util:** Contains utility classes which implement data structures like Linked List, Dictionary and support ; for Date / Time operations.
352352

353-
4) java.applet: Contains classes for creating Applets.
353+
4) **java.applet:** Contains classes for creating Applets.
354354

355-
5) java.awt: Contain classes for implementing the components for graphical user interfaces (like button , ;menus etc).
355+
5) **java.awt:** Contain classes for implementing the components for graphical user interfaces (like button , menus etc).
356356

357-
6) java.net: Contain classes for supporting networking operations.
357+
6) **java.net:** Contain classes for supporting networking operations.
358358

359359
**Points to be noted:**
360360

@@ -370,7 +370,49 @@ These are the packages that are defined by the user. First we create a directory
370370

371371
Static import is a feature introduced in Java programming language ( versions 5 and above ) that allows members ( fields and methods ) defined in a class as public static to be used in Java code without specifying the class in which the field is defined.
372372

373-
**Code3::[StatisImport.java](https://github.com/disha2sinha/Object-Oriented-Programming-in-Java/blob/master/StaticImport.java):** A program to illustrate how Static import works.
373+
**Code3::[StaticImport.java](https://github.com/disha2sinha/Object-Oriented-Programming-in-Java/blob/master/StaticImport.java):** A program to illustrate how Static import works.
374+
375+
# INTERFACES:
376+
377+
Interface looks like a class and has variables and methods declaration like that of a class but it doesnot contain any method definition.
378+
379+
380+
1.Interfaces specify what a class must do and not how. It is the blueprint of the class.
381+
2.An Interface is about capabilities like a Player may be an interface and any class implementing Player must be able to (or must implement) move(). So it specifies a set of methods that the class has to implement.
382+
3.If a class implements an interface and does not provide method bodies for all functions specified in the interface, then class must be declared abstract.
383+
4.A Java library example is, Comparator Interface. If a class implements this interface, then it can be used to sort a collection.
384+
385+
**Use of Interface:**
386+
387+
1.It is used to achieve total abstraction.
388+
389+
2.Since java does not support multiple inheritance in case of class, but by using interface it can achieve multiple inheritance .
390+
391+
3.It is also used to achieve loose coupling.
392+
393+
4.It provides boundness to the program.
394+
395+
5.Abstract classes may contain non-final variables, whereas variables in interface are final, public and static.
396+
397+
**PACKAGE:[Interface](https://github.com/disha2sinha/Object-Oriented-Programming-in-Java/tree/master/Interface):**
398+
399+
**Code1:[Interface1.java](https://github.com/disha2sinha/Object-Oriented-Programming-in-Java/blob/master/Interface/Interface1.java):** A simple java program to illustrate use of Interface.
400+
401+
**Code2:[Interface2.java](https://github.com/disha2sinha/Object-Oriented-Programming-in-Java/blob/master/Interface/Interface2.java):** A simple program to show that we can now define static methods in interfaces(JDK 8 onwards) which can be called independently without an object.These methods are not inherited.
402+
403+
Read more on Interface **[here](https://github.com/disha2sinha/Object-Oriented-Programming-in-Java/blob/master/Interface/MoreAboutInterface.txt)**
404+
405+
Inheritence can be extended or inherited.
406+
407+
**Code3:[Interface3.java](https://github.com/disha2sinha/Object-Oriented-Programming-in-Java/blob/master/Interface/Interface3.java):** A Java program to show Interface can be extended.
408+
409+
### Abstract class:
410+
A class with a pure virtual function ie, an abstract method is termed as Abstract class.In java, however the class has to be declared with abstract keyword to make it Abstract.
411+
412+
**Code4:[AbstractClass1.java]():** A program to illustrate use of Abstract class.
413+
414+
**Code5:[AbstractClass2.java]():** A program to show that java allows abstract classes without any abstract method in it.
415+
374416

375417
**JAVA ACCESS MODIFIERS:**
376418

@@ -405,7 +447,7 @@ Inheritance is an important pillar of OOP(Object Oriented Programming). It is th
405447
**4.Multiple Inheritence:** In Multiple inheritance ,one class can have more than one superclass and inherit features from all parent classes.Java does not support multiple inheritance with classes. In java, we can achieve multiple inheritance only through Interfaces.
406448
Multiple inheritance is not supported by Java using classes , handling the complexity that causes due to multiple inheritance is very complex. It creates problem during various operations like casting, constructor chaining etc
407449

408-
**FOLDER:[Inheritence](https://github.com/disha2sinha/Object-Oriented-Programming-in-Java/tree/master/Inheritence):**
450+
**PACKAGE:[Inheritence](https://github.com/disha2sinha/Object-Oriented-Programming-in-Java/tree/master/Inheritence):**
409451

410452
**Code1: [ObjectCreation.java](https://github.com/disha2sinha/Object-Oriented-Programming-in-Java/blob/master/Inheritence/ObjectCreation.java):** Code shows that super class and sub class constructors refer to the same objects.
411453

@@ -419,7 +461,7 @@ Multiple inheritance is not supported by Java using classes , handling the compl
419461

420462
'this' works as a reference to the current object, whose method or constructor is being invoked. This keyword can be used to refer to any member of the current object from within an instance method or a constructor.
421463

422-
**FOLDER: [this keyword](https://github.com/disha2sinha/Object-Oriented-Programming-in-Java/tree/master/this%20keyword)**:
464+
**PACKAGE: [this keyword](https://github.com/disha2sinha/Object-Oriented-Programming-in-Java/tree/master/this%20keyword)**:
423465

424466
**Code1: [this1.java](https://github.com/disha2sinha/Object-Oriented-Programming-in-Java/blob/master/this%20keyword/this1.java):** this used to refer current class instance variables.
425467

@@ -437,7 +479,7 @@ Multiple inheritance is not supported by Java using classes , handling the compl
437479

438480
The super keyword in java is a reference variable that is used to refer parent class objects.
439481

440-
**FOLDER:[super KEYWORD](https://github.com/disha2sinha/Object-Oriented-Programming-in-Java/tree/master/Super%20keyword):**
482+
**PACKAGE:[super KEYWORD](https://github.com/disha2sinha/Object-Oriented-Programming-in-Java/tree/master/Super%20keyword):**
441483

442484
**Code1:[superWithConstructor.java](https://github.com/disha2sinha/Object-Oriented-Programming-in-Java/blob/master/Super%20keyword/superWithConstructor.java):** 'super' keyword can also be used to access the parent class constructor.'super' can call both parametric as well as non parametric constructors depending upon the situation.This code is also an example of **Constructor chaining with super()** discussed above.
443485

0 commit comments

Comments
 (0)