Thursday 8 December 2011

class file in java : representation of your data in class file ( try it ) !!


hello friends its cold in ma country and this topic is hot because we are dealing with java { hot-coffee } . see , people think that they can not use or they can not find any-thing from the class file but , i think you can find anything if you are serious for that thing specially in a java program . today i can say that if a person like me who is poor in studies can find some-interesting thing specially in java than any-one in this world can do anything specially in java . an advice from ma side is that , just devote your life to some topic or some fields than seriously you can feel the power of that special field .
today i am just explaining one topic because i just use ma 3-days in only in this topic and still i am not perfect so i think life is not created for being perfect its just created by god to try to be a perfect man . i respect god because he gave me a opportunity to give some-thing special to this earth . and still i am trying for providing some-small things at this level but i am glad because i just make a start , & seriously after some years  i will give more things to this earth .
see now come in a topic , i have a java program here i just enter a string and i am trying to find that how data is represented inside array .

here in image i have just enter a string and trying to find out how it is represented in the class file . for this i am using ” getBytes() ” method by this method your string is converted into the bytes and these bytes are represented and stored into the arr_1 [ ] and i have just printed that data with “Sytem.out.println()”  and see after it you will find the output in the UTF-8 format because inside get-bytes we are using it & the key point is that the UTF-8 format is same as ASCII format because every thing is entered by you from key-board is same as ASCII format thats why in next image i just converted data into hexa-decimal form .

now the interesting thing is that what will be my next step . for this i just use my class file and convert it into hexa-decimal form and in the hexa-decimal form i just find some great type of thing which motvates me and shows that i did it or i use my 3 days in a accurate way .


this image is croped but the main thing resides in this image and i think for me this is enough to explain . so the data in hexa-decimal is present in my class and this is the thing what i am trying to explain you . please try some-other example also , because java is infinite in  terms and in fields .
thanks for reading .


Wednesday 7 December 2011

some hammering problems in java


some question , if you are a java programmer or java user .
1. why java provides minimum support to boolean variables .
2. why java supports only 255 dimensions in array .
3. why java supports only 255 parameters in a function .
4. why java uses 9999999 values as a diffrentiator in representing values in the form of E form and in normal form .      example :– 10000000 is represented like 1.0E7 and 9999999 represented normally 9999999.

Monday 5 December 2011

run-time polymorphism in java .

if you are dealing with polymorphism in java than definitely at the start you will face the problem in the phase of run-time polymorphism . so do you ever think that what type of thing is happened at the time of run-time polymorphism . for this look at this picture ::--

in this figure i have just described the program , because we all deal with this type of programming in the phase of run time polymorphism , now think about the output of this program .


now think about this ... how this process is happening from the scratch or from the compile time , now see at this picture , this image is passed or this is the run_time_constant_pool which is passed after the compilation of the program .
so this text of information is passed at the time of run time see at the point 4 ... from point 3 ...
you can see that compiler told to jvm that there are two methods which are referencing from main-class(1) and support-class(2) . so at the compiler time methods are only checked that they are legal or illegal . and they are displayed or represented as legal .

now at the run time , we are taking run time because objects are created at run time and every linking is performed at run time .















Sunday 4 December 2011

difference between jdk-6 and jdk-7

hello every one , these days , you can easily watch or feel the effect of java in the whole world 3 billion devices  are using Java , this is great for me . but do you know now java is under the fame of oracle . and if you download the jdk  from the site you find that they are over-taked by oracle .

now what is the difference between jdk-6 and jdk-7 , here i am sharing my views what i feel , because i tried the both and found some-great things inside jdk-7 . for a programmer if you are an people who just believe in programming , there are no difference because he never wants to deal with those affects and i found those difference because i am a blank person in this world who is living without aim .

so have you ever heard about run-time-constant pool . i think this pool is hurted mostly , because i think pool of jdk-6 and pool of jdk-7 is changed totally . the most important sun introduced in jdk-7 is UTF-8 format , which is compatible with ASCIZ representation ( same as ASCII , difference is : followed by null { zero byte } ) and the benifit of UTF-8 is that multi-lingual support and comfort in encoding .

you can feel or use the run-time-constant pool using :
        javap -verbose classfile ( without .java ) 

