Junior Java Interview Questions -- What to Expect?

  • Context: Java 
  • Thread starter Thread starter Robben
  • Start date Start date
  • Tags Tags
    Interview Java
Click For Summary
SUMMARY

The discussion centers on preparing for a junior Java internship interview that includes a math-based coding question. Participants emphasize the importance of clarifying expectations with the recruiter, particularly regarding the format and complexity of the coding tasks. Examples provided include converting strings to numerical values, extracting numbers from mixed character strings, and evaluating mathematical expressions with varying operator precedence. Effective error handling using try-catch blocks is also highlighted as a critical skill for candidates.

PREREQUISITES
  • Basic Java programming skills
  • Understanding of string manipulation in Java
  • Knowledge of mathematical operations and operator precedence
  • Familiarity with error handling using try-catch blocks in Java
NEXT STEPS
  • Practice coding string-to-integer conversion in Java
  • Learn how to extract numbers from alphanumeric strings using regular expressions
  • Study Java's evaluation of mathematical expressions and implement a simple calculator
  • Implement error handling techniques in Java, focusing on user input validation
USEFUL FOR

Junior Java developers, internship candidates preparing for technical interviews, and anyone looking to enhance their coding skills in string manipulation and error handling.

Robben
Messages
166
Reaction score
2
I am applying for a junior java internship and the recruiter told me there is going to be a math based interview question that I must code. What can I expect from this math based question? Are there general math questions that you can provide me so that I will have a good understanding of what to expect?
 
Technology news on Phys.org
Robben said:
I am applying for a junior java internship and the recruiter told me there is going to be a math based interview question that I must code. What can I expect from this math based question? Are there general math questions that you can provide me so that I will have a good understanding of what to expect?
Have you tried asking the recruiter?
 
Borg said:
Have you tried asking the recruiter?
I thought it would have been bad/taboo to ask the recruiter lol? So it is acceptable to ask the recruiter?
 
Robben said:
I thought it would have been bad/taboo to ask the recruiter lol? So it is acceptable to ask the recruiter?
If I was concerned about my ability to be fully prepared for an interview, I would check with the recruiter to clarify anything that I was unsure about. Maybe that's just me. I did ask for a raise after I got a job once - I got the raise. I think that if you just ask for clarification about the test and present it as wanting to be fully prepared for the interview, you shouldn't break any taboos.

BTW, good luck in the interview.
 
  • Like
Likes   Reactions: Robben
Borg said:
If I was concerned about my ability to be fully prepared for an interview, I would check with the recruiter to clarify anything that I was unsure about. Maybe that's just me. I did ask for a raise after I got a job once - I got the raise. I think that if you just ask for clarification about the test and present it as wanting to be fully prepared for the interview, you shouldn't break any taboos.

BTW, good luck in the interview.

I talked to the recruiter and they stated that I must code the answer to find a numerical value. Do you have any ideas what they mean?
 
Robben said:
I talked to the recruiter and they stated that I must code the answer to find a numerical value. Do you have any ideas what they mean?
It sounds like you will be given a value as a String or some other non-numerical format and will be expected to return the numerical value. There could be any number of ways to code that depending on the problem that they give you. For example, could you code the following cases?
  • Write a program that takes a String input from a user and outputs the value as a number. Pretty simple and straightforward - you probably won't get this lucky. :oldtongue:
  • Or, the above problem where the user can input letters and numbers and you have to find the numbers within - For example, given the input "fosi7f2h98s", your program should output 7, 2, 98 (or 7, 2, 9, 8 depending on how they ask for it).
  • Given an input string of the following formats, write a program that calculates the answer - For example, "4 + 2", "12 / 3", or "2*6". Note that some have spaces and some do not.
  • Or, the above problem with multiple operations taking into account operator preference - For example, "4+2*6/2-3". You would have to look ahead to make sure that the next operator(s) don't take precedence over the current one such that you don't add 4 to the 2 before multiplying it by 6 and then dividing it by 2.
  • And, probably worst of all, given an input of the form "4plus2times6divided by2minus3", find the answer.
 
Last edited:
Borg said:
It sounds like you will be given a value as a String or some other non-numerical format and will be expected to return the numerical value. There could be any number of ways to code that depending on the problem that they give you. For example, could you code the following cases?
  • Write a program that takes a String input from a user and outputs the value as a number. Pretty simple and straightforward - you probably won't get this lucky. :oldtongue:
  • Or, the above problem where the user can input letters and numbers and you have to find the numbers within - For example, given the input "fosi7f2h98s", your program should output 7, 2, 98 (or 7, 2, 9, 8 depending on how they ask for it).
  • Given an input string of the following formats, write a program that calculates the answer - For example, "4 + 2", "12 / 3", or "2*6". Note that some have spaces and some do not.
  • Or, the above problem with multiple operations taking into account operator preference - For example, "4+2*6/2-3". You would have to look ahead to make sure that the next operator(s) don't take precedence over the current one such that you don't add 4 to the 2 before multiplying it by 6 and then dividing it by 2.
  • And, probably worst of all, given an input of the form "4plus2times6divided by2minus3", find the answer.

Oh, I see. Sounds reasonable.

For your first example, do you mean a String that contains only integers i.e. "123" then I must convert the string into an integer?

And the last two examples looks pretty difficult. I am going to attempt them now. Thanks a bunch!
 
Robben said:
For your first example, do you mean a String that contains only integers i.e. "123" then I must convert the string into an integer?
Yes. It's unlikely that they would ask for something this easy unless they want you to include proper error handling also. Error handling in this case would probably be to recognize that it isn't a proper number and ask the user to try again (or enter 'q' to quit). Of course you should try to implement error handling in whatever you code for the test.
 
  • Like
Likes   Reactions: Robben
Borg said:
Yes. It's unlikely that they would ask for something this easy unless they want you to include proper error handling also. Error handling in this case would probably be to recognize that it isn't a proper number and ask the user to try again (or enter 'q' to quit). Of course you should try to implement error handling in whatever you code for the test.
By error handling would an if and else statement suffice or would I have to use a try and catch block?
 
  • #10
Robben said:
By error handling would an if and else statement suffice or would I have to use a try and catch block?
For that example, I would put a try catch block within a loop. Something like this:
Java:
Integer finalValue = null;
boolean validValue = false;
while(!validValue) {
    try {
        // Get user input
        // Check for 'q' and quit if that's the case
        // Otherwise attempt to convert input to int
        // If it doesn't throw an error...
        validValue = true;
    }
    catch(Exception e){
        // Display error message
    } 
}
// Display output
 
  • Like
Likes   Reactions: Robben
  • #11
Thank you very much!
 
  • Like
Likes   Reactions: Borg

Similar threads

Replies
8
Views
2K
Replies
1
Views
2K
Replies
86
Views
2K
  • · Replies 14 ·
Replies
14
Views
6K
  • · Replies 6 ·
Replies
6
Views
2K
Replies
3
Views
4K
Replies
1
Views
1K
  • · Replies 3 ·
Replies
3
Views
6K
  • · Replies 4 ·
Replies
4
Views
5K
  • · Replies 10 ·
Replies
10
Views
2K