Thursday 28 July 2011

why a ( 4 byte ) int can easily store in ( 4 byte ) float .

read this properly ,, and you can understand the concept of float vs integer . properly ,,,

Tuesday 26 July 2011

by only seeing your program how can you say that this java program is platform independent .

this is a very easy question , friends but for a starter , this looks like a heavy one ,
but in java , the mighty sun provide everything so . dont worry i will help you .

when we starts  program , when we declare main at time you all java horns include void , so why you include void do you ever think about it .

the reason behind void is that , we all know that no return type , but in actually we are telling to machine that we dont need anything from you so sorry i am happy with myself .

so what is the effect of void , first question in your mind that why this fool person , is wasting our time .
if m a fool than sorry leave this post . and fuck your stupid minds kingdom .

what happen when we include int in our java program , means we are now saying that we want something from machine , but we all know that java is platform independent , now if you write int , than if you are using 16 bit computer than int will return 2 byte , and 32 bit will return 4 byte , now by including int we make our program as platform dependent . so thats why java never allows you to make your program as a platform dependent . { but please dont try , strictfp + float here } and you will excuse me why this is not working .
becasue still you are returning something but it is controlled by strictfp .

Monday 25 July 2011

problem with equals( ) method .

when we generally read Object class, their we read that equals( ) works when , the two reference are pointing to one object .

animal a1 = new animal ( );
animal a2 = new animal ( );

these two are pointing to two different thing , its ok .

animal a3 = new animal ( );
animal a4 = a3 ;

here a3 , a4 are pointing to same object so they are equal .
now listen . a problem with this .
think that you have a car , and a key .
here are three things in use .

1.  person .
2.  key .
3.  car .

now think that we are doing searching , we want a person from car and key , so here we , our person and key are inherited from car . so for this first check instance of . and then apply the == equals method .
and then what you want .

Sunday 24 July 2011

difference b/w two same things ( super / this )

when we override something or extend something , what is the cause  ,that you can access any method . from from both super and sub classes .

the thing is that when you create a object at that time a default constructor is called , and calls itself implicitly , and you can also define it . but the game is that what happen in implicitly . in implicitly , the
super perform a task that , it tells the compiler that super class have these these things and now you are also the owner of these things .

but now what is the difference between , this and super , generally ' this ' is the keyword which is used for ,
reference , means totally opposite from super , but these two things provide same things to you but in different way , and you can not add these two things in a constructor . at a same time .

this is related with object ' reference ' ;
===============================================

u all heard about 'this' keyowrd now i will something different from 'this'

basically we use this for differentiating instance variable from , local or parameters . ya its ok you wana explain like this .

class alpha
{
       int x ;
       alpha( int x )
       {
                x = x ;
       }
}
now which x is yours and which is of class .
for differentiating b/w x & x we use , this .
this is used , for our class variable . means instance variable .

this.x = x
means you are assigning something , to your instance variable .

=====================================================================

but now listen i want to explain something different
we all see that , you cannot call a arguement constructor from default constructor . so for this we use               this ( ) ; method . use it like this .


class alpha
{
       
       alpha( )
       {
                this ( 3 ); 
                // and make always this ( ) ; as your first statement in the constructor .
       }
       alpha( int x )
       {
                 
       }
}
======================================================================

now i want to explain ..... that treat this as a address , or a reference , which have qualities . means 
this is only built for a particular class , or for it super class , means this is same a object reference which is necessarily created in a class and used in a particular class 

if you create a object of different class and want to use this as a ' this ' then you will got a compile time error .

every thing you do with 'this' is limited to its superclass and to this class .

=======================================================================

Friday 22 July 2011

real life difference between interface and abstract classes .

look java is real life language . and the creator create this language for this real life so , every thing is implemented in a practical way means it should implements in your real life .

so i want to explain something , i know that if you are a learner than you know these things but do you
know the real life implementation of these things . i think here you are after me . now i want to explain these basic things , because basics can fuck any engineer .

interface generally provides you a thing that , abstract can not provide you .
------------------------------------------------------------------------------------------------------------------

you all read the defination of abstract that collect these things in a common place . but you implement these things in your life .
i need these things that please implement every thing in your life .
now think you have a organization . and in organization every one is employer . so you gather all common thing in employer .
but can you differentiate employers . from only abstract thing . i think no .
take a example . that you have no information in abstract  . and you say he is manager ,and he is ceo .

remember that in abstract you put your common things .

and by multiple inheritance we can not extend two classes .

------------------------------------------------------------------------------------------------------

now in interface , you read that this is contract . ya its ok but how to implement it . think that you have 3 persons and you have to differentiate them , for this you just take a interface and define what you want ,
take a example . a person is different from this person because he wear hat , bands , jeans .. so provide these things into some interface  ...

thats why we say that a class extend more than one interface