Monday 28 November 2011

class file : please don't think that you can not find any thing from class file in java program .

today i think if 10 people are working in java than from these 10 people only 1 is working for his basics and rest 9 are only using java . i will tell you something ... i met some-one and he replied to me that he had completed his java in 30 days i am supprised and appreciate him that he did a great job , after he asked me what are you doing in java , i generally replied him that i am just using java , because i dont think you and say anything to these type of people .

some-people thinks that class file is a waste in java programming but , if you take my point or believe in me than seriously all days and nights i just use my time in working but now you will think what  a jerk i am ! yaa thats true that i am jerk and these types of words are also used by my brother for me .. i respect those words , because i deserve for those words .

now this is a class file now after this i will highlight some-points which are understand by me , and you can also understand them easily .


now here i just edited 4 points which are easy to understand .
so please look at them .

1. <init> is used for initializing the instance variable so it is called implicitly & in previous blogs you can watch the whole process of init .

2. now at second i just point the main method inside it there is a import type statement by which you can easily use string in java , so this import statement is differ from original statement because this is internal representation of jvm here we remove "." from "/" , and after it "V" is there "V" means void type .

3. now at 3 you can see that there are two methods name . so at the top only names are saved of method , and stored into string pool and when ever they are needed they are fetched from the string pool .

4. and at 4 there is a source file name .








Wednesday 23 November 2011

How things are initialized in java program inside jvm ..

hello every one i am tushar , good morning to all of you ,i m from india the best country of this world . and its honor to me that i am indian and writing blogs for my love 'java' . and today i am dealing with " How things are initialized in java program inside jvm  .. " .


so for me programming is not important , i love my state when i deal with basics . so in java i always prefer basics , than programming because basics are the the root of everything . so thats why i always deal with jvm specification .


when we perform or implement any-thing inside java program . every thing in initialized thats why initialization is the first step of every process . so inside java/jvm we have two statements for initialization they are <init> & <clinit> . 


<init> :---- this statement is used for initializing the instance       variable of java program . 


<clinit> :-- this statement is used for initializing the class type variables in a java program .


now think about what will happen in this case .
now what will happen for this program , now do you ever think that how things are initialized means its lies inside the instance variable category but these are initialized at static variable but we have only two initializer <init> and <clinit
and they are found inside jvm so the question rises is , how can you say that " int a = 10 and double d = 29 " can initialized at the compile time . so for this java/jvm operate this problem by constructor and initialized them inside constructor . like ...


now it is clear that no matter where you initialized values of instance variables , every thing is initialized in constructor if you are declaring them as a instance variables . 

                                                  .thanks tushar

Sunday 20 November 2011

real example of ...which loop is better "for or while" in performance .

hello friends its morning in india , so very good morning to you and thanks to god for providing me a great life .

when i am dealing with " which loop is better for or  while in performance " i found some difficulties but after every stairs surely you get one step closer to your destiny . so lets start with the program but before this here i use a method " System.nanoTime() " which help me the most in finding the difference between for and while .




now these three methods are used like this .

image : 1 --

image : 2 --




here we find the actual time after initialization loop means for ( int i = 0 ; i < 10 ; i++ ) ; so from this program i  found some key points related to performance of loop . these points are following .

1 . the loop which holds the property of initializing takes more time than the other loop which holds the property of only iteration .

2. and after one iteration the loop which holds the property of initialization and the loop which holds the property of only iteration takes nearly equal time 

3. after 37 tries with the help of do-while loop , both loop takes nearly half time of its initialization time .

so if you want to test this program in real machine than please switch to p-2 or p-3 processors because i am using i-3 and finding the accurate result in this machine is very hard for me . so best of luck and the whole program is added ...



Saturday 19 November 2011

difference between equals and == in java

hello friends from two days i working behind this topic , and now i can say that i can tell you equals method easily because i find some methods in java which can clears your concept easily . but still at the point of " == " still i found nothing for " ==" so sorry but you can also make a search for it . please try your best for finding the answer .

look at the what type of things are happened inside equals method or why it is different from "==" :---
                                                                                                             java is very good for users , community just add this method inside Object class that anyone can use this method . so what is the process for equals method .
