This is default featured post 1 title

Go to Blogger edit html and find these sentences.Now replace these sentences with your own descriptions.

This is default featured post 2 title

Go to Blogger edit html and find these sentences.Now replace these sentences with your own descriptions.

This is default featured post 3 title

Go to Blogger edit html and find these sentences.Now replace these sentences with your own descriptions.

This is default featured post 4 title

Go to Blogger edit html and find these sentences.Now replace these sentences with your own descriptions.

This is default featured post 5 title

Go to Blogger edit html and find these sentences.Now replace these sentences with your own descriptions.

Tuesday 21 May 2013

Pointer Arithmetic


All types of arithmetic operations are impossible with a pointer. The only valid operations that can be performed are as-


1. Addition of integer to a pointer and increment operations.

2. Subtraction of an integer from a pointer and decrement operations.

3. Subtraction of a pointer from another pointer of same type
pointer arithmetic is somewhat different from ordinary arithmetic. Here all arithmetic is performed relative to the size of basic type of pointer.

For example, 

If we have an integer pointer pi which contains address 1000, then on incrementing we get 1004 instead of 1001. This is because the size of Pointer is Four depends on architecture.

Rules of the pointer Arithmetic

Rule1.

Address+Number=Address (next address)
Address-Number=Address (pre address)
Address++=Address (next address)
Address--=Address (pre address)
++Address=Address (next address)
--Address=Address (pre address)

p1+p2;Error
p1+1;(next address)
p1++;(next address)
p1=p1+1;
++p1;(next address)
P2-p1;valid(number of element)
p2-1;valid
p2; valid
--p2;

Rule 2:

Addresss-Address=Number(number of elements)

Rule 3.

Address+Address=illegal
Address*Address=illegal
Address/Address=illegal
Address%Address-illegal

Rule4:

We can use relation operator and conditional operator between two pointers.
(<,>,<=,>=,==,!==)
Address>Address=true/false
Address>=Address=true/false


Rule 5:

We can't per from the bit wise between two pointers like
Address&Address=illegal
Address|Address=illegal
Address^Address=illegal
-Address=illegal

Rule6:

We can find size of a pointer using size of the operator.

Example of arithmetic pointers


#include<stdio.h>
main

