This week's book giveaway is in the Web Services forum.
We're giving away four copies of Microservices in Action and have Morgan Bruce & Paulo A. Pereira on-line!
See this thread for details.
Win a copy of Microservices in Action this week in the Web Services forum!

Kevin Mckeon

Ranch Hand
+ Follow
since Jan 17, 2018
Cows and Likes
Total received
In last 30 days
Total given
Total received
Received in last 30 days
Total given
Given in last 30 days
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Kevin Mckeon

Daniel Demesmaecker wrote:When you try to move a package inside the same project, it will refactor.
If you move a package from on project to an other it will copy.
A cleaner solution is to create one main project and import all the other projects as seperate modules.
By the way, I also think this is more a question for the Ide forum

Thanks ! How would I go about importing all the other projects as separate modules ?

Ill have a look in the Ide forum next time - thought this problem was java related
1 week ago
I have done 5 separate tutorials on Spring Aspect Orientated Programming and i want to upload them to GitHub for safekeeping.

At the moment, all 5 tutorials are in separate Java projects in Eclipse and I want to move them to 1 project, split into 5 different source folders. When I drag and drop source folders between projects, I get all sorts of error

Here is my hierarchy at the moment, and on the right is what I want to achieve (with a little help from MS paint) :

The problems I am having are the system sees two packages called App, both with a main method so this flags an error. I dont have this problem with other projects with this set up. Also when i move packages around, sometimes they move cleanly, sometimes they copy and sometimes they refactor the package name.

I have refactored the package names in the first tutorial but i havenr changed the second or third yet. How can this be done ?
1 week ago
On looking closer, I think the largest element is moving to the end of the array by default. (It is not the element I am trying to move)

"With every pass, the largest element moves to the end of the array" - My java book

But in my case, the smallest element moves to the beginning of the array. So therefor my algorithm is backwards.

But this shouldn't make any difference in the efficiency. Am i right ?
1 month ago

By debugging the code, it seems like the largest element moves slowly to the end of the array, but at the same time the smallest element moves to the beginning of the array.

Every time the larger number moves one index to the right, the smaller number it swaps with then moves to its correct location.

The array does sort but I'm not sure if this is correct in in terms of number of passes /efficiency
1 month ago

Jeanne Boyarsky wrote:Kevin,
Your .classpath file on the work computer specifies the "source directories". It looks you didn't commit this to the github repo. Which means, you are using the defaults on checkout.

I didn't realize that this was an issue, I thought the Home PC would generate a new .classpath file when the project was checked out.

Is the solution as simple as editing the '.gitignore' file and removing the line that states '/.classpath' ?

Or is there a separate process using Egit to now include the ./classpath file ?

I used to generate the gitignore and then typed in the '/.classpath' manually.

Jeanne, is it your experience that .project and .classpath files (or any IDE-specific files) should be included in the git repository?

I didnt include .project either. Should I ?
2 months ago
To follow on from a previous thread about Interviews Questions, Time limits, mistakes and pressure..

What is the best way to approach a coding question so that you dont :
1. Waste too much time thinking up an elegant solution that may not work
2. Waste time implementing a complicated solution that in the end, doesn't work.
3. Both of the above and in the end failing the exam.

For example here was a question I took on recently :

You have three stacks of cylinders where each cylinder may vary in height.
You can change the height of a stack by removing and discarding its topmost cylinder any number of
Find the maximum possible height of the stacks such that all of the
stacks are exactly the same height.

This means you must remove zero
or more cylinders from the top of zero or more of the three stacks
until they're all the same height, then print the height.

The removals must be performed in such a way as to maximize the height.
Note: An empty stack is still a stack.

Rather than using the Stack Class, I think an ArrayList works just as well.

Here is my process of solving the question (The tabbed format shows the process of creating methods within methods) :

(Note. The height of an array is the total when all the elements are added)

1. Change three Arrays/stacks to ArrayLists

2. Write Method checkHeightEquality() to check ArraysLists are equal height
       - Write Method calculateHeight() to calculate the height of one ArrayList
               - Loop through each ArrayList to calculate height of each.

3. While the ArrayLists are not of equal height (using checkHeightEquality() method)
      - Write Method findHighestArray() to find the highest ArrayList
             - Reuse calculateHeight() method
             - Use IF statement to return the highest ArrayList
      - Write Method removeLastElement() to 'pop' the last element off the highest ArrayList

4. Print out the height of the ArrayList(s)

If you want to see the full solution in all its un-optimized glory :

The question is not difficult. But under time pressure of an exam, it would have been a total failure.
I see that the issue now is that I dived into the question with only a loose idea of how it was going to be solved (ie. I knew what methods I would need and what they would be called).
The solution works but its extremely inefficient so it times out with large stacks/arrays.
On reflection, there is plenty to optimize. For example, the calculateHeight() method should only be used once and then keep track of the result as height changes.

