User Defined Data Types in Java

મિત્રો, આ Tutorial માં આપણે શીખીશું User defined data types, User defined data types in Java, User defined data types in Gujarati. આપણે અગાઉ ના Tutorial માં Primitive Data Types વિષે જોયું. હવે, તમે તેમાં Non-Primitive કરીને એક શબ્દ જોયો હશે. તો આજે આપણે એજ Concept શીખીશું ખૂબ જ સરળ રીતે.

User Defined Data Types in Java

Java માં 2 type ની data types છે:

1. Primitive data type

2. Non-primitive data type

આજે આપણે user defined data types જોઈશું.  

User defined data types in Java

User defined data types એ programming language દ્વારા define કરેલ નથી, પણ તે programmer દ્વારા create થાય છે.

આને nonprimitive data type પણ કહે છે.

આ પણ વાંચો – Primitive Data Types in Java

Java માં 4 Types ની user defined data type છે:

  1. Class
  2. Interface
  3. Array
  4. String

Class

  • Class એક keyword છે જેની મદદથી class data type declare કરી શકાય છે.
  • Class એ એક template છે જે things અથવા objects ના behavior અને attributes ને specify કરે છે.
  • Class એ prototype અથવા blueprint છે જેમાંથી જરૂરી હોય તેટલા desired objects બનાવી શકાય છે.
  • Class એ user દ્વારા define કરેલ prototype છે જેથી object બનાવવામાં આવે છે. આમાં methods અને variables હોય છે.
  • એક class એ objects નો સમૂહ હોય છે જેમાં એકસમાન properties હોય છે.
  • આ એક logical entity છે. તે physical નથી થઈ શકતી.
  • Class માં methods અને variables define કરવામાં આવે છે.
  • તમે class માં ઈચ્છો તેટલા objects અને methods બનાવી શકો છો.

Syntax:

class classname
{
       type variable1,variable2,….,variableN;
       type methodname(parameter-list)
       {
            //body of method
       }
}

Example:

class maricollge
{
     int i = 10;
     void display()
     {
         system.out.println("i="+i);
     }
}

Creating Object:

maricollge mc1 = new maricollge();

Interface

  • Interface એ abstract methods નું collection છે.
  • એક class interface ને implement કરે છે, ત્યાંથી interface ની abstract methods ને inherit કરે છે.
  • Class ની જેમ interface માં પણ methods અને variables હોય છે પરંતુ તેમાં declare કરેલ method abstract હોય છે.
  • Interface એ class નથી. Class એ object ના behaviour અને attributes ને describe કરે છે. Interface એ class જે behaviour ને implement માં મુકે તેને contain કરે છે.
  • જ્યાં સુધી interface ને implement કરતો class abstract ન હોય ત્યાં સુધી, interface ની બધી methods class માં define કરવી પડે.
  • Java માં interface નો reference type હોય છે અને તેની પાસે abstract methods અને static constants હોય છે.
  • javaમાં આનો ઉપયોગ abstraction અને inheritance ને મેળવવા માટે કરવામાં આવે છે.
  • Interface multiple inheritance ના concept ને support કરે છે.
  • આમાં એક થી વધારે interface ને implement કરી શકાય છે.
  • Interface એ એક predefine keyword છે.

Syntax:

interface interfacename
{
     type final-varname1 = value;
     type final-varname2 = value;
      ………….
     type final-varnameN = value;
     return-type methodname1(parameter-list);
     return-type methodname2(parameter-list);
     ………….
     return-type methodnameN(parameter-list);
}

Example:

interface maricollge
{
      void display(void);
}

Array

  • Array એક સમાન data type નું collection છે.
  • Array data type એકસમાન variables ને store કરે છે.
  • Array માં એક single variable માં એકસાથે ઘણી values ને store કરવામાં આવે છે.

Syntax:

type var_name[] = new type[size];

Example:

int a[] = new int[5];

String

  • String એ non primitive data type છે પણ જાવા માં તે predefined છે.
  • આ પણ એક class જ છે.
  • String character ની sequence ને represent અને store કરે છે.
  • String values ને double quote “” ની અંદર લખવામાં આવે છે.

Syntax:

String stringname = “value”;

Example:

String s1 = “maricollege”;

આ પણ વાંચો – Hello World in Java

આ પણ વાંચો – Java OOP Concepts – Basics of OOP

આ પણ વાંચો – Static Binding vs Dynamic Binding

આ પોસ્ટ જેમાં મિત્રો આપણે જોયું કે User defined data types, User defined data types in Java, and User defined data types in Gujarati.

જો મિત્રો તમને આ પોસ્ટ મદદરૂપ લાગી હોય, તો તમે તમારા મિત્રો સાથે ચોક્કસ શેર કરો અને જો તમને જાવા અથવા બીજા કોઈ વિષય સંબંધિત કોઈ પ્રશ્ન હોય તો તમે નીચે કોમેન્ટ કરીને અમને જણાવી શકો છો. આભાર.

Leave a Comment