Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8483309
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T20:03:58+00:00 2026-06-10T20:03:58+00:00

I wanted to make a Java tutorial website for my final year project. The

  • 0

I wanted to make a Java tutorial website for my final year project. The website would ask the user a question and they would write the java code into a form.

What I cant figure out is how to compile the code that has been submitted. Should I write my own test cases in PHP or is there a way to get a java compiler that will run on a web host like hostmonster? Any suggestions welcome.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T20:03:59+00:00Added an answer on June 10, 2026 at 8:03 pm

    Have a look at the JavaCompiler class:

    import java.lang.reflect.Method;
    import java.net.URI;
    import java.util.Iterator;
    import java.util.NoSuchElementException;
    
    import javax.tools.JavaCompiler;
    import javax.tools.JavaFileObject;
    import javax.tools.SimpleJavaFileObject;
    import javax.tools.ToolProvider;
    
    public class CompileString {
      public static void main(String[] args) throws Exception {
        JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
        String program = "class Test{" + "   public static void main (String [] args){"
            + "      System.out.println (\"Hello, World\");"
            + "      System.out.println (args.length);" + "   }" + "}";
    
        Iterable<? extends JavaFileObject> fileObjects;
        fileObjects = getJavaSourceFromString(program);
    
        compiler.getTask(null, null, null, null, null, fileObjects).call();
    
        Class<?> clazz = Class.forName("Test");
        Method m = clazz.getMethod("main", new Class[] { String[].class });
        Object[] _args = new Object[] { new String[0] };
        m.invoke(null, _args);
      }
    
      static Iterable<JavaSourceFromString> getJavaSourceFromString(String code) {
        final JavaSourceFromString jsfs;
        jsfs = new JavaSourceFromString("code", code);
        return new Iterable<JavaSourceFromString>() {
          public Iterator<JavaSourceFromString> iterator() {
            return new Iterator<JavaSourceFromString>() {
              boolean isNext = true;
    
              public boolean hasNext() {
                return isNext;
              }
    
              public JavaSourceFromString next() {
                if (!isNext)
                  throw new NoSuchElementException();
                isNext = false;
                return jsfs;
              }
    
              public void remove() {
                throw new UnsupportedOperationException();
              }
            };
          }
        };
      }
    }
    
    class JavaSourceFromString extends SimpleJavaFileObject {
      final String code;
    
      JavaSourceFromString(String name, String code) {
        super(URI.create("string:///" + name.replace('.', '/') + Kind.SOURCE.extension), Kind.SOURCE);
        this.code = code;
      }
    
      public CharSequence getCharContent(boolean ignoreEncodingErrors) {
        return code;
      }
    }
    

    The above compiles a String containing Java source and executes it
    for more see: JavaCompiler Turorials – Java2s

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm studying Java. And i wanted to make the code for checking a 2D
I wanted to make a Java based web crawler for an experiment. I heard
I wanted to make a post request in this website: http://www.prezup.info/index.php?page=films in order to
I wanted to make a button which is transparent until the user hovers over
I wanted to make a simple parser, for a pseudo code like language(kept rigid),
I wanted to make sure about something in Java: If I have a Character
I wanted to write a timer in java.which will do the following: when program
I'm fairly new to Android/Java and wanted to make an app that displays info
I wanted to make Map of Collections in Java, so I can make something
I wanted to make a facebook application in java using servlets and JSP.But as

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.