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

Thread: Skip code to compile.

  1. #1
    Member
    Join Date
    Jan 2013
    Posts
    57
    Thanks
    9
    Thanked 0 Times in 0 Posts

    Default Skip code to compile.

    Hello guys again!

    I just want to know if is possible to compile code skiping part of that code in eclipse.

    Example (I dont want eclipse to compile what is after ***):


    //By Mike Liberato, 2013.
     
    import java.util.Scanner;
    import java.text.NumberFormat;
     
    public class CalculateSalePrice {
     
    	public static void main(String[] args) {
     
    		double iprice, poff, sprice, asaved;
     
    		Scanner scan = new Scanner (System.in);
     
    		NumberFormat fmt = NumberFormat.getCurrencyInstance();
     
    		System.out.print("Enter item price: ");
    		iprice = scan.nextDouble();
     
    		System.out.print ("Percent off: ");
    		poff = scan.nextDouble();
     
    		asaved = (double) (iprice*poff/100);
    		sprice = (double) (iprice-asaved);
    		System.out.println ("Sale price: " + fmt.format(sprice));
    		System.out.print("Amount saved: " + fmt.format(asaved));
     
    ***asaved = (double) (iprice*poff/100);
    		***sprice = (double) (iprice-asaved);
    		***System.out.println ("Sale price: " + fmt.format(sprice));
    		***System.out.print("Amount saved: " + fmt.format(asaved));
    	}
     
    }

    So if I de-compile my code those lines are not going to be in the compiled file, but the code is istill going to be in my project...

    Hope, that you guys understand. Thanks.


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    21,824
    Thanks
    55
    Thanked 2,344 Times in 2,315 Posts

    Default Re: Skip code to compile.

    I dont want eclipse to compile what is after ***)
    Wrap that code in a comment using /* and */
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Member
    Join Date
    Jan 2013
    Posts
    57
    Thanks
    9
    Thanked 0 Times in 0 Posts

    Default Re: Skip code to compile.

    So the code between the /* and */ wont be compiled into the "Executable Jar File" (which is how I am compiling it)?

  4. #4
    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: Skip code to compile.

    Correct.
    Comments are only included if you include the source code when you make the jar

  5. The Following User Says Thank You to jps For This Useful Post:

    JosPhantasmE (May 10th, 2013)

  6. #5
    Member
    Join Date
    Jan 2013
    Posts
    57
    Thanks
    9
    Thanked 0 Times in 0 Posts

    Default Re: Skip code to compile.

    Ohh okay.

    And how do I exactly check if I'm compiling it with the source code included?

  7. #6
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    21,824
    Thanks
    55
    Thanked 2,344 Times in 2,315 Posts

    Default Re: Skip code to compile.

    Can you try giving some more details about what you are trying to do?
    What does "source code included" mean?
    The contents of the .class file created by the javac compiler can tell you what source was included in the compile step when the class file is executed. For example a call to the println method will print showing that the println statement was in the source that was compiled.
    If you don't understand my answer, don't ignore it, ask a question.

  8. #7
    Member
    Join Date
    Jan 2013
    Posts
    57
    Thanks
    9
    Thanked 0 Times in 0 Posts

    Default Re: Skip code to compile.

    When I export my project to an executable Jar file: (example.jar) its content will be example.class and the META-INF and org folder.

    So my question is, the comments that are between /* and */ will not be in the example.class file?? So if somebody manage to de-compile that class file, they wont have access to my comments.?

  9. #8
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    21,824
    Thanks
    55
    Thanked 2,344 Times in 2,315 Posts

    Default Re: Skip code to compile.

    if somebody manage to de-compile that class file, they wont have access to my comments.
    That is correct.
    If you don't understand my answer, don't ignore it, ask a question.

  10. The Following User Says Thank You to Norm For This Useful Post:

    JosPhantasmE (May 10th, 2013)

  11. #9
    Member
    Join Date
    Jan 2013
    Posts
    57
    Thanks
    9
    Thanked 0 Times in 0 Posts

    Default Re: Skip code to compile.

    Perfect, thank you.

Similar Threads

  1. Why does this code compile?
    By prasanna1157 in forum What's Wrong With My Code?
    Replies: 5
    Last Post: December 29th, 2012, 04:27 PM
  2. How to skip and read lines in txt file
    By saran123 in forum File I/O & Other I/O Streams
    Replies: 1
    Last Post: December 26th, 2012, 08:07 AM
  3. Code won't compile
    By JavaChallenged in forum What's Wrong With My Code?
    Replies: 6
    Last Post: February 12th, 2012, 08:18 PM
  4. Code won't compile, but can't find the error....
    By RockDoc in forum What's Wrong With My Code?
    Replies: 1
    Last Post: January 29th, 2012, 02:09 AM
  5. Codes skip some lines??
    By bczm8703 in forum What's Wrong With My Code?
    Replies: 1
    Last Post: March 21st, 2011, 09:39 AM