Good 15 minute Java question to ask recent college graduate [closed] - java

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
When interviewing college coops/interns or recent graduates it helps to have a Java programming question that they can do on a white board in 15 minutes. Does anyone have examples of good questions like this? A C++ question I was once asked in an interview was to write a string to integer function which is along the lines of the level of question I am looking for examples of.

Is there any reason why it has to be on a whiteboard? Personally, I'd rather sit them in front of a keyboard and have them write some code. Our test used to be a simple 100 (IIRC) line Swing text editor. We then broke it a few simple ways, some making the code not compile and some a little more subtle, and gave the candidates half and hour and a list of problems to fix.
Even if you can't have them do anything hands on make sure that you do give them some explicitly technical questions. In another round of interviews there were a surprising number of recent graduates who were just buzzword-spouting IDE-jockeys, so they could look OKish waving their hands around in front of a whiteboard talking about Enterprise-this and SOA-that, but when given a simple Java fundamentals multiple choice exam asking things about what final and protected meant did horrifyingly badly.

I've always thought that algorithmic questions should be language agnostic. If you want to test the java level of a student, focus on the language: its keywords (from common one like static to more exotic one, like volatile), generics, overloading, boxing/unboxing of variable, standard libraries.

Some stuff that has showed up on SO:
IsPalindrome(string s)
ReverseWordsInString(string s): "I know java" --> "java know I"
Other stuff that springs to mind:
multiply a Vector with a Matrix (can this be done OO-Style?)
echo (yes, a simple clone of the unix tool)
cat (15 min should be enough, should weed out the clueless)
a simple container for ints. Like ArrayList. Bonus question: Generic?

Write a function to swap variable values using pointers (Really poor ones will fall for this)
Write a program to find the distance between two points in the XY plane. Make use of a class to store the points.
Demonstrate the use of polymorphism in java using as simple program.
Write a program to print the first n prime numbers.
Write a program to replace a string in a file with another.

If you don't know what questions to ask them, then may be you are not the right one to interview them in Java. With all due respect, I hate when people ask me questions in interviews which they themselves don't know answers for. Answers for most of the questions can be found online by googling in a few secs. If someone has experience in Java, they will definitely know Abstract class, interface etc as they are the core building blocks. If he/she does not know 'volatile' keyword - big deal.

