
Quick Contact
Java Tutorial
- What is Java?
- History of Java
- Hello Java Program
- Features of Java
- Basic Syntax
- Java Setup
- Data Types in Java
- Java Variables
- Operators in Java
- JVM
- Java If-else Statement
- Switch Case Statement
- Java Loops
- Do-While Loop
- Java While Loop
- Continue Statement
- Break Statement in Java
- Constructors in Java
- Oops Concept in Java
- Features of OOPs
- Inheritance
- Exeception handeling
- Aggregation (HAS-A relationship) in Java
- Method Overriding in Java
- Method Overloading
- Java Static Keyword
- Java This Keyword
- Java Final Keyword
- Polymorphism
- Static Binding and Dynamic Binding
- Abstract class in Java
- Access Modifiers in Java
- Difference between abstract class and interface
- Interface in Java
- Garbage Collection in Java
- Java Package
- Encapsulation
- Serialization and Deserialization in Java
- Java Inner Classes
- Java Applets
- Multithreading in Java
- Thread Priorities in Java
- Thread Creation
- Inter Thread Communication
- Wrapper Classes in Java
- Java Input Output
- Java AWT Introduction
- Java Layout Manager
- Java Layout Policy
- Java AWT Events
- Collection Framework
- Collection Framework List Interface
- Swing in Java
- Swing Utility Classes
- Swing Layout Managers
- Java JDBC
- Hibernate Framework Overview – Architecture and Basics
Springboot
- Spring Environment Setup
- Spring Boot CRUD REST API Project using IntelliJ IDEA | Postman | MySQL
- Dockerizing Spring Boot Application | Spring Boot Docker Tutorial
- spring-boot-restapidocumentation with swagger
- Spring Boot HttpClient Overview
- Apache HttpClient POST HTTP Request Example
- Apache HttpClient PUT HTTP Request Example
- Apache HttpClient DELETE HTTP Request Example
- Apache HttpClient HTML Form POST Request Example
- Spring Boot JSP Exampl
- Deploying Spring Boot WAR file with JSP to Tomcat
- Spring Boot Annotations
- Spring Core Annotations
- Spring MVC Annotations with Examples
- Spring Scheduling Annotations
- Spring - Java-based Container Configuration
- Spring Java Based Configuration Example
Hibernate
- Hibernate 5 hello world
- Hibernate- One to One Unidirectional Mapping Annotation Example
- Hibernate - Batch Processing
- Hibernate - Interceptors
- Hibernate 5 - Create, Read, Update and Delete (CRUD) Operations Example
- Hibernate Transaction Management
- Hibernate One to Many Unidirectional Mapping Example
- Hibernate One to Many Bidirectional Mapping Example
- Hibernate Many to Many Annotation Mapping Example
- Hibernate Primary KeyJoin Column
- Hibernate First Level Cache with Example
- Hibernate XML Configuration Example with Maven + Eclipse + MySQL Database
- Hibernate Java Configuration Example
- JPA 2 with Hibernate 5 Bootstrapping Example
- JPA and Hibernate Cascade Types
- Hibernate/JPA - Primary Key Generation
- Hibernate 5 - Enum Type Mapping Example
- Hibernate Component Mapping
- Hibernate Object States – Transient,Persistent and Detached
- Hibernate 5 - Save an Entity Example
- Hibernate 5 - Persist an Entity Example
- Hibernate 5 - saveOrUpdate() Method Example
- Hibernate 5 - get(), load() and byId() Method Examples
- Hibernate 5 - merge() Example
- Hibernate 5 - Delete or Remove an Entity Example
- Hibernate 5 - load() Method Example
- Hibernate Session Interface Methods
- Hibernate Session.clear() Method Example
- Introduction Of Java strutes to Architecture
- Struts 2 - Architecture
- Struts 2 - Configuration Files
- Struts 2 - Actions
- Struts 2 - Interceptors
- Struts 2 - Results & Result Types
- Struts 2 - Value Stack/OGNL
- Struts 2 - File Uploading
- Struts 2 - Database Access
- Struts 2 - Validations Framework
JAVA FX
- JavaFX Tutorial
- Introduction to JavaFX Pane
- JavaFX Popup
- JavaFX group
- JavaFX Controller
- JavaFX Gradient Color
- JavaFXAnchorPane
- JavaFXTabPane
- JavaFX Scene
- JavaFX Stage
- JavaFXWebView
- JavaFX Timeline
- JavaFX Timer
- JavaFX Image
- JavaFX Background
- JavaFX dialog
- JavaFX Font
- JavaFXTextArea
- JavaFXObservableList
- JavaFX GUI
- JavaFX FXML
- JavaFXEventHandler
- JavaFXGradle
- JavafxScrollpane
- JavaFXAPI
Aggregation (HAS-A relationship) in Java
When we talk about aggregation than aggregation is a form of association. Aggregation is used to refer one-way relationship between two objects.
In java aggregation means HAS-A relationship, it means when class contains reference of another class known as aggregation.
Aggregation is a way of composing different abstractions together in defining a class. For example, a car class can be limited to contain other classes such as engine class, seat class, wheels class etc. The car class can define an engine class as one of its attributes. A concrete instance of a car class will have its attribute as engine which will hold a concrete instance of engine class. For example, two instances of a car class fiat and ford will have their engine attributes which will keep a ford engine and fiat engine objects respectively. Objects could share other objects. When ford and fiat are using the same engine design, they can share one engine design object. In such a case, engine design object is said to be nominally part of car design object.
Other examples of aggregation are A window class containing menu class, check-box class etc.
Example of aggregation
A car object is an aggregation of engine, seat, wheels and other objects.