1. create any object .
2. find its hash code .
    using ob.hashCode( );
    by finding hashCode , now you have the object identity , and the identity lies between                                                    Integer .MAX_VALUE + Integer.MIN_VALUE ,
3. find hexString of this hashCode .
    you can find the hashCode with the help of Integer.toHexString( ob.hashCode( ) ) ; , now i find that the hashCode is just a object-id and  Integer.toHexString( ob.hashCode( ) ) is works as a reference . so when ever you perform operation like ..
 now from here what i want to explain think about this !
here i just put code for the previous explained thing .
here i just compare the hash code of two string and found "yes_1" in the output . means hash code only works as the object id .
now the main thing starts here Integer.toHexString(str.hashCode() )  this works as reference , so the link created for this reference is created from stack , and str & str_1 are stored into stack with different addresses and == also deals with stack so it prints no_1 in the output .

now here the main thing comes the equals method which works on heap , means which is stored inside heap so by this string stores same thing so things are type copied from string pool so content is same and the output is yes_1
so the difference is also cleared from 3 & 4 picture with a explanation .


Friday 18 November 2011

How many objects you can create inside one program .

hello friends today i am with some different part of java  values of  " objects " . now the topic which i want to explain is " How many objects you can create inside one program . " so for this i just use my 2 hours but the thing is that i started from some other topic and ends in some other topic , so it is bad thing for me that i reached at different point , but the good thing is that i found another thing about java .

look how to make a start for this thing .
1. create a object
2. find its hash code using .... object_name.hashCode( ) ;

now look at the hash code which is found using the method of Object class and if you have time than please look up for Object class where you can find the method declaration like " public int hashCode()" so the main thing inside this declaration is " int " means its type is int , so  the method hashCode ( ) will always make a deal with integer values . means a value return by this method is int and which is treated as "object id " . by object id , manipulating is done in objects means objects are used . so this object id resides under integer limit means now we can only create objects whose maximum limit is Integer.MAX_VALUE .  and whose minimun limit is Integer.MIN_VALUE .

so you can create only 4294967295 objects in java .

Wednesday 16 November 2011

What is Encapsulation ... think different from your bookish world .

Hello friends i am tushar , with a simple topic , Encapsulation . today i want to explain something basic about encapsulation . surely which is beyond than your bookish world . i want to tell you something about my-life with java , when i start with java i just depend upon the book like a fool , for me if you are a lover of anything than please shutdown your books and google . and treat data like open data and edit it and built some thing new for this lovely world .

so what i read about encapsulation is , we protect our data from this entire world , but today if i say that i am fool with these protecting words than it is not a wrong statement for my state , and i am glad and enjoying my state with some new words so today for me encapsulation is used for these following words .

1. extensible
2. reliable
3. maintainable

now you follow my suggestion than i will say that encapsulation is used for extensibility / reliability / maintainability .
but why i am against protecting look at this image .

now from this image and and look at the output of this program ....

so if you have some time than please try this in your home you will find that the term protecting is never ever is related to any object , now why this is not related . this is not related because when ever a object is created it have its own copies of data so forget about data protecting .. thats why i am focusing on some new terms .

which are listed above . now its time to explaining them .

Reliable :--- now i will show you a image and think that this image is reliable for you or not .

now by seeing this program anyone in this earth can understand it easily so reliable means feasible to any layman in field of programming .

Maintainable :--- maintainable is also another important term because today my country india relies on maintenance ... so maintainability means the code is maintainable or not ... so every thing is designed very carefully because it surely it will need some maintenance in future ...

Extensibility :--- now for me the important term , why i choose this topic behind this the reason is extensibility , now i will show you a image and think that it is modifiable or not .
see at the right side i have just introduced the support class as in new form now call it or use your objects to calling your getters and setters and you will find that there is no effect in the class .

*** so now i think you can say that we all are using encapsulation not for protecting data ***
                                                                            
                                                                                                                                  thanks tushar

Monday 14 November 2011

how invoking statement creates link with the method . { Java }

hello friends i am tushar , and i just want to explain an interesting topic , which is very interesting in my sense . but i am not sure about you . this concept of method invocation is applied in all languages . means every langauage has similar type of statement so reading this topic and learning something from here never creates a junk in you mind because for a programmer it is very important to learn to all these things .

