In the previous posts we saw the basics of Object Oriented Programming , and Demo Java Programs.Now its the time to dive up into the Java Language Basics.Java language basic means the whole theory wound up around the object,so lets start with the objects and variables.


Object Instantiation
An object as quoted in my early posts is a real world run time entity.It can also be defined as an instance of a class.


In easy words instantiation is not but creation or representation.So,we will see just how to create an object.By creating an object you can access the members and methods of a class.


We generally create an object for a class say Sample,then the object is represented as : 
                                   
              Syntax : ClassName <reference variable> = new Constructor;                            


              Example : Sample s  = new Sample( );


Here Sample is the class-name , s is the reference variable and Sample() is the constructor
Constructor is defined as the block of code which is initialised whenever an object is created.


So,what actually happens when you create an object.If you observe carefuly we are using a dynamic memory allocation operator known as new here which allocates the memory for the created object.Here we will store all the member variables and the method values.


If we create multiple instances for a class we give different reference variables while instantiating.


           Example : Sample s1 = new Sample();


Accessing the members of the class by using an object


Now, we created the object.We should know what to do with the object and how to access the members by using the object.


We can access members of a class by using an object by using the DoT operator( . ).


             Syntax : <reference-variable>.classVariable;
                         <reference-variable>.classMethod();
  
             Example : s.width;
                            s1.width;
             Example : s.myMethod();
                            s1.myMethod();


Tokens


Tokens are the smallest elements in the Java program.These tokens are determined into several types.We will take a brief look over the list.So, they are : 



  1. Identifiers : Any names which are provided by the user.In Java identifier can be of infinite-length. In th declaration int a , b, c; (a,b,c) are identifiers.
  2. Keywords : Java provides 60 keywords,which are used while programming.We will come to know as we dig deep into the Java Language.
  3. Literals : These are the elements used frequently in the program.They can be divided as Numeric Literals and Character Literals(Boolean Literals).We will see this Literals once we cover the last token Datatypes.
  4. Operators : These are the elements which are specially used for the evaluations of the variables.Java supports wide range of Operators.
  5. Seperators : These are used to end ,interept or join two statements in Java.In simple words,it will inform the Java compiler how to group the statements and the code(If you want more detail explanation,better go and refer Compiler Design( :P ) ).
  6. White Spaces : Not very tough to understand isn't it?
  7. Data Types : These are the stroage structures of the variables.Every variable is associated with a Datatype in Java.
             There are mainly 2 types of Data types.They are :
  • Primitive or Non Reference Datatypes :byte,short,char,boolean,float,int,double,long( ordered in ascending and alphabetical order)
  • Reference Datatypes : Class type, Interface type,Array type,String Type.
                  We will deal with this in depth and detail when we are discussing the variables.i.e;in the next post.Stay tuned till then! Au Revoir!!