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 6 of 6

Thread: Import if Import is Found, Else

  1. #1
    Junior Member
    Join Date
    Mar 2013
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question Import if Import is Found, Else

    Hey, I am very new to Java. And I am coding a simple modification for Minecraft. Now I am gonna try to explain without the knowlegde of Minecraft and with.

    Basic Java: I want an import to import if its find the package that is set to import, else to make a new final static...

    In Minecraft: I want to make a new item if it doesnt find the mod I want to import the same item from...

    How do I do that? ifs and elses

    Did you understand that...? As I said, VERY NEW TO JAVA


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: Import if Import is Found, Else

    Are you talking about the import statement? It is used to tell the compiler what packages classes are in.
    It saves the coder from having to code the full classname including the package name.

    Otherwise please explain what you mean by "import".
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Junior Member
    Join Date
    Mar 2013
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Import if Import is Found, Else

    In Minecraft coding you import packages from the game, Minecraft itself thats in the Java project.

    Example:
    import net.minecraft.item.Item;
    Thats one of the import you can use in Minecraft coding

    You put "import (package)" in the top of the class...

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: Import if Import is Found, Else

    Do you understand what import statements are for?
    What are your questions now?
    If you don't understand my answer, don't ignore it, ask a question.

  5. #5
    Junior Member
    Join Date
    Mar 2013
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Import if Import is Found, Else

    I think so, to dont need to copy/write all classes in a package over, or to refer to some other Java. Isnt it?

    Well my question is,
    Is it possible to "if" an "import", so if it finds the referred/imported package it does whats in the "if", else it does whats in an "else"...

    import package.package;
     
    public class Class {
    if (IDontKnowWhatToBeHere){
    ItemStack sandStack = new ItemStack(Item.TheItem, 1);
    }
    else (StillDontKnowWhatToBeHere) {
     public final static Item TheItem = new TheItem(9238)
            	.setItemName(TheItem);
    }
    }

    While imported a lot of other packages though of course, I dont know if this even is possible. But what does the code do if it doesn't find the package that the import is refferred to? And what to be in "(IDontKnowWhatToBeHere)" and "(StillDontKnowWhatToBeHere)"? Do I need to creat a new boolean that checks if the code is resolved or does it exists something for this already?

  6. #6
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: Import if Import is Found, Else

    Is it possible to "if" an "import"
    That question doesn't make sense. import statements allow the code to be written without adding the package name.
    There is no requirement to use import statements. Most, maybe all, code can be written without using any import statements.

    But what does the code do if it doesn't find the package that the import is refferred to
    Try writing a small program with an import statement for a package that does not exist. The compiler will tell you that it can not find the package.
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. import question
    By bardd in forum Java Theory & Questions
    Replies: 1
    Last Post: November 20th, 2010, 09:27 AM
  2. [SOLVED] Iterator next import class?
    By daydreamer in forum What's Wrong With My Code?
    Replies: 5
    Last Post: October 3rd, 2010, 04:51 AM
  3. Something wrong with the import things
    By mingming8888 in forum What's Wrong With My Code?
    Replies: 3
    Last Post: August 25th, 2010, 07:30 AM
  4. from where i should import
    By javaking in forum Java SE APIs
    Replies: 0
    Last Post: April 12th, 2010, 07:51 AM
  5. [SOLVED] Do i need to import anything here?
    By straw in forum What's Wrong With My Code?
    Replies: 4
    Last Post: March 6th, 2010, 06:42 PM

Tags for this Thread