so a interface is used in real life for differentiating a thing from another .
------------------------------------------------------------------------------------------------------

Thursday 21 July 2011

anonymous class & object in java

java is typical , and show its tipicalness many times , typical means for user they can do ever thing , even they can kill you for user's happiness .

take a example of anonymous class .
here you can see that , why java is famous , for great user expirience , and assassin of a programmer .

anonymous means without name .
so anonymous class is , class without name . so now the image , in your mind is that , how to store it , thats why java make this class as a inner class .

but why we use it .
think you have a playstation , and in a playstation 10 players will come and play the game , so you have to display their information , for this if you are from  inheritance background , than you will make 10 classess , not a bad thinking , but in these classes their are everything is same , only different thing is a player , so here you make 10 classes for a method . thats why we use anonymous class .

now its declaration & working .

play_station o  = new  play_station()
{  // class starts at run time
void theory()
{
System.out.println("1st person");
}
/*class ends*/ }.player();
                o.screen();
                o.button();

play_station o  = new  play_station()
{  // class starts at run time
void theory()
{
System.out.println("2nd person");
}
/*class ends*/ }.player();
                o.screen()
                o.button();


when class starts , and wheu can it ends after it it will create a reference n this reference is assigned to 'o' and after it you can call the method player( ); for each different person , and overrides it.


----------------------------------------------------------------------------------------------------------------------------------

after it i have anonymous object . so same meaning but concept is that , remove name

like  " new play_station( );  " here you create a object and this have a reference , so if

"new play_station.theory() ;"; than ok it will call  , but the problem with this is that . this object is built for only one method , for using other method you have to create a block initializer or create a new object
for another method .

Wednesday 20 July 2011

difference between overloading and overriding .{ excluding the simple parameter diifference}

when i say that explain that what is the difference between overloading and overriding than , all answer will point the same thing that ... changing a thing without changing its variable , its type , its name is overriding , and changing everything except it name is overloading .

now do you think that it is ok , or not . than i will say that you are correct in some meaning but you are wrong in basics . the main difference between overloading and overriding is related with binding , but why
because every thing in every language is related with some binding . so how overloading and overriding is different .

overriding is done or come in existance in the form of dynamic binding , but why , overriding is done in dynamic time ,i think methods can having same name ,same parameter ,same type .... if every thing is same ,than you can not differ it in compile time so overriding is performed in dynamic time .

and in overloading every thing is done in time of compile time now the question is why this is done in compile time , i think that every thing or one thing is differ than original one so overloading is performed in the compile time, because diffreentness can be easily searched in compile time .

now what is the meaning of compile time and run time .
------------- class  alpha {}

    alpha ob1 = new alpha ( );
    " alpha ob1 " is compile time means overloading is depend upon this thing or this type .
   " new alpha ( ); " is run time means overriding is depend upon this thing or this type .

means overriding is depend upon dynamic selection it does not depend upon reference type .

means if  " beta ob1 = new alpha ( ); "
here if beta have a method display ( ); and alpha have a method display ( ) , not different in signature;
than making or creating display between these two is very hard in compile time .
so it first goes to " new alpha (  )" and finds that original object is of alpha type and assign all properties of alpha now all things are depend upon you that now you want to reduce it or you want to make them as a constant .

in overloading , methods are different in signature  , easily caught in compile time so it is heavily depend upon , simple or static binding .

concepts with overriding { private / final / static }

look java is famous for its topic inheritance ... and inside inheritance there is a most important topic called overriding .

if you search for  " overriding " in dictionary than the meaning is "Having superior's power "
so every thing in this text is related with this meaning now how ...

lets start ....
                 basically you can override anything from your parent ... but do you think that if parent does not allow you to override this than you can override those things ...
no ... is the answer .
but why no is the answer .
i will explain u why no is the answer .

if you know something about final , static ,private than this text is good for you otherwise go home and take a rest , and open kathy for java .
----------------------------------------------------------------------------------------------------------------------
final is a thing , which is declared as final . so it you can not override this method . but why , think that override means , a car has a gear_method ( ) , if you say that i want 6 gears in my car than ok ..you are changing it ... and making this method suitable for u .
and if i say that the value of PI in maths is 3.14 than can you change it .. no now you can not change it . but you can use it like " 3.14*r*r  " so this is the term final ..

means overrides means - change { but final cant change }
-----------------------------------------------------------------------------------------------------------------------
private is a thing where you define a signature for the thing ... so do you think that if you declare anything after it you can change it . answer is " long  no " . and private is a thing contains its signature for the whole class .. but not for inherited class ... the inherited class does not know that there is any method . because the scope of privte is only visible inside the class ..

means private looks like overrided but every private has a unique signature . so the answer is no private is never inherited
-----------------------------------------------------------------------------------------------------------------------
now the most confusing term static ...

