I will have an interview for job as a junior java developer. I have no professional experience in programming, which means I never made any application for someone. I was asked to prepare for the interview some example: a kind of calculator application. They put 2 conditions:
API should be:
public int calculate(String action, int a, int b)
example:
input: multiply 5 4 output: 20
What do they mean by API and input/output? I always inputed simple data as String[] args Should I have main class like this (by main class I mean class which communicates with a user)?
class MainClass {
public static void main(String[] args){
String action = args[0];
int a = Integer.parseInt(args[1]);
int b = Integer.parseInt(args[2]);
SomeClass calculator = new SomeClass();
// Is this using of API?
int result = calculator.calculate(action, a, b);
System.out.println(result);
}
}
What about other methods of input and output (like Scanner, InputStream, Console)? What would you expect if you conducted such interview?
Just implement the method public int calculate( String action, int a, int b ).
API stands for Application Programming Interface. It is more or less the available functions, methods, and classes that can be used elsewhere. You don't have to worry about how the data was inputted into the program, it could be hardcoded, read from a user, read from a file, etc.
Also note, a lot of time, with these seemingly simple problems, they are looking for safe code. That is how does it react to bad input, eg calculate( "invalid operation", 2, 1 ); In this scenario, since you cannot return an error code you probably want to throw an Exception of some sort.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With