Tuesday, 27 June 2023

Colection & Collections

What do you think Collection & Collections are same?

Answer is No Collection & Collections are not same.

Here we discussed how Collection & Collections are Difference.

Collection
  • Collection is Interface.
  • If we want to represent a group of individual object as a single entity than, we should go for Collection.
Collections
  • Collections is a class.
  • Collections is an Utility class present in Java.util  package to define several methods for Collection Objects.
  • For eg:- Sorting, Searching etc.
What is Collection Framework ?
  • It contains several classes & interfaces which can be used to represent a group of individual object as a single entity.
  • 9 Key Interface of Collection Framework.
  1. Collection
  2. List
  3. Set
  4. Sorted Set
  5. Navigable Set
  6. Queue
  7. Map
  8. Sorted Map
  9. Navigable Map
1.Collection (Interface)
  • If we want to represent a group of individual object as a single entity than we should go for Collection.
  • Collection Interface defines the most common methods which are applicable for any collection.
  • In general Collection Interface considered as Root Interface Collection Framework.
  • There is no Concrete class which implements collection directly.


2. List (Interface)
  • It is the Child Interface of Collection.
  • If you want to represent a group of individual Objects as a Single entity where, Duplication are allowed & Insertion order must be preserved than we should go for List(Interface).
  • Duplication are allowed.
  • Insertion Order must be Preserved


3. Set (Interface)
  • It is the Child Interface of Collection.
  • If you want to represent a group of individual Objects as a Single entity where, Duplication are not allowed & Insertion Order not required than we should go for Set(Interface).
  • Duplication are Not allowed.
  • Insertion order Not required.


4. Sorted Set(Interface)
  • It is the child Interface of Set(Interface).
  • If you want to represent a group of individual object as a Single entity where, Duplication are Not allowed Object should be Inserted according to some Sorting order than we should go for Sorted Set.
  • Duplication are Not allowed.
  • Object should be Inserted (Insertion & Sorting Order) are allowed.
5. Navigable Set(Interface)
  • It is the Child Interface of Sorted Set(Interface).
  • It Contains several methods for Navigable purpose.
6. Queue(Interface)
  • It is child Interface of Collection.
  • If we want to represent a group of individual objects Prior to Processing than, we should go for Queue.
  • Usually Queue follows FIFO(First In First Out) but based on Requirement we can implement our own Priority order also.
  • For eg:- 
  • Before Sending a Mail, all mail Id's we have to share in some data structure.
  • In which order we added Mail Id's in the some order only mail should be delivered.



Note:-
  • All the above Interface[Collection, List, Queue, Set, Sorted Set, Navigable Set] meant for representing a group of individual Objects.
  • If we want to represent a group of object as Key-Value-Pair than, we should go for Map.
7.  Map(Interface)
  • Map is Not Child interface of Collection.
  • Represent as a Key-value-Pair.
  • Both Key & Value are Object Only.
  • Duplicate keys are Not allowed but values can be Duplicated.
  • for eg:-




8. Sorted Map(Interface)
  • It is Child interface of Map.
  • If we want to represent a group of Key-Value-Pairs according to some Sorting order of keys than, we should go for sorted Map.
  • In sorted Map the Sorting should be based on Key but not based on  value.
9. Navigable Map(Interface)
  • It is the Child Interface of Sorted Map.
  • It defines several methods for Navigation purpose.