Their may be an even simpler solution, using Maps or Trees or some other data structure, but my question is how do you approach this type of question to get the best answer out in the shortest time ?
2 months ago
With something like this, you need to TellTheDetails (that's a link).

Im new enough to git so its hard to know how much info is required

* Did you execute Git from Eclipse or from the command line?

From eclipse - both on the work PC and the Home PC.

* Post the exact statement or procedure you took to pull from Git

When I make a change on the work PC, I open the 'Git stagaing' tab , Stage the changes I want to commit and click 'commit and push'.
When I open the Home PC, I clicked 'Import', 'Import from URI', chose the default options, and the packages and classes appear in my Home PC workspace

* Post the exact error message

I solved the first set of errors by adding in the JRE System Library to the project.

The rest of the errors were all based on package names. errors such as :
The declared package "equal_stacks" does not match the expected package "stacks/equal_stacks"
Hence why I posted the images above. Some packages are laid out in hierarchical order. Others follow convention 'stacks/equal_stacks' and others are named like 'stacks.equal_stacks'

* Are you pulling into an existing repository?

As I am importing the project to my Home PC for the first time, I dont believe I am pulling into an existing repository. (It gives me an option while importing to specify where this new repository will live)

* If you don't have modifications in the local repository, what about removing the local git directory and trying again?  Use git clone https://URL/path/to/your/repo.git

I will try this when I get the chance. I wonder is it possible that the issue is because of the Git Ignore file not committing the Work PC files that the Home PC requires.
2 months ago
I have a Workspace on my work PC where I solve java problems and these are sorted into packages and sub packages. I also push the contents to Github regularly

I am now trying to pull the git repository to my personal PC so I can work on them at the weekend but i get a host or errors and problems.

Here is my Work Directory :

And here is my Laptop Directory after pulling for Github :

I cant understand why some packages appear as 'packages' , others appear as 'package folders' (or source folders) and others don't keep the naming convention (ie Exams/interview_exams)

All the errors I'm getting are due to 'wrong package declarations'. Some of which are solved by making a folder the 'source folder'

I also don't want to make to many changes or when I push from my laptop, and pull to my work pc  - Ill have the same errors all over again.

Heres the Github page :
2 months ago
Thanks for all the help. It feels like it has been invaluable if not eye-opening.

Seems like I have a bit of work to do before the next interview.

Anyway, Id really like to view someones solution using the LinkedHashMap<String, TreeSet<String>> approach

I understand the concept but I am finding it hard to implement without multiple loops which I think is incorrect. In the end I had to settle for a similar method which is far from short and took a lot longer than 15 minutes  :

2 months ago

Liutauras Vilda wrote:Looking to Piet's tip (missed it before), I must say I like it too. I have solution ready.

I really advise to follow Piet's suggestion, certainly easier approach than I had initially in my mind.

Anyway, go small.

First thing is to figure out how to normalize string/anagram. There is a habitual approach or using streams. As for habitual, think if you could convert string to an array of(?) and use Collections class to sort it? So later you could construct back the string from sorted array. Using streams api is slightly easier.

I will give this ago, thanks @piet.

On a side note, would this question be considered a difficult interview question ? As I am a junior full stack developer, I don't think a single developer in my office would have gotten the answer out correctly. Only someone (like piet) who is probably working with HashMaps and TreeMaps on a daily basis and who is lucky enough to spot the correct structure would stand any chance.

This was one of two code questions (the other is write a method to check if two unsorted string arrays have the same elements) and two multiple choice questions about MultiThreading. The test was 90 minutes.

Personally I felt this was difficult but maybe I am underestimating the Java developer required skill level.

Some feedback on whether or not my solution was up to scratch or not would be very much appreciated.
2 months ago
Apologies for the confusion. I will forget about the alphabetically ordered output because at the moment I am way off,

Here is the full question and my solution


Two words are matched if they are anagrams.
Given a set of words, print out all matched words.

- Each set of words should be printed on a separate line.
- Words that are not matched should not be printed.
- The output should be alphabetically ordered across each line and within each line. (forget about this for the moment)

Input : "lamp", "palm", "finger", "deal", "elbow", "fringe", "silent", "teaching", "below", "bowel",

Expected output :

lamp palm
finger fringe
elbow below bowel


I hope that using a LinkedHashSet is the best option for a solution. My first attempt involved loops and inner loops and it was a nightmare!
2 months ago
(This is a small part of a larger question - )

Given a LinkedHashSet of anagrams, print each set of anagrams alphabetically and on a new line. (The anagrams will always be grouped like below because of the way they were added to the LinkedHashSet )

[lamp, palm, finger, fringe, elbow, below, bowel]

I am trying to traverse my LinkedHashSet to give the following output :

lamp palm
finger fringe
elbow below bowel

I cant see how this output is possible, even by changing the LinkedHashSet to a linkedlist or other data structure.

Any tips or ideas ?

2 months ago
After many frustrations and plenty of eureka moments. I have implemented my own Linked-List class

Please have a look at let me know where it falls short.

(I already know I need to add in try/catch blocks for out-of-bounds errors that arise, but is that the best solution ? )  

3 months ago
People say that ArrayLists are preferable to arrays because Arrays are immutable.

If you want to add an element to an array, you have to pretty much overwrite it with a new array which is one size larger containing the new entry.

Hence ArrayLists come in handy as they have the Add function which is more efficient as you don't have to use memory overwriting the ArrayList with a new ArrayList

However, looking into the makeup of ArrayList, it appears that the fundamental structure behind an ArrayList is in fact an array so in order to edit the ArrayList, you are editing an Array (on a deeper level)

Does this mean that an ArrayList is actually more inefficient than an array ?

Does the same logic apply to String and StringBuilder ?
3 months ago
I'm interested to hear from developers who have worked in long term or contract positions outside of Ireland be it Asia, America or Europe.

Id like to travel abroad while working but its fairly difficult to find information online about the software development market in countries and cities in terms of working hours, pay, flexibility, experience required, competition with locals etc. It's even more difficult if the country doesn't speak English as a first language.

I'm particularly interested in large Asian cities like Tokyo, Hong Kong, Singapore, Shanghai, but any interesting stories or job hunting advice in any city would be helpful.

I'm not worried about working visas or relocation issues just yet as I wont be moving anywhere any time soon but its better to start the research early in order to make plans and start building up the portfolio.
3 months ago