Posts

Showing posts from August, 2015

Continuing with exception..!!

Now as we learnt about how exception works internally how throw of object occurs in exception well as said earlier that java has provided a readymade class for handling of exception.  java provided a readymade class such as ArithmaticException,ArrayIndexOutfBoundsException, ClassCasteException, NumberFormatException,etc. Due to such ready made classes we can write its object in catch block to catch exception if for example the exception of divide by zero occurs  then declare the object of ArithmeticException in catch statement such as  try {     c=a/b; System.out.println("the answer of division is" + c); }//end of try block  catch(ArithmaticException e) {    System.out.println("exception caught" + e); } //end of catch block This is the simple exemple which i gave............. here if the exception occurs than the object of that exception is generated and thrown and in catch as we kept the object of that exception it will be caught it is not necess

How does exception actually works and the mechanism behind it ..In JAVA

Image
Working of exception       what is exception...?? simple  meaning of exception is run time error the error which occurs while execution the program.For example how this exception are generated is by the user inputs the false value or its the fault of the programmer having no better concepts about it. Some of the examples of exception are ArrayIndexOutOfBoundsException,   NumberFormatException, NullPointerException, ClassCasteException, Arithmetic Exception. so above were the exceptions that could be generated not limited to this still there are many but this all are the basic which would occur normally. Common scenarios where exceptions may occur There are given some scenarios where unchecked exceptions can occur. They are as follows: 1) Scenario where ArithmeticException occurs If we divide any number by zero, there occurs an ArithmeticException. int  a= 50 / 0 ; //ArithmeticException    2) Scenario where NullPointerException occurs

What are the main differences between Java and C++?

Both Java and C++ support object oriented programming, yet there are differences between them. To begin with, Java is a pure object oriented programming language; therefore, everything is an object in Java (single root hierarchy as everything gets derived from java.lang.Object ) . On the contrary, in C++ there is no such root hierarchy. C++ supports both procedural and object oriented programming; therefore, it is called a hybrid language. Following are the major differences between Java and C++: Java C++ Java does not support pointers, templates, unions, operator overloading, structures etc.  The Java language promoters initially said "No pointers!", but when many programmers questioned how you can work without pointers, the promoters began saying "Restricted pointers." Java supports what it calls "references". References act a lot like pointers in C/C++ languages but you cannot perform arithmetic on pointers in Java. References have types, and

basics of header file

A header file is a file with extension   .h   which contains C function declarations and macro definitions and to be shared between several source files. There are two types of header files: the files that the programmer writes and the files that come with your compiler. You request the use of a header file in your program by including it, with the C preprocessing directive   #include   like you have seen inclusion of   stdio.h   header file, which comes along with your compiler. Including a header file is equal to copying the content of the header file but we do not do it because it will be very much error-prone and it is not a good idea to copy the content of header file in the source files, specially if we have multiple source file comprising our program. A simple practice in C or C++ programs is that we keep all the constants, macros, system wide global variables, and function prototypes in header files and include that header file wherever it is required. In clud

A reason for why to take a pointer of different data type .

 why to take a pointer of different data type. for eg if we take in c and cpp we generally take the pointer variable of the type ,of which variable's address we want to store in it. for pointer it is fixed that it reserves 2 bytes for it then why is it so....?? As far as pointer is concerned we store an int variables address so we have to take a pointer tf int variable type there is a simple reason behind it . for a pointer variable,has nothing to do with what is the type of variables whose address is going to be stored in it. Remember the the two points always keep in mind it that pointer requires only two bytes & is stored always in RAM,   Lets take an example class A {      int a;      int *ptr; //(*) sign is to indicate that it is not a normal variable but a pointer variable.      ptr=&a;//stores an address of int variable a } now see we took int pointer variable so we indicate the pointer variable that we are going to store the address of vari

An introduction about data class and exception class

Posted this to make aware by the term data class and exception class First of all it is necessary to know that what is data class and what is exception class  data class is generally hat we write that is what the the programmer or the user write. So i would like to make the clear difference about it. First to understand it we have to  the word throw and return  return comes into picture when the question comes about calling the function in the class specified by the user think that the user constructed the class A in which the methods are defined such as for e.g add(); ,sub();,test(int a,int,b);  so from the  main  user calls it explicitly by passing the argument or without argument So if the function contains any return type and returns the statement then it gets return where the calling statement is specified So this is the concept about how the function works by calling and returning the value of from where it is called.  Now about the word throw:   Throw wo

working of garbage collector in java.....!!

Well in this post i will give u brief introduction and working of garbage collector....!! Garbage collector:- in java garbage means derefrenced or unrefrenced object.it is the process to reclaim the unused memory automatically.In words it is the way to destroy unused objects. To do so we are using free( )in c and delete( ) in cpp. But in java it is provided automatically so it gives a better concept to destroy unused or derefrenced object to be destroyed automatically. Advantages of garbage collector:-  It makes memory efficient as it destroys the members which are consumed in the object and unused which and are stored in heap is done by the JVM(it is the part of jvm) which makes it run at several time intervals. Now generally how could the object get derefrenced .....!!! Generally the basic concept behind the derefrenced object is that the object gets derefrenced when it's scope gets over generally when the program ends its scope would get over definate

what actually happens when u declare the objects..............!!

                                Declaration of objects    well what that happens when we declare   an object objects are those that contains the ability to access the methods and variables declared in class objects are the vaiables of class  "object" refers to a particular instance of a class where the object can be a combination of variables, functions, and data structures.   so our motto was what actually happens when we declare an object an object has two parts  one is the data that it remembers and other the actions that it has to perform. for eg objects is the collection of different types of variables of class so which all members are included in it it has to remember and which method it has to call i.e. given action by the user. the li fetime of the variable and the value is till the object is alive.i.e till the logical end of the program.                         logical end and abnormal end logical end and the abnormal end are the two ends t

some basic knowledge about constructor

                            Constructor     use of constructor:-  constructor is used to initialize the value of variable just as we initialize the value of variable in a program.    Characteristics of constructor constructor dosent have a return type. they are used to initialize the value to variable. compiler has not given us permission to call constructor . constructor is called automatically at the time of object creation. constructor dosent return any value. constructor cannot be virtual nor can we refer to their address. they can make implicit calls to new and delete they cannot be inherited. note:-normally people say that constructor dosent return anything but thats not true constructor return address implicitly. yess T wo types are there for return 1)explicitly return  2) implicitly return constructors are the examples that they return the address implicitly. for e.g. class a {       a( )       {                   }