Another Example
Consider two classes Student and Address. Each student has own address that makes has-a relationship, but the address has student not makes any sense. We can understand it more clearly using Java code.
Class Address{ int street_no; String city; String state; int pin; Address(int street_no, String city, String state, int pin ){ this.street_no = street_no; this.city = city; this.state = state; this.pin = pin; } } class Student { String name; Address ad; }
In the above code, we can see Student class has-a relationship with Address class. We have drawn an image too to demonstrate relationship between these two classes.

The Student class has an instance variable of type Address. As we have a variable of type Address in the Student class, it can use Address reference, which is ad, in this case, to invoke methods of the Address class.
Advantage of Aggregation
The main advantage of using aggregation is to maintain code re-usability. If an entity has a relationship with some other entity than it can reuse code just by referring that.
Aggregation Example
class Author { String authorName; int age; String place; // Author class constructor Author(String name, int age, String place) { this.authorName = name; this.age = age; this.place = place; } } class Book { String name; int price; // author details Author auther; Book(String n, int p, Author auther) { this.name = n; this.price = p; this.auther = auther; } public static void main(String[] args) { Author auther = new Author("Manish", 42, "INDIA"); Book b = new Book("Ducat Tutorial", 500, auther); System.out.println("Book Name: "+b.name); System.out.println("Book Price: "+b.price); System.out.println("------------Auther Details----------"); System.out.println("Auther Name: "+b.auther.authorName); System.out.println("Auther Age: "+b.auther.age); System.out.println("Auther place: "+b.auther.place); } }
Output
Book Name: Ducat Tutorial
Book Price: 500
------------Author Details----------
Auther Name: Manish
Auther Age: 42
Auther place: INDIA
Example2
Now take another example to understand aggregation. Suppose we have one more class Publisher then the Book class can reuse Publisher class details by just using its reference as Author class.
class Publisher{ String name; String publisherID; String city; Publisher(String name, String publisherID, String city) { this.name = name; this.publisherID = publisherID; this.city = city; } } class Author { String authorName; int age; String place; // Author class constructor Author(String name, int age, String place) { this.authorName = name; this.age = age; this.place = place; } } class Book { String name; int price; // author details Author auther; Publisher publisher; Book(String n, int p, Author auther, Publisher publisher ) { this.name = n; this.price = p; this.auther = auther; this.publisher = publisher; } public static void main(String[] args) { Author auther = new Author("Manish", 42, "INDIA"); Publisher publisher = new Publisher("Sun Publication","WSHO-III9","NOIDA"); Book b = new Book("Ducat Tutorial", 500, auther, publisher); System.out.println("Book Name: "+b.name); System.out.println("Book Price: "+b.price); System.out.println("------------Author Details----------"); System.out.println("Auther Name: "+b.auther.authorName); System.out.println("Auther Age: "+b.auther.age); System.out.println("Auther place: "+b.auther.place); System.out.println("------------Publisher Details-------"); System.out.println("Publisher Name: "+b.publisher.name); System.out.println("Publisher ID: "+b.publisher.publisherID); System.out.println("Publisher City: "+b.publisher.city); } }
Output
Book Name: Ducat Tutorial
Book Price: 500
------------Author Details----------
Auther Name: Manish
Auther Age: 42
Auther place: INDIA
------------Publisher Details-------
Publisher Name: Sun Publication
Publisher ID: WSHO-III9
Publisher City: NOIDA
Apply now for Advanced Java Training Course