so i want to explain some thing which is totally cleared from the following image ...

so from this figure , i want to explain that between the method and invocation part there is a arrow , so the question is that who is behind this arrow or i want to find the linker between method invocation statement and method .

so behind this there is a method , "invokeExact" method which plays a important role in linking the statement and the method . so how the process works ...

before every thing you have to learn something about machine representation of java program or something about some instructions like invokevirtual / invokespecial / invokestatic .so look when i make a simple program of linking a invocation statement and method .

now see a machine representation of this figure or you can say at run time what is the state of this program .

so for your kind information i want to tell you that compiler never connects or works as a linker . for this compiler just create a instruction which can be invokespecial / invokevirtual / invokestatic . and when ever there is a statement like invoke , it makes a call to " invokeExact " which is a method . and now the task of invoke method starts who is the linker between these two .

so the syntax of invokeExact is "invokeExact(object, methodName, args);" so ... invokeExact is the cause behind linking in java ..

for more information use this link "
http://commons-beanutils.sourcearchive.com/documentation/1.8.0/classorg_1_1apache_1_1commons_1_1beanutils_1_1MethodUtils_f4ce95949171d8df38555ba441a1cc51.html"

Sunday 13 November 2011

see , how short / int / double can create difference in execution of for loop .

I got a beautiful response from people in previous week so i can not say good bye to my blogging ... here a simple but interesting topic , see how can values like short / int / double can create difference in execution of for loop . 

now its time to come in my topic . look when our for loop walks inside machine , for execution , at the rum time if you are using int in your for loop than its ok , because java is there for programmers who love int in their programming . i am just making a simple program of for loop where i have just use int values . 



now look what will happen when this program will reach into machine for execution . at machine level too many instructions are used there . 
                                                     
some instructions are used here . look some which i want to explain . see here why i am saying that java is built for int lovers , if you want to use increment statement in your programming than you can only use increment word in your programming with integer no other data type is in java to support "inc" instruction . and for int lovers look at comparision statement here we use if_icmpge statement , only one statement . and the best thing is that for int lovers . if you see this code this is too small than all the codes relatives to for loop . 
means i will show you some images , by seeing them you can say that run time code for for loop for int is too small than all the other data types in java . 

now i want to explain a example where i have used short . and see the difference between int and short and here you can see the compactness followed by int values which is provided by java .

               
now see the difference between int for loop and short for loop . comparsion statement is same because implicitly in java every thing is performed with the help of  "int" . so every thing is same but a statement is changed that is iadd and i2s . i have  already said that increment word or instruction is only used with integer so this is short but before this we all know that short is also used as int , so why we are using i2s instruction , we are using this instruction because when one process of for loop ends after it the value is stored into memory in the form of short so we have to store it as short . 

now look i have to explain the double for loop . so i am using double value . for explaining the for loop . 
now look at the double for loop . here things are different than int for loop but some things like increment is same as short for loop . now look at differentness from int for loop , differentness is a compare statement , at int for loop we are using statement like ig_cmpge but here different statement is used which is dmpg + ifge so .. thats the difference , and thats what i want to explain ... to all of you .. so ba-bye and take care 

                                                                                                                                  thanks tushar 

Wednesday 9 November 2011

practical difference between interpreter and compiler .


public class TimeArray 
{
    public static void main (String args[]) 
   {
         int something = 2;
         long startTime = System.currentTimeMillis();
         for (int i=0, n=Integer.MAX_VALUE; i<n; i++) 
         {
              something =- something;
         }

         long midTime = System.currentTimeMillis();
         for (int i=Integer.MAX_VALUE-1; i>=0; i-) 
        {
              something = -something;
        }
        long endTime = System.currentTimeMillis();
        System.out.println("Increasing Delta: " + (midTime - startTime));
        System.out.println("Decreasing Delta: " + (endTime - midTime));
   }
}



