Amazon Interview Question for Software Engineer / Developers


Country: United States
Interview Type: Phone Interview




Comment hidden because of low score. Click to expand.
2
of 2 vote

For Java Guys :

import javax.tools.JavaCompiler;
import javax.tools.ToolProvider;
public class CompileHello {
  public static void main(String[] args) {
  JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
  int result = compiler.run(null, null, null,"src/Hello.java");
  System.out.println("Compile result code = " + result);
  }
}

- Kiddo July 12, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

Another one with error tracking etc (only for java)

public class MyClass {

  private static void printLines(String name, InputStream ins) throws Exception {
    String line = null;
    BufferedReader in = new BufferedReader(
        new InputStreamReader(ins));
    while ((line = in.readLine()) != null) {
        System.out.println(name + " " + line);
    }
  }

  private static void runProcess(String command) throws Exception {
    Process pro = Runtime.getRuntime().exec(command);
    printLines(command + " stdout:", pro.getInputStream());
    printLines(command + " stderr:", pro.getErrorStream());
    pro.waitFor();
    System.out.println(command + " exitValue() " + pro.exitValue());
  }

  public static void main(String[] args) {
    try {
      runProcess("javac Main.java");
      runProcess("java Main");
    } catch (Exception e) {
      e.printStackTrace();
    }
  }
}

- Kiddo July 12, 2012 | Flag
Comment hidden because of low score. Click to expand.
1
of 1 vote

write a bash script to do that and execute that bash script at runtime from your code.

- ethioer July 11, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

You can use the system call for executing the commands at run.Yes you can also make the shell script and execute through system() call.

- Guest July 11, 2012 | Flag
Comment hidden because of low score. Click to expand.
1
of 1 vote

#include<stdio.h>
#include<syscall.h>
int main()
{
int i;
i = system("gcc test2.c");
i = system("./a.out");
return 0;
}

- Rohan Tare July 12, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Do it in a different process. Anyways using system calls will fork new processes

- Yoda July 11, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
-1
of 1 vote

use a C/C++ function pointer?

- pws August 02, 2012 | Flag Reply


Add a Comment
Name:

Writing Code? Surround your code with {{{ and }}} to preserve whitespace.

Books

is a comprehensive book on getting a job at a top tech company, while focuses on dev interviews and does this for PMs.

Learn More

Videos

CareerCup's interview videos give you a real-life look at technical interviews. In these unscripted videos, watch how other candidates handle tough questions and how the interviewer thinks about their performance.

Learn More

Resume Review

Most engineers make critical mistakes on their resumes -- we can fix your resume with our custom resume review service. And, we use fellow engineers as our resume reviewers, so you can be sure that we "get" what you're saying.

Learn More

Mock Interviews

Our Mock Interviews will be conducted "in character" just like a real interview, and can focus on whatever topics you want. All our interviewers have worked for Microsoft, Google or Amazon, you know you'll get a true-to-life experience.

Learn More