I agree with Nicolas in regards to separating the algorithmic questions from the actual language questions.
One thing that you might want to consider is giving them a couple simple algorithm questions that they can write up the pseudo code for on the white board (ex. "Explain to me the Bubble sort and show me the pseudo code for it."
Then once they have demonstrated their algorithmic knowledge you can move on to the Java questions. Since some people work better in front of a computer than in front of the whiteboard, I would give them something simple, but leveraging their knowledge of Java, that they can implement in 30 minutes or so in using the same IDE that you are using at the company. This way if they claim to know the IDE you can also get an idea of how well they know it.

Write a function that merges two sorted lists -- stopping at limit. Look for the easy optimizations and correct boundary checks / sublist calls. Tell them T implements compareTo.
public List<T> merge(List<T> one, List<T> two, int limit)
Write a function that returns true if any two integers in the array sum to the given sum. Have them try to do better than n squared using some sort of set or data structure.
public boolean containsSum(int[] nums, int sum)

I would avoid asking them questions that would have been covered in their undergrad classes. I would be more curious about their ability to apply everything they've learned to solve complex technical problems. If your business has a specific need for an IT solution you could use that as a starting point. You could ask the candidate what technologies they would use and the pros and cons of using those technologies versus alternate technologies. As the discussion progresses you could get a feel for their technical skills, problem solving skills, interpersonal skills, etc. I think it is important to avoid coaching them, even in awkward moments. This is important to weed out the BSers.

Related

Parsing and Solving a Formula in Java SE 8

Disclaimer: Not Homework
I've written very basic calculator parsers in Java using tokenizers, but I have recently started writing a problem to help me understand chemistry. As I began writing more and more formulas, it became increasingly apparent that the complexity required to solve for each equation is almost more tedious than mastery of the equations themselves. Take the equation PV = nRT, how could I write a parser that would allow me to input all know variables and solve if it was solvable? I can do the logic behind solvability, but here are a few requirements:
must be able to solve for any unknown variable.
parsing should be capable for formulas of any size (ex: I want to implement more than one formula, such as π = MRT and formulas of increasing complexity, and only want to have to define them once.)
Once again this is purely for my enjoyment and to be used as a learning tool. Any help would be appreciated, as searching Google and StackOverflow for this problem have given me either vague or inapplicable answers.
As you have posted no code I will speak my thoughts.
I used to have an hp48G calculator which had a library with many formulas covering different areas.
Instead of parsing a single line, you had to choose through menus which was the formula to apply, then the calculator would ask for each parameter separately, and apply it to the formula to provide the result.
If you follow this approach, and helped with java's interfaces I think you can do something like you are asking.

Can this be considered Artificial Intelligence? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
I'm currently using Java to code a program that can have conversations and solve problems.
So far, the program can only have conversations. The solving problems is still in process.
The program is capable of learning, however, it's how I made that happen that gives me doubts.
The way my program learns new words is it stores them in a TreeView menu as branches.
Each branch (word) has sub-branches that give the word meaning.
Each sub-branch has sort of like different tags to differentiate the relation to the main branch.
For example, if I teach it the word Hello and type Hello>>Hi, it then saves Hi as a sub-branch in the main branch Hello, but in the form of =s=Hi=s= to tell the program it's a synonym of Hello, so it can use Hi instead of Hello. More synonyms can be added.
Though if you type, for example, Hello<>Greeting, it stores the branch Greeting in Hello in the form of =m=Greeting=m=. To show that Hello is a type if greeting.
There is more, but too much to explain.
Just my cheap attempt on A.I.
Can this class as a program learning? Or have I got a long way to go?
As per definition of AI:- It's the capacity to perform operations analogous to learning and decision making in humans.
Your program do seems to learn the new words and make decision on what type of word it is i.e. Hello, Hi -->Greeting
But more than learning, how you control its learning will be AI. For example if I use a bad word for greeting, it should not learn it. Controlled learning and decision-making do make your program a true AI program.
You have actually started to learn AI. And this what you do is called giving ground terms manually for the machine. But AI is something that the system learns by itself. For example, now you have taught that hi is a way of greeting, if some other user greets it, it must greet him too. And yes you will be writing logic for that too. You cannot fully achieve AI such that the computer learns itself without writing any logic for it (only fictional characters like Jarvis can do so).
To be frank I am not deep into machine learning and AI. But to my perception, I think some sort of implementation which involves human like thinking would be better. For example, try to implement a chess game. In that you have back tracking. You can get a better understanding. Properties of each coin and their power is what you give as ground terms(base knowledge). And based on the moves of User, system must analyze future moves and predict user's view and backtrack to make its move.
Not sure whether I answered your question, but you seem to be doing cool stuff, thumbs up for you, move on and develop cool and small scale AI systems first which involves lot of computation and Algorithm stuffs.

Is this Java reply to a job questionnaire valid? [closed]

Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 10 years ago.
Improve this question
I was asked this in WRITTEN form through a recruiter, with the previous question being string related, and the previous one being about Inversion of Control:
How would you find the second largest element in an array?
Being a Project manager who has is self teaching/learning JAVA, my response was:
How is large defined (integers? parsing of: strings/objects? ) How large is the array? Bubble sort , then return the second to last index. Temporarily store the largest and second to largest variable, sort through the array, replacing the appropriate variables, then return the second largest variable. There are many ways, however to develop an appropriate function that isn’t expensive would require more information. If the range is very wide, make several lean methods, measure the array length, and apply the appropriate method on the array.
Is this a valid response to the question, and if not, what do you think it needs improvement on? I'm asking this because of the extreme gap presented in the common recruitment atmosphere, and am having difficult understanding the actual intended purpose of similar structured questions, and need your feedback to understand what/how to approach/reply.
UPDATE I received notification that they typically see code, but provided no parameters or guidelines, and replied with this:
I can not provide a codified answer, not knowing at least the first two pieces of information. The first will allow for parsing, as numbers are sorted universally, while strings, objects, and others are parsed subjectively. The second part, dealing with the array length, and whether or not it is static, is definitely relavent as a developer, as expensive code (whether in computation time facing the user, or hardware costs to the client) can be costly. The question is worded poorly for an exact technical response, especially given that it is in written format, where there is no feedback. I am merely typing my considerations as a reply, the same as if it were asked in person. The context I am given from the previous questions is that they are looking for someone who understands IoC practices (bullet 3) and would be parsing Strings (given bullet 2) in potentially a transaction (try/catch) situation (bullet 4) and then find (current issue). If the questionnaire's purpose is to see how I approach a problem, then my response is valid. If they would like further clarification, I would be happy to accomodate, but if they are requiring a codified answer AND unwilling to provide the necessary context, then I am unwilling to work with them, as it would highlight there misunderstanding of how to interact with external customers, who DO need guidance when one "simple" question is asked, but other pieces of information are needed to best accommodate, the central reason behind any business seeking outside specialized help. I hope this response in not read in a harsh tone, as my cadence when replying out loud is quite the opposite, as further information is required, including if sole development in JAVA is within the scope of this job, as I am skilled in JS and Python as well, and this was not discussed yesterday. Hopefully you and your client can understand that with the recruiter method, a layer of abstraction can be beneficial in many areas, but in situations like this, it can hinder and cloud perceptions without direct communication and feedback. Please feel free to provide this in addition to my answer.
and received acclaim for this reply. Thank you for your help, as I am really trying to get a programming job, but have no prior formal experience and this guidance really helps.
In this case, I think the interviewer really wants to know in order to find 2nd largest element, does one have to sort the entire array(and pick the second element) or is there any better approach?
The answer is you don't have to sort the entire array in order to find top k elements. Sorting will take O(nlgn) time whereas finding top k items will take only O(nlogk).
You can explain the answer using simple example. If you have to find 2nd largest card in 100 cards with numbers ranging some low to high. The cards are not sorted. To find 2nd largest card, all of you have to do is hold top 2 cards that you have seen so far in your hand. As you pick new cards, see if it is larger than the one in your hand, if so replace the new largest with the smallest in hand. At the end of this process, you will end up holding top 2 cards.
EDIT: Like others said, bubble sort has worst runtime O(n^2). For fun, Check out President Obama's answer to sorting interview question. http://www.youtube.com/watch?v=k4RRi_ntQc8
The most efficient to do the needed task is obvious: iterate once on the array and looking for the "largest" element, all the while storing also the previous "largest" element. At the end of the array, your previous "largest" element is the one your method needs to return.
To formulate your answer, I see 2 choices:
Beginning your answer by "Assuming the array contains int elements..." or something approaching.
Using an undefined isLargest() or isLarger() method and explain that the purpose of the method is to check if the current element is largest currently examined, whatever it means.
This is pretty subjective, but frankly I agree with your question-about-the-question -- they should have defined what it is your array contains.
What you could have done is written something like "Assuming the elements in the array are all integers, here's how I'd do it" and then give your answer with that assumption.
I'd follow the same steps with your other requests for additional info -- make an assumption, declare your assumption, then proceed with that assumption in mind.
Seems valid - I just fear they wanted CODE. I think maybe you should have just assumed integers and written something IN ADDITION to what you said.
My initial gut reaction would be "Modified Merge Sort", implemented using a ForkJoinPool. It's still O(n log[n]), but the actual runtime would be faster than a serial implementation.
You may ask why not quicksort, and it's because worst case for quicksort is O(n^2), which would be bad for an extremely large dataset. Modified Merge Sort has more predictable performance and a better worst case scenario O(n log[n])

Java library to compare image similarity [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 8 years ago.
Improve this question
I spent quite some time researching for a library that allows me to compare images to one another in Java.
I didn't really find anything useful, maybe my GoogleSearch-skill isn't high enough so I thought I'd ask you guys if you could point me into a direction of where I could find something like this.
Basically what I want to do is to compare two images with each other and get a value of how much the two are similar. Like a percentage or so.
I hope you guys have something I can use, I wouldn't know how to write something like that myself...
PS: It doesn't necessarily has to be in Java, that's just the environment my app will be running.
You could take a look at two answers on SO itself: this one is about image comparison itself, offering links to stuff in C++ (if I read correctly) while this one offers links to broader approaches, one being in C.
I would suggest starting with the second link since there's links on that discussion that'll lead to implementation code of some relevant techniques which you might be able to "translate" into Java yourself.
That's the best my google skills could do, no Java though - sorry. I hope it's a good starting point!
EDIT:
Here's someone with your problem who wrote his own comparison class in Java. I didn't read the source code though. He expressly states that he couldn't find Java libraries for that purpose either, so that's why he wrote it himself.
Oh, and this question on SO has probably the best links on this, all regarding Java libraries of image processing. Hopefully there's one amongst them that can compare images for similarity.
Ok, last edit:
The Java Image Processing Cookbook shows a Java implementation of a basic algorithm to determine the difference between two pictures. It also has an email to contact the guy who wrote it as well as a host of references. No library though.
EDIT after reading your comment to your question:
Unless you've already checked all of the above links, since what you want seems to be checking whether two images are equal, I would suggest starting with the Java Image Processing Cookbook (since that has an implementation of an algorithm in Java to check for equal images) and the last link to an SO question. Also, check PerceptualImageDiff and the source code of that project (C++); it sounds really nifty - it's apparently supposed to check whether two images look equal to the human visual system.
Just off the top of my head, OpenCV is a great image processing library, but it might be overkill if you just want to compare images. If that's the case, I'd go with ImageJ.
Someone already asked how to do this using OpenCV here.
I'd use C++ for this, but if you must use Java, there is a project which made a Java wrapper for OpenCV, here.
I used the class in this link to compare two product images, and the results were cool. It's not very hard to implement it just to be used for comparing two images, you just need to delete the lines of JAI and Swing and such. It resizes images to 300x300 and returns a difference value such as "1234". The maximum difference value is near "11041", it's stated in the link. Doing a division, you can simply get the percentage. If interested I can post the modified code here later.
The results were cool, but I still got "digital camera photos", detected to be similar to "TV photos". So, I used ImageJ to detect edges in the picture. Using the detect edges operation, ImageJ converts the image into a edge detected greyform image. Than I put the two edge-detected images in the same comparator and multiplied the both values. The results got even more accurate.
Getting the edge-detected form of the images

Want to improve math skills for programming [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 9 years ago.
Improve this question
I have just started programming with Java and noticed I might need to improve my math skills if i'm to do anything worthwhile with it. I just noticed that some of the exercises should be easy for someone with a solid understanding in math as there seems to be some math formulae running the show. I finished high school two years ago and did not get any opportunity to do math at the highest level there. I'm deeply worried by this and so i'm looking for pointers from more experienced and knowledgeable people on what I should study to get a basic grasp of mathematics before indulging in deep waters.
I was generally a sharp student in math and I have got a real quick mind. My goal is to become a certified and well-experienced Java programmer by the end of the year. I know people will say experience takes time and effort but i'm willing to sacrifice whatever that I have towards fulfilment of this goal. I have programmed with PHP and MySQL a bit before and got a general understanding but Java gave me a real kick when I read about it. If you know any other stuff that may help me in this endeavour, please let me know.
Thanks.
I strongly encourage you to read Steve Yegge's Math for Programmers.
If you're looking for some books, I recommend Concrete Mathematics and The Art of Computer Programming.
If you're looking for some problems to practice with, check out Project Euler.
Do not be discouraged by challenging problems. It's is only through overcoming challenges that you will grow. The community here is quite willing to give you assistance and nudges when you reach a roadblock.
Let's also not forget the famous quote:
Whatever your difficulties in mathematics, I can assure you mine are far greater.---Albert Einstein
My goal is to become a certified and well-experienced Java programmer by the end of the year.
Finally, the only way to become well-experienced is to write code, and lots of it.
Discrete Mathematics is what you are most likely needing. Understanding base 2 (binary) base 16 (hex) number systems is helpful a must. You don't have to get bogged down in discrete mathematics as some of that is way too deep and makes math majors cringe. Look over basics such as sets and logic.
As for trig/calculus... I have taken all these in college and have never relied on these extensively... or well, at all.
Mathematical aptitude is not necessarily a prerequisite for being a good programmer. There is a strong association though in that good programmers tend to be good at math. That doesn't mean that learning more math will necessarily make you a better programmer. To become a better programmer usually takes a lot of coding. So with that in mind:
Code much and often and with best practices, try not to "cheat"
Challenge yourself
Try working through some problems on Project Euler
Trying doing advanced Sudoku in your head to practice deduction and to warm up
Linear equations, matrix algebra, Base 2, 8 ,18, and 10 conversions, logarithms, and set theory (intersections, unions, etc) will give you a basic foundation. If your algebra is sound, look into discrete mathematics, precalculus, and trig. Once you've gotten that far, you should have no trouble continuing if you wish.
Honestly, it may be worth your time to take a placement test at a local community college to get an honest evaluation of your skills. From there, you have the choice of enrolling in a class or learning their curriculums through self-instruction.
Go through http://www.khanacademy.org/ math section. Most people graduate high school with only Calculus I under their belt.
If you go through all math here, you will have almost satisfied math requirements for a bachelors in CS. What remains is discrete math, algorithms, finite automata.
Check out MIT Open Courseware for that as well.
IF you have any free time left after all these great suggestions, I might throw Head First Statistics on your reading list as well.
http://www.amazon.ca/Head-First-Statistics-Dawn-Griffiths/dp/0596527586
While not directly related to core Java programming, statistics finds many uses in some areas of computer science. For example, i"ve found this book very useful in some of the data mining projects I've been a part of.
I recommend this book because it is very easy and fun read, and serves as a good intro to statistics without bogging you down. This is that "before bead" reading you can do with minimal effort.
This isn't recommendations so much as general encouragement; I learn by doing. Reading books on mathematics, out of the context of some problem to solve, is boring, dry and generally not conducive to learning. I find if I set myself a programming challenge, one that is above my current level of competency, I will learn a lot and open up new areas of knowledge as a consequence of solving the problem. Perhaps it's harder/slower this way, but I find it gives me a solid, practical grounding in a subject. For example, back in the days I learned a lot about modulo mathematics by trying to find the simplest way to do human Vs computer rock-paper-scissors game.... My two cents.
I've quite often tried working through books, and have a good selection of partly read maths books. I gained a lot doing a second-year Open University pure maths course (M208) a couple of years ago - it's well structured, you have to do all the exercises, and it was both wide enough to introduce a few things I wouldn't have looked at off my own bat, but deep enough to be satisfying.
"Concrete Mathematics" would be a book suggestion on this topic.

Categories