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 8249991
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T23:43:56+00:00 2026-06-07T23:43:56+00:00

I will have to be using JavaCompilers in the near future so I am

  • 0

I will have to be using JavaCompilers in the near future so I am trying to learn about the basics now and choose the best one to learn and I have come across a question that i could not really fine an answer to online

At the moment im looking at the JavaCompiler. If i have a program X being evaluated and it takes input from System.in and prints output to System.out,
can I compile and run it while feeding it some specific input and capturing it’s output in a file?

If so, is there any examples online so i can try understand it a bit better?

EDIT:

Simple Test case to pass in while compiling

import java.util.Iterator;

public class TestSet
{
public static void main(String[] args)
{
  try
  {
     System.out.print(   "[1]--constructor 1, size, isEmpty: ");
     LinkedSet<String> s1 = new LinkedSet<String>();
     if (s1.size() != 0)
        System.out.print("*** size? ***");
     if (!s1.isEmpty())
        System.out.print("*** isEmpty? ***");
     System.out.println();
  }
  catch(Exception e)
  {
     System.out.println("*** CRASH !!! ***");
  }
  try
  {
     System.out.print(   "[2]--constructor 2, size, isEmpty: ");
     LinkedSet<String> s1 = new LinkedSet<String>( "alpha");
     if (s1.size() != 1)
        System.out.print("*** size? ***");
     if (s1.isEmpty())
        System.out.print("*** isEmpty? ***");
     System.out.println();
  }
  catch(Exception e)
  {
     System.out.println("*** CRASH !!! ***");
  }
  try
  {
     System.out.print(   "[3]--contains: ");
     LinkedSet<String> s1 = new LinkedSet<String>("alpha");
     if (!s1.contains("alpha"))
        System.out.print("*** elt. not found ***");
     if (s1.contains("beta"))
        System.out.print("*** non-elt ``found'' ***");
     System.out.println();
  }
  catch(Exception e)
  {
     System.out.println("*** CRASH !!! ***");
  }
  try
  {
     System.out.print(   "[4]--add: ");
     LinkedSet<String> s1 = new LinkedSet<String>();
     s1.add("alpha");
     s1.add("beta");
     s1.add("gamma");
     if (s1.size() != 3)
        System.out.print("*** size? ***");
     if (!s1.contains("alpha") ||
        !s1.contains("beta") ||
        !s1.contains("gamma"))
        System.out.print("*** elt. not found ***");
     if (s1.contains("delta"))
        System.out.print("*** non-elt ``found'' ***");
     s1.add("beta");
     if (s1.size() != 3)
        System.out.print("*** size/duplicates? ***");
     System.out.println();
  }
  catch(Exception e)
  {
     System.out.println("*** CRASH !!! ***");
  }
  try
  {
     System.out.print(   "[5]--remove: ");
     LinkedSet<String> s1 = new LinkedSet<String>();
     s1.add("alpha");
     s1.add("beta");
     s1.add("gamma");
     s1.remove("beta");
     s1.remove("alpha");
     s1.remove("gamma");
     if (s1.size() != 0)
        System.out.print("*** size? ***");
     if (s1.contains("alpha") ||
        s1.contains("beta") ||
        s1.contains("gamma"))
        System.out.print("*** non elt. ``found'' ***");
     System.out.println();
  }
  catch(Exception e)
  {
     System.out.println("*** CRASH !!! ***");
  }
  try
  {
     System.out.print(   "[6]--print: ");
     LinkedSet<String> s1 = new LinkedSet<String>();
     s1.add("this");
     s1.add("is");
     s1.add("assignment");
     s1.add("four");
     s1.print();
  }
  catch(Exception e)
  {
     System.out.println("*** CRASH !!! ***");
  }
  try
  {
     System.out.print(   "[7]--addAll: ");
     LinkedSet<String> s1 = new LinkedSet<String>();
     s1.add("alpha");
     s1.add("beta");
     s1.add("gamma");
     LinkedSet<String> s2 = new LinkedSet<String>();
     s2.add("beta");
     s2.add("delta");
     s1.addAll(s2);
     if (!s1.contains("alpha") || ! s1.contains("beta") ||
        !s1.contains("gamma") || !s1.contains("delta"))
        System.out.print("*** elt. ``dropped'' ***");
     if (s1.size() != 4)
        System.out.print("*** size ? ***");
     System.out.println();
  }
  catch(Exception e)
  {
     System.out.println("*** CRASH !!! ***");
  }

  try
  {
     System.out.print(   "[8]--containsAll: ");
     LinkedSet<String> s1 = new LinkedSet<String>();
     s1.add("alpha");
     s1.add("beta");
     s1.add("gamma");
     LinkedSet<String> s2 = new LinkedSet<String>();
     s2.add("beta");
     s2.add("delta");
     if (s1.containsAll(s2))
        System.out.print("*** non-containment incorrect ***");
     LinkedSet<String> s3 = new LinkedSet<String>();
     s3.add("beta");
     s3.add("alpha");
     if (!s1.containsAll(s3))
        System.out.print("*** containment incorrect ***");
     System.out.println();
  }
  catch(Exception e)
  {
     System.out.println("*** CRASH !!! ***");
  }
  try
  {
     System.out.print(   "[9]--removeAll: ");
     LinkedSet<String> s1 = new LinkedSet<String>();
     s1.add("alpha");
     s1.add("beta");
     s1.add("gamma");
     s1.add("delta");
     LinkedSet<String> s2 = new LinkedSet<String>();
     s2.add("beta");
     s2.add("delta");
     s1.removeAll(s2);
     if (s1.contains("beta") || s1.contains("delta"))
        System.out.print("*** some  elts not removed? ***");
     if (!s1.contains("alpha") || !s1.contains("gamma"))
        System.out.print("*** wrong elts removed? ***");
     System.out.println();
  }
  catch(Exception e)
  {
     System.out.println("*** CRASH !!! ***");
  }
  try
  {
     System.out.print(   "[10]--retainAll: ");
     LinkedSet<String> s1 = new LinkedSet<String>();
     s1.add("alpha");
     s1.add("beta");
     s1.add("gamma");
     s1.add("delta");
     LinkedSet<String> s2 = new LinkedSet<String>();
     s2.add("beta");
     s2.add("delta");
     s1.retainAll(s2);
     if (s1.contains("alpha") || s1.contains("gamma"))
        System.out.print("*** wrong elts retained? ***");
     if (!s1.contains("beta") || !s1.contains("delta"))
        System.out.print("*** wrong elts removed? ***");
     System.out.println();
  }
  catch(Exception e)
  {
     System.out.println("*** CRASH !!! ***");
  }
  try
  {
     System.out.print(   "[11]--elements: ");
     LinkedSet<String> s1 = new LinkedSet<String>();
     s1.add("alpha");
     s1.add("beta");
     s1.add("gamma");
     s1.add("delta");
     Iterator<String> list = s1.elements();
     System.out.print("("+list.hasNext()+") ");
     if (list.hasNext())
        System.out.print(list.next()+"; ");
     System.out.print("("+list.hasNext()+")");
     if (list.hasNext())
        System.out.print(list.next()+"; ");
     System.out.print("("+list.hasNext()+")");
     if (list.hasNext())
        System.out.print(list.next()+"; ");
     System.out.print("("+list.hasNext()+")");
     if (list.hasNext())
        System.out.print(list.next()+"; ");
     System.out.print("("+list.hasNext()+")");
     if (list.hasNext())
        System.out.print(list.next()+"; ");   
     System.out.println();
  }
  catch(Exception e)
  {
     System.out.println("*** CRASH !!! ***");
  }
}
}
  • 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-07T23:43:57+00:00Added an answer on June 7, 2026 at 11:43 pm

    Ya you can……

    1. Are you talking about the command line arguments, if yes then its possible..

    Eg:

    javac Test.java
    enter code herejava Test Hello       // Hello is the Input
    

    In Java this “Hello” input is sent to the main() method in it String[] array.

    public static void main(String[] args)

    So to access this Hello which you have passed as an Argument to the main() methods parameter, you need to do this..

     String s = args[0];
    

    2. Now if you want to write this into a file internally from within the program do this.

     String s = args[0];
     File f = new File(d:\\vivek.txt);
     FileWriter fw = new FileWriter(f);
     BufferedWriter bw = new BufferedWriter(fw);
    
     bw.write(s);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Anyone who's tried to study mathematics using online resources will have come across these
I have an app that will show some images using UIImageView, now I want
i am generating *.reg file using code which will have some important data. and
Using SubSonic v2.3 in a web app. Each client (200+) will have their own
I am working on project in JSF, using Tomcat 7. The application will have
I have tried using date(m/d/Y, strtotime(04-05-2012)) but I will get 05/04/2012 or on some
I am using android 2.1 platform.The code I have will display the Name number
I'm using Apache BCEL to dynamically create java classes that will each have its
I have a situation where I will be using a repository pattern and pulling
i have several controllers which will all be using common functionality. So i have

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.