Netbeans

Discussion in 'Scripting & Programming' started by zxspectrum, Dec 17, 2009.

  1. zxspectrum

    zxspectrum Terabyte Poster Forum Leader Gold Member

    2,092
    216
    244
    We have started using netbeans 6.8 for java programming in uni and as im slowly getting used to it i have a question that for some reason the tutor likes to avoid answering, and all i get is look in the book, but i dont have a book for netbeans which ive told her, basically we keep going round in circles

    When we open a new project we have to uncheck a box that says, create main class, and then this will be called what ever name we choose, for this purpose well call it myfirstproject , etc.

    So what does unchecking that actually do, am i right in thinking that i need to have other separate classes for my project to work. Or does it create a running issue if i dont uncheck the box???

    Thanks

    Ed
     
    Certifications: BSc computing and information systems
    WIP: 70-680
  2. ericrollo

    ericrollo Megabyte Poster

    524
    11
    64
    Well everything is a class in VB.net and the main class would probably be the sub main which is where the program "starts". In this instance it may create the main class and call it myfirstproject instead of main.

    I dont really know it could be something to do with accessing methods as well.
     
    Last edited: Dec 17, 2009
    Certifications: MOS Master, A+, MCP 271
    WIP: HND, Programming, Another Job
  3. MLP

    MLP Kilobyte Poster

    305
    19
    59
    If memory serves me correctly, the Main project is the one that fires up first when the app runs. It normally looks something like:
    Code:
    public class MyProj
             {
                   public static void main(String[]args)
                   {
                          //Some code goes here - poss. firing off other classes etc
                   }
             }
    
    My java is really, really rusty.

    Maria
     
    Certifications: HND Computing
  4. ericrollo

    ericrollo Megabyte Poster

    524
    11
    64
    I have actually learned something doing programming!!
     
    Certifications: MOS Master, A+, MCP 271
    WIP: HND, Programming, Another Job
  5. dmarsh
    Honorary Member 500 Likes Award

    dmarsh Petabyte Poster

    4,305
    503
    259
    It will be wizard style code generation functionality specific to netbeans.

    As mentioned all code in Java resides inside a class as its a fairly 'pure' object orientated language.

    Each class can choose to implement a main method if it likes, this provides a program entry point, in other words the first method that the java runtime calls to start your program. Most languages have a similar system of an entry point and in C style languages its commonly called main.

    The wizard could do other things depending on the project type like create a jar and manifest and put the name of the start class into the manifest.

    IDE's normally have loads of documentation and theres also loads on the web.

    http://leepoint.net/notes-java/tools/netbeans/netbeans.html

    Basically IDE's sometimes try to be overly helpful, its important to understand what your IDE is doing for you in case one day it goes wrong...
     
    Last edited: Dec 18, 2009
  6. soundian

    soundian Gigabyte Poster

    1,460
    71
    107
    As far as I can figure out, if you create a main class, you won't be able to run individual classes as files until they're associated with the main class*. It's an IDE thing rather than a Java thing.



    *Even then I think it runs the main class. Maybe you should experiment.
    This is one of the reasons why I recommend getting a reasonably firm grasp of a language before using IDEs.
     
    Last edited: Dec 18, 2009
    Certifications: A+, N+,MCDST,MCTS(680), MCP(270, 271, 272), ITILv3F, CCENT
    WIP: Knuckling down at my new job
  7. dmarsh
    Honorary Member 500 Likes Award

    dmarsh Petabyte Poster

    4,305
    503
    259
    Well i'm not a fan of netbeans as I use Eclipse, but there should be no reason stopping you putting a main method in all classes if you wanted.

    By configuring the IDE correctly you should be able to compile and debug all these classes either together or seperately.

    In reality there is no such thing as a 'main class' only a main method.

    There is a start class which is the class chosen by the runtime to start in, this is either performed on the command line as in :-

    Code:
    java StartClass arg1 arg2 
    or can be performed in other manners such as a jar with a manifest.

    The start class must have a main method. This applies to both console and swing apps. If you are working with other frameworks or middleware or IOC containers etc, you application lifecycle and entry points can be different.

    Again however there could be multiple start classes if you are using the command line to specify the start class.

    Its just convenience for you, it looks like the wizard creates a workspace, with a default project and default project settings. Sometimes the defaults are what you want, sometimes not...

    A lot of programmers view code generation as evil, the truth is a little more complex. Ruby restarted the debate with convention over configuration.
     
    Last edited: Dec 18, 2009
  8. LordMoolyBap

    LordMoolyBap Nibble Poster

    95
    0
    28
    I think the main class and I assume subsequently the Main method would be the ones it would automatically create (in a console app anyway, not sure about a Swing app) and set as the startup method. If you untick and create your own it is basically making the class you choose to be the start up class instead.

    I haven't really looked at Netbeans before except briefly a couple of years ago but that seems the sensible thing to happen.

    Dom
     
    Certifications: HND (Comp) MBCS
    WIP: Msc Intelligent Systems

Share This Page

Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.