now if you compile this program means if you want to convert it into byte code ... for this we use " javac TimeArray.java" now the byte code is ready in the form of jvm understanding code . now jvm comes is the role and play its game with machine . it converts this program or deals with this byte code . and for dealing it uses jit compiler 
and for it we write " java TimeArray " and the output came in only 5 seconds but if you want to use interpreter in the place of compiler than you can use "java -Djava.compiler="" TimeArray " and the output came in 53 seconds ... this is a beautiful thing wow , i love it ...


                                                thanks tushar .


array ( memory problem ) in java .

I heard from some people that java deals with memory very beautifully . here i am not opposing them they all are learner and i am also in this class . but i find that some-times java is not correct in the matter of space saving .

why i am saying this .. see this article ..
http://jroller.com/rreyelts/entry/that_byte_is_about_7x

a great person .. Toby reyelts ..

here instruction like bipush and iconstant and ldc are not exclaimed at good level .
i will exclaim these three topics .

bipush & iconstant  :----
                                        iconstant is a part of bipush , and iconstant  is better than bipush but how , iconstant saves 1 byte in case of entering any data into machine by array , bipush takes 7 bytes to entering data into array and iconstant takes 6 bytes to enter data into array .

How 7 bytes are used by bipush :----
1.  1st byte is used dup the variable used in run time for passing data from operand stack to local array .
2.  2nd byte is used for finding the array .
3.  3rd byte is used for finding the index in array .
4.  4rth byte is used for passing the value .
5.  used for bastore .
6.7. two bytes are used for passing the operand and passing the value  .

how 6 bytes are used by iconstant :----
1.....5 every thing is same .
6,7 are converted to 6 and both things are passed only in one instruction .

so think about this that for passing one byte you have to use 7 bytes , so at this point java makes somee mistake that they did not create some instruction to handle the data or the array .

ldc :----
            ldc is a instruction used for loading values form run time constant pool .
there are 3 types of ldc .
1.  ldc  :-- used for small ranges .
2.  ldc_w  :-- used for ranges like int and float .
3.  ldc2_w  :-- used for ranges like long and double .


Tuesday 8 November 2011

machine independency of java


how to find that your compiler or machine works in one-byte , two-byte or in four-byte

I think when you want some-thing from your heart you will find that thing from nature in the gift but the condition is that nature needs patience . Java also needs patience , if you want to follow my foot-prints then after every new fetched information you have to take a break .

now its time to take a dip in the topic , " how to find that your compiler or machine works in one-byte , two-byte or in four-byte " .

behind this there is a simple concept ... if you are using c than make a code like :--


                int *p , *q , *r , *s , *t , *u;
                *p = a ;
                *q = 4 ;
                *r = 5 ;
                *s = 1 ;
                *t = -10;
                *u = 100;
                printf("%d",p);
                printf("\n%d",q);
                printf("\n%d",r);
                printf("\n%d",s);
                printf("\n%d",t);
                printf("\n%d",u);

and you will found output like ( in my machine )
                862
                874
                12803
                -29156
                3365
                64

now the use of this output is that , if we get address in odd-even by any machine than it surely it will work in one-byte opcode fetching or use one-byte .

and the same concept is also followed in Java

test_of_addresses ob = new test_of_addresses ( );
System.out.println(ob);

test_of_addresses ob_1 = new test_of_addresses ( );
System.out.println(ob_1);

test_of_addresses ob_2 = new test_of_addresses ( );
System.out.println(ob_2);
test_of_addresses ob_3 = new test_of_addresses ( );
System.out.println(ob_3);
test_of_addresses ob_4 = new test_of_addresses ( );
System.out.println(ob_4);
test_of_addresses ob_5 = new test_of_addresses ( );
System.out.println(ob_5);

int i = Integer.valueOf("1fee6fc", 16).intValue();
   System.out.println("Integer:=" + i);

   int j = Integer.valueOf("1eed786", 16).intValue();
   System.out.println("Integer:=" + j);

int k = Integer.valueOf("187aeca", 16).intValue();
   System.out.println("Integer:=" + k);

   int l = Integer.valueOf("12dacd1", 16).intValue();
   System.out.println("Integer:=" + l);
   int m = Integer.valueOf("1ad086a", 16).intValue();
   System.out.println("Integer:=" + m);

and you will get the output like :---

                _________92
                _________58
                _________22
                _________77
                _________98

"" and by this concept we can easily say that  Java and C follows the concept of one-byte opcode reading and writing . ""

