Java4teachus

Tuesday, December 25, 2018

Types Of Data Members & Methods In a Class

In every java programming language , A class can containing  two types of Data Members .They are :

1.Non-static data members.

2.Static  data member.

Instance Data Member 


➢Instance data members memory space is created each every time whenever the object is created.

Instance data member are used for storing specific values which are suitable  for individuals.
➢Instance data member declaration should not be preceded by 'Static keyword' .
      Ex:- int a=10,20,30,40; (Instance Data Member) 
➢Datatype V 1 ,V 2,V 3........V n ;.
➢Each & every instance data member must be access with respect to Object name
     (Object . Instance Data Member Name)

➢Instance data member value are not shareable.
➢Instance data members are also called "Object level Data Members".Below following examples are the instance data type members.

 EX :  int student Id ;

       String course;
       String student name ;
       float marks;
Static-vs-non-Static-data-members.jpeg

Static Data Members 


➢ Static  data members memory space is created  once only when we defined the class then irrespective  number of times objects are created.

➢ Static date members  are used for storing  common values which are suitable for all programmers.
➢ Static data members declaration is must be preceded by "static keyboard "
➢ Static" data type V 1,V 2.......V n ;
➢ Each & every data member must be access to respect to object even with class name (obj. class).
➢ Static   data members are shareable
➢ Static data member are also called "class level data members ". Below following examples are the static data type members.

EX:  static string course ;  

         static string Delhi  ;
         static string pi ;
NOTE:-   Each every final variable must be static but a static variable  value may are  not be final .
       static final float PI= 3.14f ;
       static final String s="Java";

Tuesday, December 18, 2018

Different B/W the Class vs Object In JAVA

Hash code or hexadecimal code:

When we create an object  with new operator by referring internally for created java execution provides a unique numerical id called Hash code / hexa decimal format called hexa decimal code.

The purpose of hash code or hexa decimal code is always used for identifying the objects or provides identity object.

ClassLoaderSubSystem:

A ClassLoaderSubSystem is one of the java program available  as a part of java software and whose job role is to load the .class file from "Secondary Memory into Main Memory". without loading .class file name we cannot create a object.

Class :
  • A Class is collection of  'Data Members & Methods' .
  • The definition of  class does not contain memory space for  Data Members & Methods .
  • Class definition is always consider as  'Logical existence' .
  • When we execute the Java program the definition of class will be loaded once in the in the Main Memory  with the help of "ClassLoaderSubSystem" .
  • When we  write a java program the definition of a class will exists only once .
  • The definition of class resides in Secondary Memory in the form of  class name  .
Class-vs-Object-In-java.jpeg

Object :
  • Instance of a class is caned an  'Object'. 
  • Memory space is created for  Data Member & Methods  only when we create an object 
  • Object creation is always consider as 'physical existence'. 
  • After loading  class file name in the Main Memory  and later we can create the  object  .
  • With respect to one class definition we can create multiple objects 
  • Objects residing in   Main Memory.

Note 

  1. All "Objects " of java resides in the "Heap Memory". 
  2. All "Methods" of java resides & executes in "Stack Memory".
  3. All  "figurative constants"  values (directly used). resides in "Associatine memory" .
  4. All the above three memories are of the parts of "Main Memory" .

Wednesday, December 05, 2018

Definition Of Object & Create an Object in Java

Create an Object 

  • We know that when we define a class memory space is not created so that data members and method but whose memory is created when we create an  "Object".
  • In other word to enter for the data member of a class, first we must allocate memory space for data member by creating an"Object" .
  • To do any data processing we must create an "Object".
  • To create an object either must exist a class definition otherwise it is compile error.
Definition of object
  • Instance of a class is called an"Object" ( instance is nothing but allocating sufficient amount of memory space for "Data members & Method" ).
  • Each & every class variable is called an "Object".
  • Each & every grouped item is called "Object".  
  • (in grouped item is a variable which allows to store multiple value of same type or different type or both types.)
Creating an object in java
  • Creating an object in nothing but allocating the sufficient amount of memory space for data members and methods of a class. By following dynamic memory allocation with the help of new operator and it is called "dynamic memory allocation" operator.

New Operator In Java 

  • It  allocates  sufficient  amount of memory space for data member and method of specified  class.  
  • It takes an address / reference of created memory space and placing it into L.H.S variable i.e.   is  object  name.
  • Out  of  many  way  of creating an object in java with 'New Operator' .
  • We can create an object with two syntax's  they are:

Syntax:-1

<Class name>  <object> = new  <Class name > ----> 1

➽ create an object of Student class.
       
     Student  S= new Student( );


➽ Create an object of Circle class.

     Circle   C= new Circle( );

➽ Create an object of Employee Class.

     Employee e = new Employee( );


From the above examples we create an object by using the Class name called Employee or Programmer defined data type.

Here Employee is the 'programmer defined datatype' and 'e' is one of the 'reference variable or object' of Employee class. In Java by default reference variable contain 'Hash code / Hexa decimal code' which is very high security for applications.