fact about java

I came to know that when we compile a program without any constructor then a default constructor or a blank constructor is created at the run-time itself by a compiler.But if we create any of the constructor then this complier is not going to create ant default constructor.

To see that default constructor created by the compiler at the time of compilation is
javap -
Use the above command after compiling and interpreting the program.
Those who know this is fine but those who do not know just type this command and see a default constructor is created itself by the compiler.
You will see a default constructor is created before the main() method and those lines of codes are in assembly language.

But i want know that why this default constructor is created at the time of compilation by the compiler only if we do not define any form of constructor in the class definition before the main() method ?

Replies

  • sushant005
    sushant005
    There is a correction,

    after compiling the java program if we write javap -c
    the above code will give the idea about the constructor execution and before the main() method a default constructor is created by the compiler itself if no constructor is being defined by the user/programmer.
    And the code appear in the command prompt. will be in assembly code.
    In case of inheritance after executing the program write javap -c and the process of execution of program how a class is extended.
  • anandkumarjha
    anandkumarjha
    hello sushant
    so far as i know this default constructor is being created during compilation of java so as to destroy all the values of previous program.Although i am not sure .let me search it out
  • sushant005
    sushant005
    @anandkumar
    please justify your answer/comment.

    After lots of thinking i reached to the point that to initialized the object an default constructor is create by the compiler if no constructor is defined by the user.
    But we know that we make main() method static if no no object is created but in this case a default constructor is created is created which automatically create and initialized an object which is used to access the members of class.

    I do not know up to which point i am correct please do me correct if i am wrong at any point.
  • Leo
    Leo
    Hey buddy javap have nothing to do with use of constructor. javap is Java bytecode disassembler, all you see after using this command is execution of working bytecode.
  • anandkumarjha
    anandkumarjha
    hey leo....are you trying to say that default constructor is not being created while compilation of the java program??
  • Leo
    Leo
    No i want to say javap is Java byte-code disassembler and had to do nothing with above constructor discussion.
  • gavinol
    gavinol
    Java is a very ideal platform for network computing. This is one of the best & all-rounder known technology that is used from servers to cell phones to smart cards... If you don't define a constructor for a class, a default parameterless constructor is automatically created by the compiler.


  • xxxabhash007
    xxxabhash007
    Java follows UNICODE.
  • Morningdot Hablu
    Morningdot Hablu
    public class r
    {
    //public r();//you must need this to initialise the class r so this is why "r()" is bydefault.
    public static void main(String args[])
    {
    int x=2;
    System.out.println(x);
    }
    }
    One more thing javap is the command which display all the members of class and constructors used in the public class.
  • sushant005
    sushant005
    Leo
    No i want to say javap is Java byte-code disassembler and had to do nothing with above constructor discussion.
    I know that javap is nothing to do with the constructor creation.It is just a command which shows that a default constructor is created by the complier only if no constructor is defined in the class definition.
    My actual question why a default constructor is created?
  • anandkumarjha
    anandkumarjha
    sushant005
    I know that javap is nothing to do with the constructor creation.It is just a command which shows that a default constructor is created by the complier only if no constructor is defined in the class definition.
    My actual question why a default constructor is created?
    Because for operation of the actual class atleast one constructor is required so if you dont mention any of the constructor then while compilation it will create its default constructor.as far as creation of constructor is concerned we must be knowing that it initialises the variable and without initialise of variable we can't access them,so default constructor is being created

You are reading an archived discussion.

Related Posts

Hi, I have CMOS camera that the output is NTSC or PAL. I want to interface with PIC. Did anyone know how to connect that? Maybe it have a chip...
Source: Email from DimDim Better Video. As soon as you start a meeting, you'll notice the video broadcaster has gotten a lot bigger and better. The host can broadcast their...
Software engineers are obviously attracted towards Facebook - now the world's biggest social network; and lot of Google's talented employees have obtained offers from Facebook. Google's making counter offers to...
In India, there are about 550 million mobile phone users and only about 50 million web users. SMS GupShup - a mobile social network started in 2007 has over 35...
CEan MayurPathak celebrates his birthday today. Let's wish him many happy returns of the day and hope he returns to CE ๐Ÿ˜› ๐Ÿ˜๐Ÿ˜๐Ÿ˜๐Ÿ˜ Happy Birthday Mayur ๐Ÿ˜๐Ÿ˜๐Ÿ˜๐Ÿ˜