take it easily and create the defination of static in your mind ..that static is a class type ... means visible to whole class as a single entity ... so when i am saying that visible to class means to only that class .
now ... static is also same as private in look and feel ... but deifferent in working ... it basically work on static binding or in compile time binding .. means it is necessary also .. why take this example .

Class_name     ob_name   =   new   Class_name   (  ) ;
      |
      |
      |______________________ so this class name is in use in static or compile time binding ..
but why ... so i am saying that it is visible to only that class ... and this thing is only provided by this thing ... because in the end of assigning reference you have to declare its  type ...

after this name ... is you access the method with overridden syntax than it will go to               class_name.method( );    so i think thats enough for basics related with final & static & private

brother difference between private and final ...

look i am with java ... and want to explain that private method are never in state of overridden ...

but why ... if i say ... that grandfather has a old dress and they built this dress only for him ... do you thik that after declaring this method as a private father is ready to wear or use this dress ...

so look at this code ....
public class Baseclass
{
    private void method()
    {
        System.out.println("base class called");
    }

    public static void main(String[] args)
    {
        Baseclass b = new Subclass();
        b.method();
    }
}

 class Subclass extends Baseclass
{
    protected void method()
    {
        System.out.println("sub class called");
    }
}


look if you say that private method also inherited than ... i will never support you ...
because private is defined for a class ... and if you make a same method in another class as private than you never face a problem and if you declare a method also as a public than u will never face a problem

means private class is only visible to its class .....
if you want to try or check .... that ,,, i am wrong than declare this baseclass method as a final and if it compiles than i am correct and if not than  i am wrong .

now its time to the output ...
                                              Baseclass b = new Subclass();
                                                             b.method();

what this statement says that first goes in Subclass for search of method() ,, if you not found that method than come in Baseclass and search here .... ok now you find the method () and o/p is  " base class " ....
nethod () is not found in subclass means ... because your method is private and thats why private method has it unique signature and thats why this method is not inherited in subclass ... but why the protected method is not used thats the question .....

but look the code closely ... because ...in the declaration of this syantx ... you are saying that ok i am providing all subclass properties but  + baseclass properties ... but at the compile time synatx ( baseclass b)  we are defining that we have a method so you have to access it ... means at the compile time means
you can only access those methods which are present in baseclass .. so in baseclass there is only private with unique signature ...thats why here protected method is not working ...

want to implement some best things with your computer   use this for improving your thinking about computer

brother difference between private and final ...

final & private ... in field of overriding ... they confused you too much .... now
every one knows the defination of final & private ..

final --- you can use me ... but you cant change me ...thats why i am final ....
private --- i m only visible inside a class ....

but why i am telling you these basic things ... because every big thing is built from basic concepts ...

people say that private method can inherited ... but we can not inherited final ... why ?

so the answer is .. private only allows you encapsulation ... means some protection ...thats why the private method has an signature ...and only visible inside a class .. if you declare an some method outside the class than no you found no error .. because the second method have its own unique signature ...

but what is the problem with final ... final says that ... if you want to declare me as a final then i want something that ... now you can not change me .... now you can only use me ....

changing means --- overriding
using means --- with the help of object just accessing it ( like toString() & instanceOf methods )

Tuesday 19 July 2011

look every thing is ok with older for loop ... but today everything is changing ....
so what is new in new for loop ...

now you are engineer .... so please call the new for loop as  " for   each " loop .

so what is good in this new for loop .
so start ... 1 . are you bored with increment thing in for loop  .
                2 . are you happy with size declaration .
                3 . are you happy with initialization .

if you are happy than stay and remain in older state  . if not than join me ... i will show you some goodness of java ...

for each loop presentation ...

for ( int x : array_ name )
 {
   ------------------
   ------------------
}

1.  question in your mind ... is it ok ... than you will try and it will perform correctly ...
2.  question in your mind ... its tough for me  ... and how this for loop finds the size ...
3.  and how this loop is incrementing ...

for every answer just open Iterate class .. there is a iterator mehtod ...

this method is used to incrementing ... and how to find the next value ....for this there is another method
hasNext() by the help of this method you can find the next element ... but how it initialize ....

for solving this ... the syntax play a important role ... ( int  x : array_name )  here "int x" the type with variable is necessary ....
so what this type do .... in this for each loop ....
we just find the next value and just copy it into " x " so after it we can easily use it ...

but in this world for every goodness there is a badness ... and this badness is also here .. so 

read carefully.... generally it works on original array 
                int [] arr = { 1 , 2 , 3 };
for( int x : arr )
{
System.out.println(x);
x++;
}
for( int y : arr )
{
System.out.println(y);
}
the output : 1,2,3;
                   1,2,3;

so you can call it also as a read only loop


Monday 18 July 2011

how the mighty JVM knows allocate space for array where constructor is not defined.

