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

Thread: #ifdef in Java?

  1. #1
    Junior Member
    Join Date
    Aug 2014
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default #ifdef in Java?

    Hello,

    Is there any kind of conditional compilation in Java? Like there is #ifdef / #endif in C - anything like that in Java?

    Thanks,
    Jamie

    p.s. This is my first real post here; hope it's not breaking any rules or etiquette...


  2. #2
    Senior Member
    Join Date
    Jul 2013
    Location
    Europe
    Posts
    567
    Thanks
    0
    Thanked 103 Times in 88 Posts

    Default Re: #ifdef in Java?

    There is none.
    What would you use that for in java? It seems rather pointless to me.

  3. #3
    Forum VIP
    Join Date
    Jul 2010
    Posts
    1,657
    Thanks
    25
    Thanked 325 Times in 302 Posts

    Default Re: #ifdef in Java?

    Took a look at this. The wikipedia article (Conditional compilation - Wikipedia, the free encyclopedia) states:
    This technique is commonly used when these differences are needed to run the software on different platforms, or with different versions of required libraries or hardware.
    Due to Java's "write once, run everywhere" nature, worrying about differences in platforms is almost never needed (with a handful of exceptions, which can usually be resolved by making a call to one of Java's utility classes).
    NOTE TO NEW PEOPLE LOOKING FOR HELP ON FORUM:

    When asking for help, please follow these guidelines to receive better and more prompt help:
    1. Put your code in Java Tags. To do this, put [highlight=java] before your code and [/highlight] after your code.
    2. Give full details of errors and provide us with as much information about the situation as possible.
    3. Give us an example of what the output should look like when done correctly.

    Join the Airline Management Simulation Game to manage your own airline against other users in a virtual recreation of the United States Airline Industry. For more details, visit: http://airlinegame.orgfree.com/

  4. #4
    Member jdv's Avatar
    Join Date
    Jul 2014
    Location
    This Land
    Posts
    59
    Thanks
    0
    Thanked 4 Times in 4 Posts

    Default Re: #ifdef in Java?

    Quote Originally Posted by mrqwak View Post
    Hello,

    Is there any kind of conditional compilation in Java? Like there is #ifdef / #endif in C - anything like that in Java?
    Not in the same way, because there isn't a preprocessor (which is the thing that actually reads the #ifdef lines, replacing them with valid C before passing them onto the compiler) like there is for a C toolchain.

    However, see here: Java Practices -> Conditional compile