Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 5 of 5

Thread: First line of Java Programming- package help

  1. #1
    Junior Member
    Join Date
    Mar 2011
    Location
    VA
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default First line of Java Programming- package help

    Alright I am using Netbeans IDE 6.9.1

    When I start a new project I get very lil code on the right hand side.

    The very first line (of actual code, not the comments) is package javaapplication11;

    Now I am watching/reading/listening to some tuts on youtube. The person on youtube is using Eclipse and can just go straight to typing

    public class Main{}

    I want to be able to just do that. Go straight to typing class so I can follow along with the tuts. But if I take out the package statement it wont let me continue.

    Says missing package statement.

    Am I just completely overlooking something?

    I know this is a really really basic question that may be easy to most of you but like I said Im just learning this stuff.

    Any help greatly appreciated it.

    Oh and hello to all of you lol.


  2. #2
    Banned
    Join Date
    May 2010
    Location
    North Central Illinois
    Posts
    1,631
    My Mood
    Sleepy
    Thanks
    390
    Thanked 112 Times in 110 Posts

    Default Re: First line of Java Programming- package help

    That line means it's part of a package. You may run into problems if you remove that as it might not recognize stuff that might be in other classes that the tutorial might be using that are in that package.

  3. #3
    Junior Member
    Join Date
    Mar 2011
    Location
    Bangalore
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: First line of Java Programming- package help

    In any IDE, when you write java class. your first line of code is package, but it need not be necessary. once you started writing your java class and inside that if you are trying to write the code which required some specific package, then you have to declare untill then not required.

    for your information java.lang is default package.

    Note: if you are writing your java class in any private folder then you have declare the package accordingly.

    Thanks
    Motilal

  4. #4
    Junior Member
    Join Date
    Jun 2013
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: First line of Java Programming- package help

    package is a kind of folder in which your program is being stored. So Eclipse on your computer has created a 'folder' named "javaapplication11" when you created a new project, while the one in the tutorial video is using the 'default package' which need not be mentioned in the program. Packages create no complexity so don't be scared of them. Just see how these folders are arranged In Eclipse go to Windows>Show View>Package Explorer. In the package explorer window click {your_project} >src>javaapplication11 ... here it is... inside it is your class file. packages help avoid name clash of the "Titans"... oopsie... "Classes"

  5. #5
    Super Moderator jps's Avatar
    Join Date
    Jul 2012
    Posts
    2,642
    My Mood
    Daring
    Thanks
    90
    Thanked 263 Times in 232 Posts

    Default Re: First line of Java Programming- package help

    Welcome iNoshift

    My advice is to use the same IDE as the tutorial you are following, for the following reasons.
    1 Knowing more than one IDE will not kill you
    2 Knowing more than one IDE will actually benefit you (versatility as well as a better understanding of java from the 3rd person perspective)
    3 Following the tutorial will prove much easier (this is the reason that ultimately led to this post it seems)

Similar Threads

  1. Is it possible to package Java
    By UnderWater2 in forum Java Theory & Questions
    Replies: 1
    Last Post: November 2nd, 2010, 01:31 AM
  2. how do you leave a line space in java?
    By ss7 in forum Java Theory & Questions
    Replies: 7
    Last Post: November 5th, 2009, 08:20 AM
  3. Serail Port Programming regarding phone line hook
    By maskey_dipesh in forum Java SE APIs
    Replies: 2
    Last Post: September 4th, 2009, 05:12 AM
  4. Reading a file line by line using the Scanner class
    By JavaPF in forum File Input/Output Tutorials
    Replies: 0
    Last Post: April 17th, 2009, 07:34 AM
  5. How to Read a file line by line using BufferedReader?
    By JavaPF in forum File Input/Output Tutorials
    Replies: 0
    Last Post: May 19th, 2008, 06:32 AM