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: JAVA- .class to .java

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

    Default JAVA- .class to .java

    hello everyone,

    i'm new to computer science and i was challenged by one of my friends to find out the right code for a class file he gave me.

    I have done some work on it but just need your help, this is not a homework assignment, its just for fun

    if i'm thankful for anyone who helps me

    this is my code

    public class Tpi
    {
        private static final class Mode extends Enum
        {
     
    	private enum Mode
    	{
    		UNKNOWN, COMPILE, INTERPRET
    	}
            private static final Mode $VALUES[];
     
            public static Mode[] values()
            {
                return (Mode[])$VALUES.clone();
            }
     
            public static Mode valueOf(String s)
            {
                return (Mode)Enum.valueOf(Tpi$Mode, s);
            }
     
            static 
            {
                UNKNOWN = new Mode("UNKNOWN", 0);
                COMPILE = new Mode("COMPILE", 1);
                INTERPRET = new Mode("INTERPRET", 2);
                $VALUES = (new Mode[] {
                    UNKNOWN, COMPILE, INTERPRET
                });
            }
     
            private Mode(String s, int i)
            {
                super(s, i);
            }
        }
     
     
        private static final int version = 1;
        private boolean success;
        private String sourceFile;
        private String destinationFile;
        private Mode mode;
        private static final String expectedSourceFileSuffix = ".p";
        private static final String destinationFileSuffix = ".s";
     
        public static void main(String args[])
        {
            Tpi tpi = new Tpi(args);
        }
     
        private Tpi()
        {
        }
     
        public Tpi(String as[])
        {
            success = false;
            mode = Mode.UNKNOWN;
            if(!decodeCommandLine(as))
            {
                return;
            } else
            {
                Parser parser = new Parser(sourceFile);
                success = parser.isSuccessful();
                return;
            }
        }
     
        public boolean isSuccessful()
        {
            return success;
        }
     
        private boolean decodeCommandLine(String as[])
        {
            String s;
            int i = ".p".length();
            System.out.println("Tpi version 1");
            if(as.length != 2)
            {
                System.out.println("Invalid number of arguments.");
                explainArguments();
                return false;
            }
            sourceFile = as[1];
            if(sourceFile.length() < i + 1 || !".p".equals(sourceFile.substring(sourceFile.length() - i)))
            {
                System.out.println("sourcefile must end with .p");
                explainArguments();
                return false;
            }
            s = as[0];
            if(!s.equals("-C"))
            {
                break
            }
            destinationFile = sourceFile.substring(0, sourceFile.length() - i);
            new StringBuilder();
            this;
            destinationFile;
            ".s";
            toString();
            destinationFile;
            mode = Mode.COMPILE;
            System.out.println(new StringBuilder() + "Compiling " + sourceFile + " to " + destinationFile);
            break
            if(s.equals("-I"))
            {
                mode = Mode.INTERPRET;
                System.out.println((new StringBuilder()).append("Interpreting ").append(sourceFile).toString());
            } else
            {
                System.out.println("Invalid mode.");
                explainArguments();
                return false;
            }
            return true;
        }
     
        private void explainArguments()
        {
            System.out.println("Usage: java Tpi mode sourcefile.p");
            System.out.println("where mode is one of the following:");
            System.out.print("-C compiles sourcefile.p");
            System.out.println(", writing assembly code to sourcefile.s");
            System.out.println("-I interprets the contents of sourcefile.p");
        }
    }

    and i have attached the class file.


    Thanx
    Attached Files Attached Files


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

    Default Re: JAVA- .class to .java

    Can Anyone HELP?!

  3. #3
    Member
    Join Date
    Mar 2010
    Posts
    271
    Thanks
    21
    Thanked 7 Times in 7 Posts

    Default Re: JAVA- .class to .java

    Sorry I'm new too, and I got no clue what that means or dose. lol

    Welcome to the Forums!!

  4. #4
    Super Moderator Json's Avatar
    Join Date
    Jul 2009
    Location
    Warrington, United Kingdom
    Posts
    1,274
    My Mood
    Happy
    Thanks
    70
    Thanked 156 Times in 152 Posts

    Default Re: JAVA- .class to .java

    Have a look at javap - The Java Class File Disassembler or something like JD | Java Decompiler

    // Json

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

    Default Re: JAVA- .class to .java

    okay, thank you so much for your help, it is much better than before

    thanx

Similar Threads

  1. How to Sendkeys to an application in Java using the Robot Class
    By JavaPF in forum Java SE API Tutorials
    Replies: 6
    Last Post: August 4th, 2011, 12:13 AM
  2. run java class file from independent of OS
    By starsoheil in forum Java Theory & Questions
    Replies: 6
    Last Post: March 16th, 2010, 08:05 AM
  3. Need help compiling java class files
    By peahead in forum What's Wrong With My Code?
    Replies: 5
    Last Post: February 11th, 2010, 09:04 AM
  4. Java Locked Class
    By unstoppable3 in forum What's Wrong With My Code?
    Replies: 0
    Last Post: January 29th, 2010, 03:17 PM
  5. [SOLVED] How to call string in another class in java?
    By tazjaime in forum What's Wrong With My Code?
    Replies: 4
    Last Post: April 23rd, 2009, 09:31 AM