i want to ask a question to you that , we all are reading java from 3-4 years now explain me how space is allocate when you create a array .

                        int [ ] arr = new int [ 4 ] ;

tell me here how space is allocate when , there is no constructor ?

so i think for me . for today this is the best question for a learner . 

now i will provide solution to you . but please dont accept it as a final , because it is my opinion and always opinions are wrong in JAVA .

so lets start . when you define int  [ ] arr ;
at this time you say that .... hola i have a reference ... which is pointing to something which is group of same values .... you can call it a Array .

now if i say are you happy with it . if you are starter than you say .. ok  but i am not a starter i want to learn things provide me things . 

now the sentence i am saying that " i am learner and want something " this case is also allowed in case of array . but how is the question .

for this you have to read some the mighty concept of java .. the " new " 
when i write -----------------------------------------------------------------------------:" new int  [  ] "
what happen can you think .

for this dig into this part . whenever JVM finds new , the instruction for JVM is that now its to allocating something , but what than your syntax says that there is a int type of something , but do you think that this is ok , without asking syntax how much .
its like a example a requester goes into bank and say i need money , and the bank say to him sir please go to the store and take money from there , without asking his need .

so when we define syntax , it is necessary that defining the size also there .
now every thing is ok . but where is the topic's matter ,,, ya now my task is started ... read it carefully ...

when your array is initialized in heap , but the point is that everything is heap is in form of  '0' if you taking it . but surely now your question is that why ' 0 ' i dont want to provide any value .. but my boy 
here you will work for  java  and in its things ..not for me ,and not yourself .

so why this ... because in INTEGER class ,,, if you have a time , than please walk inside the integer class
there you find that it have a constructor where providing value is necessary . thats why if we dont provide value to our used thing than always it shows error that , value is not assigned .. but why this thing is related to array .

now you have a array with by default values ' 0 ' . 
so now its time for wrapping .
wrapping is used when you want to create a object means you are using heap , for space saving .
so for int you use a INTEGER class . now INTEGER is wrapped class of int . so what is the work of this INTEGER . 

listen i told you that , we have by default values with all ' 0 ' s .
so when i say that your array is holding 4 values  , and each of this value is 0 , at that time the INTEGER class takes this 0 with an int , to allocating the space , space allocation instruction comes from " new " so when the whole task is completed , means by iterating the array , because size is defined and here we use Iterator() & hasNext() method . for finding the next value of the next variable . 

so JVM  will allocate nearly 16 bytes for  4 values and thats all for this topic . and thanks to god to helping me in this topic & for creating these all different things in my mind ... and thanks to you for opening it ...and thanks to google for providing a way to expressing ....

some thing about array .

array the smallest but i think the hardest thing for a learner .
why ... in every question i am related with why ?

in java array is simply different from c .
first i want to explain array in c .

int a [4] : meaning of this line

you create a box ... inside this box you divide it into 4 parts ... now after dividing you say that these all are of int types ...
so you can say an int array generally ...or a primitive array ...
why i am saying primitive array ...

                              int                  a                     [4]
                                         array-name

now your array is type of int and in int every thing is int so these all values are int type .
thats why this is int array , or primitive array .

..........................now please come in my field and concentrate ,

in java ... you or sun are always different .. why ..
because you are from c level .. and they are still from mighty sun ..
now why they are different .
they remove your all wasting theory and put them into dustbin .
and ...
   for this they focus on memory

in c u did not focus on memory ..
why focus on memory .. because in java JVM takes 1/3 of ram ( physical memory ) in my laptop with 3 gb ram it takes nearly 980 mb .
so focusing on memory is necessary for java ..


now come in task .... the arrray .

int [] a = new int  [];
this is the syntax for saving memory in array .

so what is the meaning .

here int a [] is changed to int [] a why ..
look every thing in java have some reason ....

in java for saving memory we use object ....
so object is created in heap .. and when program ends the whole space allocated to object is cleared by garbage collector .


so what we do for it

     in java in reference variable we store the address of the first value in heap . means this is the starting index of array in heap ... so for this we only need starting index to accessing any thing .
and we provide it to  ' a '

now we did this task

int          [    ]               a                 =              new             int                   [ 4 ]
                          ref-name


when we say that new is their than every thing relating it will be the part of heap . when JVM finds new at that time JVM say to new that allocated some space for the array . and it allocate the space . and then
it says to int [ 4 ] that install or fill the allocated space .

now a question can arise in your mid that why .. when you create a array in a heap than there shold be nothing in the array .. and your reference varible is not showing any error that variable is not initialzed

for this question the answer is explained previously that , we provide reference in the form of  r-value to it . r-value means that right value of variable is assigned to reference varibale thats why it is not showing any error

so till now  ...  every thing is clear to new now when new finds that every thing is clear ... than it gives the address to reference variable ...

so after this whole process their is array ... with default values which is 0 for all integers ...