Monday 7 November 2011

in JAVA , deal with interpreter ... after compilation ....

thanx to god that , i have internet because without internet i am a worth element in this world . and thanx to SUN MICROSYSTEM that are in this world for helping all java lovers and they are like my parents and greater than my parents . 


now i have to deal with my topic . dealing with interpreter after compilation . but what is the meaning of this topic . it means that when we compile our program we convert it into machine understanding language . now in JVM , jvm will come in game and its work starts that it will load the class ... this takes too much text because it has too much data behind the loading , now i have to introduce the topic that how interpreter comes in sun-light . what you have compiled will be send to jvm to interpret because at jvm , jvm will also understand the byte-code . 


take a example :--


generally make a program ... name it as " compile.java"


:-- compile it using **javac compile.java** 
    { here you had converted your code into byte-code }


:-- now generally we include **java compiler**
    { here our all byte-code is understand by the help of JIT-  compiler means the term **java compiler** is used for jit compiler . here out code is treated as whole page . but if you want to understand it by line by line than remove **java compiler** from your cmd screen and include 
     
        **java -Djava.compiler= "" compiler{program name}**
        " " you can pass any name inside it . { but why still i am searching for it " .


{ try this in your machine because i love it , and i think you will also love it } 


...in java when we write **javac file_name.java** {compilation} & **java file_name** {JIT compilater means still compiler to understand byte code } .. 
means compilation + use of compiler { but if you want to use interpreter }.


for this you have to include **javac file_name.java** {compilation} & **java -Djava.compiler =" "file_name **{ means now we have removed jit compiler and we are dealing with interpreter }...

Sunday 6 November 2011

optimization in any programming language .

Hello friends , good morning to all readers , first why i choose this topic , i choose this topic because the term OPTIMIZATION used too much in raw-material of languages . 


Here i want to explain the basic thing or why it is used in languages and what is the thing behind it , that it is used too much in raw-material of language  . "optimization" is a term used with some different thinking , when you write any code and after compilation it is changed into machine understandable code . 


when any code changes into machine code , before it at intermediate level many optimization steps are taken . they are some-thing like that :- 


write a code :---- ( images from wiki-pedia )

int a = 30;
 int b = 9 - a / 5;
 int c;
  
 c = b * 4;
 if (c > 10) {
    c = c - 10;
 }
 return c * (60 / a);



after first optimization :--------

int a = 30;
 int b = 3;
 int c;
  
 c = 3 * 4;
 if (c > 10) {
    c = c - 10;
 }
 return c * 2;



after second optimization :-------



int c;
  
 c = 12;
 if (12 > 10) {
    c = 2;
 }
 return c * 2;



after third optimization :-------



return 4;



now in what basics these optimization steps are carried-out .
these steps are carried out in the basics of constant folding and constant propagation.


constant folding :- 
                             constant folding is a term which means that solving constant expression when they are needed .


constant propagation :- 
                                    constant propagation is term which means that passing you constant values with the help of some variable to some other expression .
                    int a = 10 ;
                    int z = 20 + a ;


at the compilation time , the value is passed to the expression is very accurately processed  , because if you process it with some false thinking than at the compilation it can create some problem , so optimization is very necessary in all languages .

Saturday 5 November 2011

UD chains and DU chains in all languages .

i am in the way of failure , but  i am sure that i will succeed in my task which i set for me and myself . when you get or feel something bad , that you are going in the shrink , i think that is the phase where you have to start . this topic looks too complicated but it is too easy to understand .

we have two things UD chains and DU chains .

UD chains :--
                     UD is a combination of two things . 1st is U and another is D . the meaning of  "U" is that a variable and the meaning of "D" is all the definitions of the variable but now what is the sense of meaning .
look at this
declare a variable :---- int a ;
a = 10 ; 
a = 20 ;
a = x+y ;
there are 3 different use of a single "a" variable .


DU chains :--
                     DU is a combination of two things . 1st is D and another is U . the meaning of "D" is definition and u means use of this definition ..
look at this
declare a variable :---- int a = 5 ;
int x = a ;
int y = x + a ;
two different use of  a definition .

use of DU and UD is in , data linking , sign extension algorithms .