Note:- Following Legacy Character are present in Collection Framework.
  • Enumeration(Interface)
  • Dictionary(AC)
  • Vector(Class
  • HashTable(Class)
  • Properties(Class)
  • Stack(Interface)
What is the need of Cursor in Collection?
  • A group of individual object, we want get these object one by one from the collection than we will go for Cursor concept.
Three type of Cursor are present in Collection.
  • Enumeration(Interface)
  • Iterator(Interface)
  • ListIterator(Interface)
In Collection Two Utility Classes
  • Araays
  • Collections


Thursday, 22 June 2023

Collection (What is the need of Collection & What is difference B/w Array & Collection)

 What is Collection?

It is a group of individual object as a single entity.

  • It provides readymade architecture.
  • It represents a set of classes and interfaces.
  • It is optional.

for eg:-


As we know that collection are arrays somehow, same but 
sometime why we don't use arrays why use collection than, let discussed about that why these are different from each other?

What is Array?

An array is an indexed collection of Fixed Number of Homogeneous data element.

What is the Main advantage of Array?

.we can represent multiple values by using single variable so, Readability of the code will be improved.

What is the Limitations of Arrays?

1.Arrays are fixed in size. Once we create an array there is no chance of increasing or decreasing the size based on our requirement, due to this to use array concept compulsory we should know the size in advance which may not possible.

2.Array can hold only Homogeneous data type elements.

Suppose, I have took Student Array

Student[]s=new Student[10];

Here, only Student type of object we can hold.

s[0]=new Student(); Valid

s[1]=new Customer(); Not Valid

But now we have question than How to resolve this problem?

We have solve this problem only by using Array.

.Any type of Object hold by requirement

.Go for Object Array

object[]a=new object[12];

a[0]=new Student();  Valid

a[1]=new Customer(); Valid

3.Arrays concept not implemented based on some standard data structure hence, Readymade method support is not available for every requirement, we have o write code explicitly which increase complexity of programming.

To overcome these problem we should go for Collection concept.

The Main Advantage of Collection

1.Collection are Growable in nature[Not Fixed in Size] that is based on our requirement, we can increase or decrease the Size.

2.Collection can hold both Homogeneous and Heterogeneous element.

3.Every Collection class implemented based on some standard data structure hence, Readymade method support is available for every requirement, being a programmer we are responsible to use those methods.

What is the difference between Array & Collection?




Thursday, 1 June 2023

AEM Dialog v/s Design Dialog

Before knowing about Dialog or Design Dialog. Let us understand about   AEM  Component. A component is a basic building block of a template.

Basic uses of Component is to hold, format, and render the content made available on your webpages. When authoring pages, the components allow the authors to edit and configure the content.

Content can be  of two types:

1.Page Specific (in this case component dialog is used)

2.Design/Global(in this case design dialog is used)

If we talk about (Page Specific or component dialog) the question can you think of component without dialog can you reuse your component without dialog?

so, the answer is No, without  component dialog AEM component is just a piece of code which you cannot reuse on multiple pages so it is most important part of component.

How to create component dialog?

Before create component dialog let us know about sling super type and sling resource super type  property. These property play important role in AEM.

so, we create a node and the structure of node is:







In AEM there are two type of or fields available 

1.Foundation 

 



2.Coral Foundation




Nowadays, both are working but as of now we use coral foundation

Role of Load Dialog Specific ClientLibs

Whatever, the script you will be writing if you are writing script in jQuery, JavaScript inside a client Library that's the only standard way to write.



this is the additional property called extra Client Libs and we will add this as a dialog. In this case if we load client library in this way this client library will load only for the dialog and when the dialog is open.

To show you dialog I created the component


 

First let's see the dialog so if I open I added there is a dialog open here.






Here is one drop-down, in grey screen these are container than first Name and Last name hold Textfields. Now we see node structure how to created this dialog and sling resource type.




Here, the resource type is sling:resourceType it means
.locate the resource to be used for rendering.

Now, we see node structure how to created this dialog and sling resource super type.








Here, the resource type is sling:resourceType it means:-
.locate the resource to be used for rendering.


Now we talk about Design/Global(in this case design dialog is used.

What is Design Dialog?

It is dialog which allows to store content/configuration that can be exist across pages. so, it is used when we require component whose content or configuration should be same throughout the application and which are created using same template.
Changes will get reflected across all the pages created using the same template.

How to create Design Dialog? 

  • Login to CRXDE.
  • Go to /apps/<project-name>/<path to component> [For Ex:- /apps/training/components/structure/trainingPage ]
  • Right Click on your component and select –> Create –> Create Dialog
  • Rename Label from dialog to design_dialog . [Note:- Label should be design_dialog only]
  • Expand the design_dialog node


  • Rename Label from dialog to design_dialog . [Note:- Label should be design_dialog only]
  • Expand the design_dialog node.


  • Expand design_dialog node and select Tab 1 node.(I will describe what is the use of which node and why we have created)
  • Right click on Tab 1 node. From menu select Create –> Create Node 
    • Name:- items (Name of node should be items only. Its is mandatory)
    • Type:- cq:WidgetCollection

Select items node. From menu select Create –> Create Node 
  • Name:- customTitle (It is adviced to have name in lower case)
  • Type:- cq:Widget

  • Add below jcr properties to customTitle node.
  • Name:- name           Type:-  String  Value:- ./title
  • Name:- xtype           Type:-  String   Value:- textfield
  • Name:- fieldLabel   Type:-  String   Value:- Enter Title
  • Now if we have a look on our design dialog, it should look like below:-


Author Design Dialog in AEM


Now lets see how content authors can make use of this design dialog and author it on page.

  • Go to site admin.
  • Open your existing page or create a new page.
  • From side kick navigate to design mode.
    • Now Lets add selection drop down field to this dialog
    • Select widget collection node(items) above full name. Right click and Create Node.
      • Name: country_list (Name of the Node/Widget)
      • Type: cq:Widget (It can be any type of widget depending upon which xtype we will use)
      • Save All.
      • Add xtype = selection in order to behave this node as selection node.Note:- Selection xtype have further sub-types like select (dropdown), combobox (select plus free text entry), checkboxes and radio buttons.
      • Add type : select  for creating a dropdown.
      • Add fieldLabel : This will be displayed as a label before the field.
      • Add name : This(./country) should be unique name to get user value from dialog to jsp. All fields in a component should have a unique value of name property.

Now lets create the dropdown options.

  • Select country_list node, right click and Create Node
    • Name: options
    • Type: cq:WidgetCollection (It will hold option list)
    • Save All.
  • Select options node, right click and Create Node
    • Name: v1
    • type: cq:Widget
    • Save All.
    • Select v1 node and
      • Add text –  India (This text will be displayed in dropdown to users)
      • Add value – india(this is the value that is stored at jcr node)
    • Repeat above process  2 more times and create node v2 and v3.

  • Double click on dialog node.

What is the difference between dialog and design dialog in AEM?

.when we want the configurations/content to be page specific then we use dialog
. when we want the configurations/content to be page specific then we use design_dialog.

Servlet in AEM/Sling Servlet

  What is Servlet? A servlet is a Java class that runs on the server side where the application resides. It acts as a middle layer between t...