Wednesday 28 September 2011

In java or any other language how method or constructor knows about those things which are declared in the class .

Today if 100 people are using java or any programming in this world but i am sure that 30 people in those 100 people does not know the reason behind " In java or any other language how method or constructor knows about those things which are declared in the class . " 


if you are not clear than watch this  ...

----------
{
     int a ;
    method_1 ( )
    {
       // question :- now how this method knows about " int a "
    }
}
----------


Tuesday 27 September 2011

object creation at machine level ....



please comment if ... you have any doubt ... because for me life without doubts is worth ... so think different and i think after reading this you will find or get some good knowledge of object creation ...
                                                                                                                                   so thanks tushar

Wednesday 21 September 2011

why we never declare our class as private and protected .


                        

I promise that i never back to my promise , so when i decide something to do than i do it no matter what you think about me .

i asked this question to myself on 12th august and today is 22nd august , i find my answer in 11 days , takes too much time but ... for me its like a defeat of my another opponent . so lets come in the answer and start the explanation .

private :--- private , when we make a class , we think that when we built it generally send to JVM and nothing else is needed to run or process this class . but sorry we all are wrong , because there are 2-others type of classes which are needed to process any class , they are BOOTSTRAP classes and EXTENSION classes . so what is the task of these two classes , these classes are used at run-time means they provide the basic API to solve or execute our problem , and these API's are stored in jar files so if you make your class as private than no other class can access it , means BOOTSTRAP and EXTENSION classes also can not access it .
thats why this class can never be performed means never be executed so NO to PRIVATE class . for more information refer it (http://download.oracle.com/javase/1.5.0/docs/tooldocs/findingclasses.html#javalauncher)


protected :--- protected and default are same but a small difference , but which thing makes protected as special ,  now in this case (why we never declare our class as private and protected .) the speciality hurt protected ,
                we all know that protected is visible to outside the package but think when class is loaded at the JVM the object is created for ever class to perform actions now we have declare that we are protected and
visible to the outside the world with the help of inheritance . JVM only takes your class as a default but why as a default , JVM take you as a default because at JVM working is performed by object and everything is similar between DEFAULT and PROTECTED in the case of object means default == protected for object but , what for inheritance , inheritance is a positive point of protected but here protected breaks security so NO to PROTECTED .


Default :--- Default and protected are same at every thing but benefit of default is that , only package is visible to class loader , and thats why default is in use , and protected is out of the game because of its speciality . now why default is in game , when we perform any execution the class file inside this package is visible to the class loader so default is visible to JVM . means whole package is visible to the loader . so no problem for BOOTSTRAP and EXTENSION classes to access the whole package .

Public :--- public is simple , but used heavily in java , but why heavily because when you create anything that is built for help in some-other program means consider all API they all are created as public means they are open to all for use , and another reason that feasible to all means anyone can access it . so no problem for BOOTSTRAP and EXTENSION classes .

( please if you know more things about java and any question will rise in you mind than please share your question with comment , because i want to learn many things any random questions are the best way to learn anything )

Friday 16 September 2011

first time i am dealing with heap and garbage collector .



  • HEAP and GARBAGE COLLECTOR

JVM term in field of JAVA . when sun introduces its JVM . before sun's jvm , IBM vm is working as sun in the market . but when SUN came up with a JVM after it only sun's sun shine in the sky , and IBM VM hide in some cloud .

this theory is typical but read this , how sun is different than any other . we all know that in java every thing is JVM , and inside JVM there is a heap . but do you know that we have two parts inside this heap .
1. permanent heap .
2. old or young region .

now question in your mind where object will reside , now listen our object will reside in old or young region and in permanent region our class code resides . now how these two are seperated . these two are seperated by layer ( means physically )


  • JVM uses two parameters for representing heap . 

XX : MaxPermSize (Permanent region)
Xmx (Maximum Java Heap size)

now do you think that JVM is only built for heap . the another main task of JVM is class loading and class unloading , class unloading is the term which is most famous in the field of java :- now why ?

class unloading is a term which i want to explain , because i like this part . what is unloading and how unloading is performed . class unloading is done when all objects are set as unused , now you something which collects these objects , this term is knows as garbage collector .

:- a problem is there in unloading a class , problem is that when you unload a class at that time memory leak can occur , so this can cause an error , which is known as
                            
                                                 OUT_OF_MEMORY_EXCEPTION .

garbage collector , i said that it like to collect the objects which are unused . so this collection is done under 3 cases . means 3 types of garbage collection is done .
1. default collection .
2. manual collection .
3. low pause mark sweep collector .

default collection :- default collection is simple and provide no extra advantage .

manual collection :- manual collection is a term , where you we can tune this garbage collection .

low pause mark sweep collector :- this is the field which is most important , this is same as default but if you  are in-compatible with default collection than refer to it . now what is the benifit of refering it . This collector is particularly helpful with the very large heaps that are used with the 64-bit JVM, or applications that have a large set of long-lived data, also and that maintains comparatively good cache utilization .

Monday 12 September 2011

Stack trace is a term which is used in representing the errors.


If anyone in this world ask a question to you that who represent the errors . than please say to him that errors are represented by STACK TRACE not by compiler or interpreter .
before this , i am also a part of your family in the scenario of error presentation answer , but today and right now i am apart from family . the reason behind this is that the term “STACK TRACE” .

  • STACK TRACE .
Stack trace is a clicked picture of the current state of your program execution means , when you are making any program or developing anything in this great world , at that time surely we all need to test our program . so testing means you want to find the errors , in simple term .
so whole task is only done for fetching information about the errors .
  • Three ways to tackle your ERROR .
1.   send an signal to your machine for STACK TRACE .
2.   your machine will send a picture of STACK TRACE .
3 .  using debugging tools .
  • How STACK TRACE is generated .
Stack trace is a term is generated when we test or compile our program . means  a snapshot of    
our problems . as shown in the figure .
  • from when ERROR is represented in the form of String .
The STACK TRACE is introduced when String is introduced because without explanation of error it is worth that you are trying to solve the error , which is represented in the form of some numbers .

for me and for my java errors are introduced in the form of string when java 1.1 .  
in java the creator introduced error in the form of string , for reducing the complexity of removing errors .