{
static int arr[]={0,1,2,3,4};
int *p[]={arr,arr+1,arr+2,arr+3,arr+4};
int **ptr=p;
ptr++;
printf("\n%d%d%d,ptr-p,*ptr-arr,**ptr);
*ptr++;
printf("\n %d %d %d",ptr-p,*ptr-arr,**ptr);
*++ptr;
printf("\n %d %d %d",ptr-p,*ptr-arr,**ptr);
++*ptr;
printf("\n %d %d %d",ptr-p,*ptr-arr,**ptr);
}


Output:111
          222
          333
          344

Explanation

Let us consider the arr and the two pointers with the same address.

arr

arr_value        0       1      2        3         4    
arr_address   100   102    104    106      108


P

arr_address       100       102    104   106   108
pointer_address 1000    1002   1004  1006  1008

ptr

p_address  100
ptr_address 200

Ptr is incremented by ptr++ and has value 1002, Now ptr-p is (1002-1000)/(scaling factor)==1,*ptr-arr=(102-100)/(scaling factor)===1,**ptr=1.

Hence the output of the first print is 1,1,1.
*ptr++ becomes 1004. Hence the output for the ptr-p=2,*ptr-arr=2,**ptr=2.
*++ptr becomes 1004. Hence the output for the ptr-p=3,*ptr-arr=3,**ptr=3.
++*ptr increments ptr by the scaling factor. so the value in array p at location 1006 changes from 106 10 108.hence ,the outputs for ptr-p=1006-1000=3,*ptr-arr=108-100=4,**ptr=4.

Example2:

#include<stdio.h>
main()
{
char *str="xyz"
char *ptr=str;
char lest=127;
while(*ptr++)
least =(*ptr<leeast)?*ptr:least;
printf("%d", least);
}


Output 0

Explanation

When ptr reaches the end with the string, the value pointed by ptr is'\0' ,value of ptr is less the value of least. So the logical result of expression is zero. Hence least is zero.


Saturday 11 May 2013

What Is Hungarian?


Hungarian notation:

It is one of the naming conventions followed by the sun micro system for naming predefined, class/interface/predefined methods and data methods.

Hungarian

Rule 1 for class and interface


"If any class name or interface name", is containing either one word or more than one word. All words first letter must be capital.
EX:


       Normal Notation
          
         Hungarian  Notation
  System
 Action event
Number formal exception array index out  of bounds exception.
  System
  Action event
 Number formal exception array index out of bounds exception.
          

Hungarian Rule 2 for the methods


If any method is containing either one word or more then one word, then one word first letter is small and rest of sub-sequence words first letter must be capital.
EX:

              Normal notation
         Hungarian  notation
  Print/n()
Action perform()
Item state change()
  Print/n()
Action perform()
Item state change()

Hungarian Rule 3 for the methods:

If we are using any predefined data members then all the data member must be  in capital letter.
 If the data member contains more than one word, than they be separated by underscore (-).

               Normal
Hungarian
  PI
MAX-PREORITY
SCROLLBARS-VERTICAL ONLY.
   PI
MAX-PREORITY
SCROLLBARS-VERTICAL ONLY.


The above rules are mandatory for predefined Class/Interface, method and data members.

The above rules are optional for user defined Class/Interfaces, method and data members. Software industry is always recommended to Java programmers apply the Huainan rules even for user defined class/interfaces, methods and data members.

Thursday 9 May 2013

Difference Between Instance Data Member and Static Data Members

 Types of data members in Java:

We known that every single java program must be written with respect to class, and a class is containing a collection of data members and method. In Java program data members from the class are classified as two types. They are

  1.  Instance data member’s
   2.  static data members

           Instance data members
        Static data members
1. Instance's data members are those whose memory space is creating every single time,"when we create an object."
1. Static data members are those whose memory space is creating only once. When the class is a loader into main memory irrespective of the number of object are created.
2. If the data member of a class is taking a specific value, than we must take the data member as instance.
2. If the data member of a class is taking a specific value, "then we must take the data member as instance."
3. Programatically instance data members declaration should not be preceded by keyword static.
Syntax:-
    Data type V1, V2……….
3. Programmatically instance's  data members declaration should not be preceded by keyword static.
Syntax:
    Data type V1, V2……….
4. Every single instance data member must be access with the respective object name.

Objname.instance data member name
4. All the static data members in Java must be access with the respective class name.

Classname.static data member name
5. All the values of instance data members are not sharable.

5. All the values of static data members are sharable.
6. All the instance data members are known as object's  level data members, because they depend on object name and independent from class name.

EX:- Int PIN,STNO,
6. All the static data members are known as class's  level data members, because they depend on class and independent from object name.

Static string INDIACAP,crsname;

Tuesday 7 May 2013

Difference Between Class and Object in Java?

Definition of class:- Class is a collection of data members and associated methods.

Definition of object:- Blue print of class is known as object

 

Different between class and object is follow


                    Class
                       Object
1.The process of binding the data member
 and associated methods. In a single unit
  is known as class.
1. Class variable is known as object.
2. Whenever we defined a class we never get any amount of memory space for the data members of class.
2. Whenever we create an object we get the memory space for the data member of a class.
3. Class will have logical existence.
3. Object will have physical existence.
4. Class will be loader first by class. Loader subsystem from secondary memory to primary memory.
4. After loading the class .In main memory object creation will taken place.




All the object of Java resides in heap memory (in general which ever languages follow dynamic memory location whose object resides in heap memory).

All the methods of all the programming languages executes in Stack memory.

All the constants values of all programming languages reside in Associative memory.

Heap memory, Stack memory and Associative memory are the parts of main memory.

Saturday 4 May 2013

What Is Constructor in Java?

 A constructor is a special member method which will call by the JVM automatically whenever an object is created by placing over own values without placing the default value.

Advantages of constructors:


If we use the constructor concept add a part of over the java program, we get the following advantage.

1. It eliminates in placing default values.

2. It eliminates in calling ordinary method. The purpose of constructor concept is that it initialized  the object.

.

Properties/characteristic of constructor:


 In over the java program, if we want to make use of constructor, the java programmer must follow the rules.

1. Constructor will be called automatically are implicitly whenever an object is created.

2. Constructor name must be similar to class name.

3. Constructor will not return any value even void also (if we write any return type in java, which is by default treated as an ordinary method).

4. The modified of the constructor should not be static because constructor will be called each time as a when an object is created...

5. Constructor will not be inherited because each constructor of class must initialize its own data member.

6. A constructor of a class may are may not be private.

7. If the constructor is private than the object of corresponding class can’t be created within the context of some other class, but it can be possible to create it object only within the context scope of class.

8. If a constructor is not private than the corresponding class object can be created everywhere i.e. no restriction on the accessibility of the constructor.

Thursday 2 May 2013

What Is Different Between Instant Methods and Static Methods?


Each and every class of java contains a collection of methods the methods of java are divided into two types. They are

1. Instance methods/non static methods.

2. Static methods.


                    Instant methods
                   Static methods
1. Instance methods are those, which are recommended to perform Repeated operations such as reading the records from the file, reading records from the data base.

1. Static methods are those, which are recommended to perform. One time operation such as obtaining connection from the data base opening the file either in read mode or write mode.
2. Pro-grammatically, instance methods definition should not be preceded by a keyword.

Static

 Syntax

  Return type method name(list of formal parameter)
{
      block of statements()
}

2. Pro-grammatically, static methods definition must be preceded by a keyword static.

Syntax

  Static return type method name(list of formal parameters)

{

     Block of statements()
}



3. Each and every instances method in java must be axis with respective to object name objname instance method name.

3. Each and every static method in java must be axis with respective to class name
Class name Static method name.

4. The result of instance is not sharable.

4. The result of static method is sharable.

5. Instance method is also known as object level methods because they depend on object name and independent form class name.

Example:

Void calfot()
{

   tot=m1+m2+M3;
}
5. Static methods are also known as class level method because they depend on class name and independent on object name.

Example:

Static void main(string arrays)
{

    S1,caltotal();
   S2.caltotal();
}


6. ISR is only executed when the interrupt is trigger.



6. function is only executed when the function caller called the function.

7 function call the arguments, local  variable and return address is stored in the stack.


7. ISR after execution the current instruction the context is saved with no return value.



Twitter Delicious Facebook Digg Stumbleupon Favorites More