

{"id":14998,"date":"2018-05-17T06:00:55","date_gmt":"2018-05-17T06:00:55","guid":{"rendered":"https:\/\/data-flair.training\/blogs\/?p=14998"},"modified":"2026-05-22T18:02:19","modified_gmt":"2026-05-22T12:32:19","slug":"association-in-java","status":"publish","type":"post","link":"https:\/\/data-flair.training\/blogs\/association-in-java\/","title":{"rendered":"Association In Java &#8211; Explore the Concepts of Composition &amp; Aggregation"},"content":{"rendered":"<p><span style=\"font-weight: 400\"><em>Association in Java is a connection between two separate classes that is set up through their objects.<\/em> Although Java association can balance one-to-one, one-to-many, and many-to-many relationships. It defines the multiplicity between objects.<\/span><\/p>\n<p><strong>There are two types of associations in Java<\/strong><\/p>\n<p><strong>1. Aggregation<\/strong><\/p>\n<p><strong>2. Composition<\/strong><\/p>\n<p>We will discuss in the tutorial with examples. So, let&#8217;s start the journey!<\/p>\n<h3>Association in Java<\/h3>\n<p>The association relationship indicates that a class knows about another class. It can be described as a &#8220;has-a&#8221; relationship between classes. The relationship between the classes can be bi-directional.<\/p>\n<p>For example, if we talk about the association between a teacher and a student, multiple students can associate with a single teacher, and a single student is also associated with multiple teachers, but both can be created or deleted independently. So, when a teacher leaves the school, we don\u2019t need to remove any students, and when a student leaves the school, we don\u2019t need to remove any teachers.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-67616 size-full\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/05\/Association-in-Java-1.png\" alt=\"Association in Java \" width=\"392\" height=\"133\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/05\/Association-in-Java-1.png 392w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/05\/Association-in-Java-1-150x51.png 150w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/05\/Association-in-Java-1-300x102.png 300w\" sizes=\"auto, (max-width: 392px) 100vw, 392px\" \/><\/p>\n<p>So, in the above example, the teacher has many students and vice versa, connected to various objects. Thus, we can say <em>the association in Java follows a many-to-many relationship.<\/em><\/p>\n<p><strong>Benefits of association in Java:<\/strong><\/p>\n<ul>\n<li>It maps the relation between the objects of two classes.<\/li>\n<li>Relating the objects to each other helps in driving the new information.<\/li>\n<li>Whenever there is a need to change the object, we can apply dependency while establishing a relation. And when the need for the object to remain independent arises, it also allows for mapping the relation without affecting it.<\/li>\n<\/ul>\n<p><strong>Java Association\u00a0 Example \u2013<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">package com.dataflair.association;\r\nclass Teacher\r\n{\r\n  private String name;\r\n  Teacher(String name)\r\n  {\r\n    this.name = name;\r\n  }\r\n  public String getTeacherName()\r\n  {\r\n    return this.name;\r\n  }\r\n}\r\nclass Student\r\n{\r\n  private String name;\r\n  Student(String name)\r\n  {\r\n    this.name = name;\r\n  }\r\n  public String getStudentName()\r\n  {\r\n    return this.name;\r\n  }\r\n}\r\nclass AssociationDemo\r\n{\r\n  public static void main (String[] args)\r\n  {\r\n    Teacher teacherObj = new Teacher(\"Rahul Sir\");\r\n    Student studentObj = new Student(\"Renuka\");\r\n    System.out.println(studentObj.getStudentName() +\r\n        \" is Student of \" + teacherObj.getTeacherName());\r\n  }\r\n}\r\n\r\n<\/pre>\n<p><strong>Output-<\/strong><\/p>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/05\/Association-example.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-67626\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/05\/Association-example.jpg\" alt=\"Association-example in Java\" width=\"1306\" height=\"745\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/05\/Association-example.jpg 1306w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/05\/Association-example-150x86.jpg 150w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/05\/Association-example-300x171.jpg 300w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/05\/Association-example-768x438.jpg 768w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/05\/Association-example-1024x584.jpg 1024w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/05\/Association-example-520x297.jpg 520w\" sizes=\"auto, (max-width: 1306px) 100vw, 1306px\" \/><\/a><\/p>\n<h3>Types of Association in Java<\/h3>\n<p>There are two types of association in Java<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-67624 size-full\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/05\/Types-of-Association.png\" alt=\"Types of Association in Java\" width=\"485\" height=\"191\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/05\/Types-of-Association.png 485w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/05\/Types-of-Association-150x59.png 150w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/05\/Types-of-Association-300x118.png 300w\" sizes=\"auto, (max-width: 485px) 100vw, 485px\" \/><\/p>\n<p>&nbsp;<\/p>\n<h3>Aggregation in Java<\/h3>\n<p><span style=\"font-weight: 400\">Now, Aggregation in Java is a special type of association. It has the following characteristics \u2013<\/span><\/p>\n<ul>\n<li style=\"font-weight: 400\"><span style=\"font-weight: 400\">It represents the Has-A relationship.<\/span><\/li>\n<li style=\"font-weight: 400\">Aggregation in Java follows a one-way or one-to-one relationship.<\/li>\n<li style=\"font-weight: 400\"><span style=\"font-weight: 400\">Ending one entity won\u2019t affect another; both can be present independently.<\/span><\/li>\n<\/ul>\n<p>Let\u2019s take the example of a mobile phone and a battery. A single battery can belong to a mobile phone, but if the mobile phone stops working, we delete it from our database. The phone battery will not be deleted because it may still be functional. So in aggregation, while there is ownership, objects have their own lifecycle.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-67849 size-full\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/05\/Example-of-Aggregation-in-Java1.png\" alt=\"Java Aggregation with example\" width=\"678\" height=\"332\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/05\/Example-of-Aggregation-in-Java1.png 678w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/05\/Example-of-Aggregation-in-Java1-150x73.png 150w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/05\/Example-of-Aggregation-in-Java1-300x147.png 300w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/05\/Example-of-Aggregation-in-Java1-520x255.png 520w\" sizes=\"auto, (max-width: 678px) 100vw, 678px\" \/><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">package com.dataflair.association;\r\n\r\nclass Employees\r\n{\r\n  String name;\r\n  int id ;\r\n  String dept;\r\n  Employees(String name, int id, String dept)\r\n  {\r\n    this.name = name;\r\n    this.id = id;\r\n    this.dept = dept;\r\n    System.out.println(\"Employee name is \"+name+\" Id is \"+id+\" Department is \"+dept);\r\n  }\r\n}\r\nclass Department\r\n{\r\n  String name, employees;\r\n  Department(String name, String employees)\r\n  {\r\n    this.name = name;\r\n    this.employees = employees;\r\n  }\r\n\r\n}\r\nclass Organization\r\n{\r\n  String officeName,departments;\r\n  Organization(String officeName, String departments)\r\n  {\r\n    this.officeName = officeName;\r\n    this.departments = departments;\r\n  }\r\n\r\n}\r\n\r\npublic class AggregationDemo{\r\n  public static void main (String[] args)\r\n  {\r\n    Employees s1 = new Employees(\"Mia\", 1, \"Sales\");\r\n    Employees s2 = new Employees(\"Priya\", 2, \"Marketing\");\r\n    Employees s3 = new Employees(\"John\", 1, \"IT\");\r\n    Employees s4 = new Employees(\"Rahul\", 2, \"Designing\");\r\n  }\r\n}\r\n<\/pre>\n<p><strong>Output-<\/strong><br \/>\n<a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/05\/Aggregation-example.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-67628\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/05\/Aggregation-example.png\" alt=\"Aggregation-example in Java\" width=\"1306\" height=\"745\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/05\/Aggregation-example.png 1306w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/05\/Aggregation-example-150x86.png 150w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/05\/Aggregation-example-300x171.png 300w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/05\/Aggregation-example-768x438.png 768w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/05\/Aggregation-example-1024x584.png 1024w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/05\/Aggregation-example-520x297.png 520w\" sizes=\"auto, (max-width: 1306px) 100vw, 1306px\" \/><\/a><\/p>\n<p><span style=\"font-weight: 400\">So, in this case, there is an organization that has a number of offices. Each office has a number of Departments. In this way, we influence an Organization to the class, which has a reference to an object or some Objects (i.e., Rundown of Objects) of the Department class. That implies the Organization class is related to the Department class through its Object(s). What&#8217;s more, the Department class has a reference to Object or Objects (i.e., Rundown of Objects) of the Employees class, likewise implying it is related to the Employees class through its Object(s). It speaks to a <em>Has-A relationship<\/em>.<strong>\u00a0<\/strong>Code rescue can be best achieved by Aggregation in Java.<\/span><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/05\/Organization.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-67644 size-full\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/05\/Organization.png\" alt=\"Organization Example\" width=\"495\" height=\"296\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/05\/Organization.png 495w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/05\/Organization-150x90.png 150w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/05\/Organization-300x179.png 300w\" sizes=\"auto, (max-width: 495px) 100vw, 495px\" \/><\/a><\/p>\n<h3>Composition in Java<\/h3>\n<p><span style=\"font-weight: 400\">This is a restricted form of Java aggregation where the quantities are highly dependent on each other. It represents a part-of relationship. One entity cannot exist without the other. <em><strong>Composition in Java represents a one-to-many relationship.<\/strong><\/em><\/span><\/p>\n<p>Suppose if we take an example of the relationship between questions and answers. Single questions can have multiple answers, but multiple answers can not have multiple questions. If we delete questions, answers will automatically be deleted. In this, the entities are dependent.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-67850 size-full\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/05\/Example-of-Composition-in-Java1.png\" alt=\"Java Composition with example\" width=\"591\" height=\"291\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/05\/Example-of-Composition-in-Java1.png 591w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/05\/Example-of-Composition-in-Java1-150x74.png 150w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/05\/Example-of-Composition-in-Java1-300x148.png 300w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/05\/Example-of-Composition-in-Java1-520x256.png 520w\" sizes=\"auto, (max-width: 591px) 100vw, 591px\" \/><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">package com.dataflair.association;\r\n\r\nimport java.util.*;\r\nclass Book\r\n{\r\n  public String title;\r\n  public String author;\r\n  Book(String title, String author)\r\n  {\r\n    this.title = title;\r\n    this.author = author;\r\n  }\r\n}\r\nclass Library\r\n{\r\n  private final List&lt;Book&gt; books;\r\n  Library (List&lt;Book&gt; books)\r\n  {\r\n    this.books = books;\r\n  }\r\n  public List&lt;Book&gt; getTotalBooksInLibrary(){\r\n    return books;\r\n  }\r\n}\r\npublic class CompositionDemo {\r\n\r\n  public static void main (String[] args)\r\n  {\r\n    Book bookObj1 = new Book(\"Java:A Beginner's Guide\",\"Herbert Schildt\");\r\n    Book bookObj2 = new Book(\"Core and Advanced Java\", \" Dreamtech Press\");\r\n    Book bookObj3 = new Book(\"Head First Java\", \"Kathy Sierra\");\r\n    List&lt;Book&gt; books = new ArrayList&lt;Book&gt;();\r\n    books.add(bookObj1);\r\n    books.add(bookObj2);\r\n    books.add(bookObj3);\r\n    Library library = new Library(books);\r\n    List&lt;Book&gt; bks = library.getTotalBooksInLibrary();\r\n    for(Book bk : bks){\r\n      System.out.println(\"Title : \" + bk.title + \" and \"\r\n          +\" Author : \" + bk.author);\r\n    }\r\n  }\r\n}\r\n<\/pre>\n<p><strong>Output-<\/strong><\/p>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/05\/Composition-program.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-67633\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/05\/Composition-program.png\" alt=\"Composition-program in Java\" width=\"1306\" height=\"748\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/05\/Composition-program.png 1306w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/05\/Composition-program-150x86.png 150w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/05\/Composition-program-300x172.png 300w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/05\/Composition-program-768x440.png 768w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/05\/Composition-program-1024x586.png 1024w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/05\/Composition-program-520x298.png 520w\" sizes=\"auto, (max-width: 1306px) 100vw, 1306px\" \/><\/a><\/p>\n<h3>Choosing Between Aggregation and Composition in Java<\/h3>\n<p>While both aggregation and composition represent &#8220;has-a&#8221; relationships between objects, understanding the key differences is crucial for effective code design. Here&#8217;s a helpful guideline:<\/p>\n<ul>\n<li>Use aggregation when the objects can exist independently. In the example of a mobile phone and battery, the phone can function without a battery (albeit temporarily), and the battery could potentially be used in another device. In such scenarios, aggregation is suitable as objects have their own life cycles.<\/li>\n<li>Use composition when the parts have a strong dependency on the whole. Consider a car engine. The engine&#8217;s parts ( pistons, valves, crankshaft) are intrinsically linked to the engine&#8217;s functionality and wouldn&#8217;t exist independently. When destroying the car, the engine and its parts are typically disposed of together. In these cases, composition is more appropriate as the parts rely on the whole object for their existence.<\/li>\n<li><span style=\"font-weight: 400\">Well, it depends on the requirements of the applications when it comes to choosing between the two. The use of Aggregation and composition will rely on the state and the structure of the application. <\/span><\/li>\n<\/ul>\n<h3>Summary<\/h3>\n<p>In conclusion, we can say<\/p>\n<ol>\n<li>Association follows many-to-many relationships.<\/li>\n<li>Aggregation follows a one-to-one relationship.<\/li>\n<li>The Composition follows a one-to-many relationship.<\/li>\n<\/ol>\n<p>Now, you can apply any one of the above relationships with the help of examples. Hope you liked the explanation.<\/p>\n<p>Drop your suggestion and feedback in the comment section.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Association in Java is a connection between two separate classes that is set up through their objects. Although Java association can balance one-to-one, one-to-many, and many-to-many relationships. It defines the multiplicity between objects. There&#46;&#46;&#46;<\/p>\n","protected":false},"author":5,"featured_media":67848,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[32],"tags":[20863,20862,20864,20860,20859,20861],"class_list":["post-14998","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-java","tag-aggregation-in-java-with-example","tag-association-in-java-with-example","tag-composition-in-java-with-example","tag-java-aggregation","tag-java-association-tutorial","tag-java-composition"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.4 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Association In Java - Explore the Concepts of Composition &amp; Aggregation - DataFlair<\/title>\n<meta name=\"description\" content=\"Java association balances one-to-one, one-to-many, and many-to-many relationships. Learn more about the Java association.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/data-flair.training\/blogs\/association-in-java\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Association In Java - Explore the Concepts of Composition &amp; Aggregation - DataFlair\" \/>\n<meta property=\"og:description\" content=\"Java association balances one-to-one, one-to-many, and many-to-many relationships. Learn more about the Java association.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/data-flair.training\/blogs\/association-in-java\/\" \/>\n<meta property=\"og:site_name\" content=\"DataFlair\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/DataFlairWS\/\" \/>\n<meta property=\"article:published_time\" content=\"2018-05-17T06:00:55+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2026-05-22T12:32:19+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/05\/Types-of-association-in-java.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"802\" \/>\n\t<meta property=\"og:image:height\" content=\"420\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"DataFlair Team\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@DataFlairWS\" \/>\n<meta name=\"twitter:site\" content=\"@DataFlairWS\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"DataFlair Team\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"6 minutes\" \/>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Association In Java - Explore the Concepts of Composition &amp; Aggregation - DataFlair","description":"Java association balances one-to-one, one-to-many, and many-to-many relationships. Learn more about the Java association.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/data-flair.training\/blogs\/association-in-java\/","og_locale":"en_US","og_type":"article","og_title":"Association In Java - Explore the Concepts of Composition &amp; Aggregation - DataFlair","og_description":"Java association balances one-to-one, one-to-many, and many-to-many relationships. Learn more about the Java association.","og_url":"https:\/\/data-flair.training\/blogs\/association-in-java\/","og_site_name":"DataFlair","article_publisher":"https:\/\/www.facebook.com\/DataFlairWS\/","article_published_time":"2018-05-17T06:00:55+00:00","article_modified_time":"2026-05-22T12:32:19+00:00","og_image":[{"width":802,"height":420,"url":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/05\/Types-of-association-in-java.jpg","type":"image\/jpeg"}],"author":"DataFlair Team","twitter_card":"summary_large_image","twitter_creator":"@DataFlairWS","twitter_site":"@DataFlairWS","twitter_misc":{"Written by":"DataFlair Team","Est. reading time":"6 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/data-flair.training\/blogs\/association-in-java\/#article","isPartOf":{"@id":"https:\/\/data-flair.training\/blogs\/association-in-java\/"},"author":{"name":"DataFlair Team","@id":"https:\/\/data-flair.training\/blogs\/#\/schema\/person\/7f83c342f5d1632d6f7b4b0b0f447823"},"headline":"Association In Java &#8211; Explore the Concepts of Composition &amp; Aggregation","datePublished":"2018-05-17T06:00:55+00:00","dateModified":"2026-05-22T12:32:19+00:00","mainEntityOfPage":{"@id":"https:\/\/data-flair.training\/blogs\/association-in-java\/"},"wordCount":817,"commentCount":3,"publisher":{"@id":"https:\/\/data-flair.training\/blogs\/#organization"},"image":{"@id":"https:\/\/data-flair.training\/blogs\/association-in-java\/#primaryimage"},"thumbnailUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/05\/Types-of-association-in-java.jpg","keywords":["Aggregation in Java with example","Association in Java with example","Composition in Java with example","Java Aggregation","Java Association tutorial","Java Composition"],"articleSection":["Java Tutorials"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/data-flair.training\/blogs\/association-in-java\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/data-flair.training\/blogs\/association-in-java\/","url":"https:\/\/data-flair.training\/blogs\/association-in-java\/","name":"Association In Java - Explore the Concepts of Composition &amp; Aggregation - DataFlair","isPartOf":{"@id":"https:\/\/data-flair.training\/blogs\/#website"},"primaryImageOfPage":{"@id":"https:\/\/data-flair.training\/blogs\/association-in-java\/#primaryimage"},"image":{"@id":"https:\/\/data-flair.training\/blogs\/association-in-java\/#primaryimage"},"thumbnailUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/05\/Types-of-association-in-java.jpg","datePublished":"2018-05-17T06:00:55+00:00","dateModified":"2026-05-22T12:32:19+00:00","description":"Java association balances one-to-one, one-to-many, and many-to-many relationships. Learn more about the Java association.","breadcrumb":{"@id":"https:\/\/data-flair.training\/blogs\/association-in-java\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/data-flair.training\/blogs\/association-in-java\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/data-flair.training\/blogs\/association-in-java\/#primaryimage","url":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/05\/Types-of-association-in-java.jpg","contentUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/05\/Types-of-association-in-java.jpg","width":802,"height":420,"caption":"Java Association Tutorial"},{"@type":"BreadcrumbList","@id":"https:\/\/data-flair.training\/blogs\/association-in-java\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Blog Home","item":"https:\/\/data-flair.training\/blogs\/"},{"@type":"ListItem","position":2,"name":"Java Tutorials","item":"https:\/\/data-flair.training\/blogs\/category\/java\/"},{"@type":"ListItem","position":3,"name":"Association In Java &#8211; Explore the Concepts of Composition &amp; Aggregation"}]},{"@type":"WebSite","@id":"https:\/\/data-flair.training\/blogs\/#website","url":"https:\/\/data-flair.training\/blogs\/","name":"DataFlair","description":"Learn Today. Lead Tomorrow.","publisher":{"@id":"https:\/\/data-flair.training\/blogs\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/data-flair.training\/blogs\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/data-flair.training\/blogs\/#organization","name":"DataFlair","url":"https:\/\/data-flair.training\/blogs\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/data-flair.training\/blogs\/#\/schema\/logo\/image\/","url":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2016\/07\/Data-Flair.png","contentUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2016\/07\/Data-Flair.png","width":106,"height":48,"caption":"DataFlair"},"image":{"@id":"https:\/\/data-flair.training\/blogs\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/DataFlairWS\/","https:\/\/x.com\/DataFlairWS","https:\/\/www.linkedin.com\/company\/dataflair-web-services-pvt-ltd\/","https:\/\/www.youtube.com\/user\/DataFlairWS"]},{"@type":"Person","@id":"https:\/\/data-flair.training\/blogs\/#\/schema\/person\/7f83c342f5d1632d6f7b4b0b0f447823","name":"DataFlair Team","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/4cf3a74600d131330b8c481d519afd1574093ed89f6d3396a95393ad223eb7cd?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/4cf3a74600d131330b8c481d519afd1574093ed89f6d3396a95393ad223eb7cd?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/4cf3a74600d131330b8c481d519afd1574093ed89f6d3396a95393ad223eb7cd?s=96&d=mm&r=g","caption":"DataFlair Team"},"description":"DataFlair Team creates expert-level guides on programming, Java, Python, C++, DSA, AI, ML, data Science, Android, Flutter, MERN, Web Development, and technology. Our goal is to empower learners with easy-to-understand content. Explore our resources for career growth and practical learning.","url":"https:\/\/data-flair.training\/blogs\/author\/dfteam1\/"}]}},"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts\/14998","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/users\/5"}],"replies":[{"embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/comments?post=14998"}],"version-history":[{"count":19,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts\/14998\/revisions"}],"predecessor-version":[{"id":148424,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts\/14998\/revisions\/148424"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/media\/67848"}],"wp:attachment":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/media?parent=14998"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/categories?post=14998"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/tags?post=14998"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}