Archive for the ‘Quick Bytes’ Category

Quick Bytes: Do you have experience with agile?

Agile Interview Questions

Agile Interview QuestionsIt’s impossible to be a Java developer without experience agile in one of it’s many forms.  Stemming from the agile manifesto which originally launched in 2001, agile practices took the software world by storm to quickly becoming one of technologies biggest buzzwords, which it still is today.  The problem is, many if not most agile projects have little or nothing to do with agility, instead becoming an excuse for poor design or instead allowing clients to demand more output at a faster pace and for less.


This makes agile a very interesting interview question from both sides. Chances are you have experience in a project which claimed to be agile, but was it really? Can you recognise the strengths and weaknesses?  Agile questions also give you a great opportunity to understand a teams development practices.  Are they the real deal, or have they just added two week sprints on top of waterfall? The maturity of a companies agile practices can be a good indicator of the quality of it’s systems.


What is Agile Development? How does it differ from other methodologies?

Agile development acknowledges that software projects are very different from building projects where more traditional development methodologies came from.  It is entirely possible to know up front exactly you would build and design a house; you can perfectly spec the size, shape and design up front. This allows you to perfectly plan what work is required and how long it will take based on previous experience: putting a brick wall up with a window is a standard practice wherever you do it.  Software is not like that. System development is complicated and difficult, but more importantly the end user does not normally know what they want or they are incapable of explaining it.  If you take 6 months to write a full specification and a further 12 to build the system it is often out of date by the time it is finished and won’t actually meet the needs of the customer.

Agile development acknowledges up front that requirements are malleable and that there will be unknowns. Being able to respond to change and produce a working, valuable system is our primary goal.   There are a number of features of agile development which help to achieve this:

  • Iterative development: a minimum viable product is produced to get a system in the hands of the user.  New functionality is added and the system improved using the feedback of users.  This minimises the time between a user requesting a feature and being able to use it live.  In turn this helps to prioritise the features which will add the most value for development next.
  • Stakeholder interaction: One of the central tenets of agile lies in the close interaction of development and business, working as partners on the solution.  This requires commitment from the business to spend time on the project but ensures a higher quality solution. In other methodologies such as Waterfall where the requirements are agreed up front lead to IT being a service and the solution rarely matching the needs of the consumer.
  • Product Backlog/Planning: The work for the coming weeks or months is written as stories; these are chunks of work which can be usually completed within a single iteration (usually lasting 2 weeks).  Features can be prioritised by the business based on rough sizing (such as t-shirt sizing). Features with higher importance can then be broken down into detailed stories.  Only the work for the upcoming iterations should be well understood with detailed stories, as this reduces the chance of wasted planning because of a change in priorities. Agile embraces change.
  • Velocity: By measuring the size of stories (either in time, story points or some other fashion) we can see how many of that unit we can complete each iteration.  A well performing team will “burn down” a similar amount each sprint, allowing for a team to be able to estimate upcoming deliveries with a reasonable degree of accuracy.

Where agile tries to incrementally develop and deliver a product, Waterfall instead focuses on creating all the requirements up front and delivering the system as a “big bang”. This rarely works.

Tell me about your experiences with Agile. Do you think it’s a good thing?

Obviously this is going to completely depend on how your teams have worked, but the important thing is to take the time before an interview to think about your experiences and come up with a concise opinion.  Here’s my view.

In principal, agile development is a great thing. It’s certainly lightyears ahead of waterfall and other legacy methodologies.   There’s a big difference between lowercase agile and uppercase Agile.  Lowercase agile is about actually being agile: flexible, nimble and open to change. This is a rare thing though, as most firms use the formal uppercase Agile.  It has garnered a worsening reputation in recent years.  A lot of people have used the banner of Agile as an excuse for poor development practices; skipping out on design, poor planning, completely abandoning documentation.  The most common practice in my experience seems to be to continue to do Waterfall; big requirements up front, but then to do two week “iterations” without any flexibility or interaction with the stakeholders.  This is obviously a bad thing.

Further to this, things like Scrum have further damaged the reputation in my opinion. It places formal process around the intentionally loose agile manifesto, which can add significant overhead at no benefit in an undisciplined and untrained team.  Scrum master certification has removed all value in the term “Scrum Master’ thanks to greedy training companies allowing anyone with money and a weekend spare to become certified.

For me, good agile can be represented simply as “iterative development” and working closely with my stakeholders.  Each team and each project works differently and it’s important to come up with something that works for you.  Being able to react quickly to changing requirements and deliver brilliant, functional systems is the most important thing for an agile team.  This doesn’t preclude up front design and this doesn’t stop documentation.

I’d love to know what you think.  What is your experience with agile, or indeed Agile?  Let everyone know in the comments!


Core Java Interview Questions List Part V

core java interview questions v

core java interview questions vThis week I’m mixing up the core java interview questions: all the questions are going to be about the number types in Java!

1. What is the difference between a byte, short, int, a long, a float and a double?

byte, short, int, long are all integer types (they don’t have decimal places; whole numbers only here).  The only difference between them is the number of bytes they take up.

byte = 1 byte (8 bit)

short = 2 bytes (16 bit)

int = 4 bytes (32 bit)

long = 8 bytes (64 bit)

Integer values are stored as twos compliment.  The maximum value of a byte is 128, whereas for a short it is 32,767, int is  2^31-1 and long 2^63-1.

float and double are real numbers (e.g. have decimal places)

2. What syntax can be used when assigning integer types?

Integer types can be assigned to

  • Regular numbers:. int i = 101
  • Octal: int i = 013
  • Hex: int i = 0xABCABCAB
  • Postfixed with l or L for long:long l = 12ll long t = 0x12321232L

3. What syntax can be used when assigning real types?

  • double types using d or D: double d = 15.0d
  • float types using f or F: float f = 17.0f
  • e can be used for scientific notation: float f = 212e-23f (212 to the power of negative 23)

4. What restrictions are there on using the different types with each other?

It is perfectly fine to cast to a data type which has more space.

byte b = 121;

int i = b;

Is completely fine.  However when attempting to assign in the opposite direction a cast is required.

5. What is Autoboxing?

int, long etc. are examples of primitive types in Java.  Each has an object representation such as Integer and Long.  Autoboxing was introduced in Java 8 to automatically convert between these types.  For example:

Integer j = 4;

Is an autoboxing operation. The JVM is automatically converting “4” into an Integer object with value 4. This works in both directions too.
int i = new Integer(4);

6. Why do we care about autoboxing?

It can cause a performance hit. Depending on your application it probably doesn’t matter, from the spec:
“It is not appropriate to use autoboxing and unboxing for scientific computing, or other performance-sensitive numerical code. An Integer is not a substitute for an int; autoboxing and unboxing blur the distinction between primitive types and reference types, but they do not eliminate it.”

If you have a piece of code that is being repeatedly hit that involves autoboxing, it may be worth looking to remove it.

7. What is the result of the following java code?

System.out.println(((Integer) 0) == ((Integer) 0));
System.out.println( ((Integer) 200) == ((Integer) 200)  );

It depends on your JVM. On mine it shows




But it may be different on your machine; this is a JVM optomisation to create a cached instance of Integer values under a certain amount: for integers under a certain value it does not create a new object but instead reuses an existing, cached one.

8. How do you convert from a String to an integer type and vice versa?

Use Integer.parseInt(“123”). This throws a NumberFormatException if the String cannot be converted, which is a RuntimeException.

To convert from Integer to String, user Integer.toString(i).

9. long l = 1/0 : Will this expression compile? What is the result if so?

This will compile but result in a java.lang.ArithmeticExpresion, specifically, “java.lang.ArithmeticException: / by zero”.

10. When should I use a float or a double?

Generally it is better to prefer double unless there is a very specific reason not to. A float is half the size of a double and can be faster on some processors, however double can be faster on some modern processors.  There is a wonderful piece of advice on StackOverflow:

“Don’t use float. There is almost never a good reason to use it and hasn’t been for more than a decade. Just use double.”

A float is single (32 bit) precision whereas a double is (unsurprisingly) double (64 bit) precision.

Core Java Interview Questions List: Part IV

Core Java Interview Questions Part 4

Core Java Interview Questions Part 4The name of the game is core java interview questions and I will be your quiz master. Each week I will publish 10 new quick fire questions and answers.

1. What is the big O of object retrieval in a hashmap and why?

In the best case of no clashes it will be O(1).  The hashing function will result in direct access to the element, irrelevant of how many other objects are in the map.  However, in the worst case it could be O(n), as if the hashing function results in all the objects landing in the same bucket it will be the same complexity as linked list (which is the backing structure; see Java Data Structures Interview Questions for more).

2. What is the result of the following statement? 

int[] ints = {1, 2, 3, 4, 5};
System.out.println((ints.length/2) * (ints.length + 1));

This outputs 12Because array.length is an integer, ints.length/2 = 2, not 2.5.

3. What is the difference between JVM, JRE and JDK?

JVM is the Java Virtual Machine. All java applications execute on the Java Virtual Machine. (Read more in JVM and Garbage Collection Interview Questions: The Beginners Guide).

The JRE is the Java Runtime Environment. The JRE contains the JVM, along with supporting files such as libraries.

The JDK is the Java Development Kit and contains the JRE (and JVM) along with the tools developers need to build and create applications, such as a compiler.

4. What is a constructor? Why is it different from other methods?

A constructor is used to create an object.  It does not specify a return type (as the return type is implied; the constructor for MyObject will return a MyObject type). Constructor must be called via the new keyword, whereas regular methods will be called on an existing object (or static methods on a class). Constructors must have the same name as the class.  A default constructor is created by the JVM if one is not coded. If a class is a subclass then the first line must be to call super() to initialise the variables etc. inherited from the parent class.

5. Does importing a package, e.g. import com.cjiq.*, also import it’s subpackages e.g. com.cjiq.hello.*

No, They must me imported explicitly.

6. Explain pass by reference and pass by value

In pass by reference, a reference to the object is passed around, not the actual object.

In pass by value, a copy of the actual object is passed around. This means it cannot be modified by the method it is passed to.

7. Is Java Pass by reference or pass by value?

Java is always pass by value. However, when passing an object to a method, the reference is passed by value.  This means the same object is referenced by both the method and the caller despite being pass by value.

8. Are Java variables initialised with default values?

Static and Instance variables are given default values (e.g. false, 0, and null for Objects.  Local variables are not, and attempting to access them before initialisation will result in a compiler error.

9. What is Autoboxing?

Autoboxing is the process of the JVM automatically converting between a primitive type and it’s companion Object equivalent, e.g. int and Integer, boolean and Boolean. We should be careful when relying on this as it can have huge performance impacts if not used correctly as well as causing some very subtle bugs.

10. What access modifiers can I have on a class?

On a top level class, only public or default. Marking a class private or protected will result in a compiler error.  Inner classes can be private and static.

Core Java Interview Questions List: Part III

Core Java Interview Questions

Core Java Interview Questions

The name of the game is core java interview questions and I will be your quiz master. Each week I will publish 10 new quick fire questions and answers.

1. Can you overload the main method?

Absolutely.  However, the JVM will only use the standard main(String[] args) when launching.

2. What is a marker interface?

A Marker interface is an interface with no methods on it, used only as an indicator.  Serializable and Clonable are examples in the JDK.

3. Can a constructor be final?


4. What does applying final actually do?

Applying final to a variable means the variable cannot be changed.

Applying final to method means they can be overridden.

Applying final to a class means the class cannot be overridden

5. What is an anonymous inner class?

It is possible to create the implementation of an interface in line. Syntactically, it looks like we are instantiating a new instance of an interface.

MyInterface interface = new MyInterface(){
   public void aMethod(){


It is called anonymous because it cannot be referenced elsewhere.  It literally has no name.

6. What is casting in Java?

Casting is the act of turning one object into another.  We can refer to an Integer as an Integer, or upcast it to an Object.  It is an upcast as it is higher in the inheritance hierarchy. Alternatively, if we cast the other way from an Object to an Integer, we are downcasting.  We must be careful when casting as, if the object cast is invalid it will throw a ClassCastException.

7. Can we override an overloaded method?

Yes! Of course.  They are two orthogonal concepts.

8. What is a transient variable?

When a variable is marked transient it will not be serialized.

9. What is the difference between while and do while?

A while loop is not guaranteed to run; if the condition is false then the code in the loop will not be executed.  A do while is guaranteed to execute once.

10. What does the % operator do?

% is the modulus operator.  It will give the remainder of a division. For example, in 11 / 2, the result is 5. 11%2 will provide the remainder, which is 1.


Core Java Interview Questions List: Part I

core java interview questions 1

core java interview questions 1As I’ve discussed several times on this site, I’m not a fan of learn by wrote java questions. However, a lot of people continue to ask them during their interview process so it means you need to know how to answer them.

The name of the game is core java interview questions and I will be your quiz master. Each week I will publish 10 new quick fire questions and answers.

1. What is a static variable?

A static variable is a value that remains the same through all the instances and can be modified by all the instances. It is a shared value.

2. If I change the order of a methods modifiers will it still work? Is public static void main the same as public void static main? What about void static public main?

Modifiers can be moved around freely. The visibility modifier (if there is one)must be at the start.

3. Why would you pick an ArrayList or LinkedList?

ArrayList is great if you need fast access to objects but can cope with slower writes. Conversely, if you need fast writes (moving, removing or adding) but can cope with slower direct access then choose a LinkedList (read our in depth article on collections here).

4. What are the different access modifiers in Java and what do they mean?

public- accessible to everyone in the JVM

private- only accessible from inside the class.

protected- accessible from by any class in the same package or any subclass in any package

default- when no visibility modifier is present. accessible from any class in the same package only.

5. If you wanted to prevent your methods or classes from being overridden, how would you do this?

By declaring something as final you prevent it from being overridden.  Nothing is perfect though, as crafty developers can always use Reflection to get around this, or alternatively just copy and paste your code into their own version of the class.  It is rarely a good idea to prevent your methods or classes being overridden, and you should code defensively to reflect this.

6. What is an immutable object?

The state of an immutable object cannot be changed after construction.  Immutable objects can play an important roll in threading. (read more on threading here).  A good example of an immutable objeect is String.  Any modification to an immutable object will result in  the creation of a new object.

7. What is the difference between overloading and overriding?

Method overloading is having multiple methods with the same name. They can be differentiated as they will have a different signature, e.g. take different method parameters.  Overriding is used when creating a subclass of a class and specifying your own functionality for the method by copying the method signature identically.

8. What does it mean when we say java does not support multiple inheritance? Is this a good thing?

Java cannot extend functionality from more than one concrete or abstract class.  If both parent classes had a jump() method, it would be unclear which functionality the caller would need to use.  We can implement multiple interfaces however as the the implementation occurs in our actual class so this problem does not occur.

9. What is an abstract class?

Similar to an interface, an abstract class cannot actually be instantiated. Unlike an interface, an abstract class can have method implementations.  Any method without implementation will have the modifier “abstract” to indicate to classes which extend it that they must provide the implementation.

10. What does “write once run anywhere” mean in relation to Java?

Java is a cross platform language; java compiles down to byte code which can be run on a Java Virtual Machine (JVM). JVMs are available on many platforms including the major operating systems. This means that any Java application can in theory run on any platform where a JVM is available, hence write once (for the JVM) and run anywhere (there is a JVM).


Sign up to our mailing list now to get this and many other updates in your inbox in a handy weekly digest.



Interview Brain Teasers I

Interview Brain Teasers

Interview Brain TeasersLet me start out by saying i am not a big fan of interview brain teaser questions.  I understand why people like them; you get to see how someone reasons something out, how they work a problem with little or no background knowledge. However I’d rather give someone some code and ask them to figure that out as it’s much more likely to show whether they can solve programming problems.

However with that rant out of the way, my view is irrelevant. A large number of companies still love to ask these so it’s good to run through a few before you go in for your interview. If you’re lucky one that you know will come up, but more likely it will just help you to get into mindset of solving puzzles.


Two Ropes

This is a very classic puzzler which I always forget the answer to.

“You have two pieces of string. If you light the string at one end it will take exactly 1 hour to burn through.  However, the string does not burn evenly, sometimes burning faster and sometimes burning slower.  The only guarantee is it will take 1 hour to burn the whole string.

With only 2 pieces of string and a lighter, measure out 45 minutes”

Break the units of the question down. We have two string to measure out 1 hour, and we need to come out with 45 minutes. 45 minutes can be broken down into 30 minutes and 15 minutes.  How can we get those two units?

The 30 minutes is relatively easy. By lighting one of the strings at both ends that gives us exactly 30 minutes. But how do we get the extra 15 minutes? We can’t fold the string in 4 due to the uneven burning.  Our options are only lighting one end of a string or lighting two ends.

If we could have a string of 30 minutes we could burn that at both ends to get 15 minutes. How do we get a string of 30 minutes?  At the start of the lighting light the second string from only one end.  When the first string burns out at 30 minutes the second string will be 30 minutes long. We can then light the other end to get 15 minutes!

The Fox, The Hen and The Grain

There’s a ton of “cross the bridge” type question variations like this.

“You need to cross a river which is too deep and the current too fast to swim through. You have a fox, a hen and some grain The only option is a small footbridge which can only cope with you carrying one item over at a time.  If you leave the fox and hen together the fox will eat the hen. If you leave the hen and grain together the hen will eat all the grain.  

How do you transport them over?”

When I think about this the standout information is that the hen is the most problematic animal; it could beeaten by the fox or it could eat the grain. Therefore it’s the only option to take over first. Only the fox and grain are safe together.  So when returning to the start, which do you take?  The answer is it doesn’t matter;  because neither can be left with the hen you will have to bring the hen back with you. Let’s take the fox over and put it on the other side.  We then bring the hen back to the start and pick up the grain. We can safely drop this with the fox and then come back for the hen.

Trip 1: Hen Out, nothing back

Trip 2: Fox Out, Hen Back

Trip 3: Grain Out, nothing back

Trip 4: Hen Out.

The Cube

“If I have a 10 x 10 x 10 cube made up of 1 x 1 x 1 cubes and I paint the outside bright green, on how many cubes are there paint?”

A fun spatial reasoning exercise! There’s a bunch of ways to figure this out, and I never remember the easy one.

The cube is made up of 10 x 10 x 10 smaller cubes, so 1000 in total. The easiest way to calculate how many cubes are painted is to imagine removing all of the painted cubes from the cube. You’re left with another cube (like a russian doll) of 8 x 8 x 8 (because you’ve lost a layer on both sides. Don’t get caught out thinking the underlying cube would be 9 x 9 x 9).  8 x 8 x 8 = 512, 1000-512 = 488.

The other option is to actually count the sides; obviously the cubes overlap (the edge cubes appear on multiple sides).  If you take two opposing sides you have 2 10 x 10 sides (200 cubes).If you then take another 2 opposing sides you have 10 x 8 cubes that haven’t been touched. 2 x 10 x 8 = 160.  That leaves you then with 2 x 8 x 8 sides at 128. 128 + 160 + 200 = 488.


Image credit Kohlman Sascha

Quick Bytes: Explain database to a 5 year old

Explain databases to a 5 year old

Explain databases to a 5 year oldQuick Bytes is a series of quick interview questions and answers. Got a question you want covering? Email us!

How would you explain what a database is to a 5 year old?

I absolutely love this question. I was given it in an interview some moons ago and thought it was brilliant.  It’s a really good question to throw a candidate off; everyone’s always prepared for technical learn-by-rote questions, and they (should be) prepared for the “how many grains of sand in the world” type questions, but this treads a line straight down the middle.  Even better, it’s a really valuable question to ask as it has direct relevance to a candidates ability to do their job.

Although there aren’t many 5 years olds in the average dev shop, the whole point of this question is that it is testing your ability to talk to non technologists.  In almost all roles you’re going to be interacting with business, marketing, HR, or some other department full of people that will have never seen Firefly and won’t have a clue what Linux is.  Interacting with these people is immensely important; if you’re building in house software it may be the most important part of your job. If you can’t communicate properly with your stakeholder then it’s going to limit your ability to do your role.

I am not at this point comparing your business stakeholders to 5 year olds.  However if the question was “how would you explain what a database is to your business” people will always make assumptions based on their experiences and start talking about tables and query languages.  Explaining it to a 5 year old makes the question much easier to answer. You can’t use anything complicated, you can’t assume any prior knowledge.  How do you answer it?

My Model Answer: The Toy Box

A database is like a very special toy box.  You put all of your toys into the box and it shuffles everything around and puts them in order.  You can then ask the toy box for any toys you want and it will find them for you really quickly.  You could ask for all of the red toys and it will find them for you. Or all of the toys that make loud noises. Or all of the red toys that make loud noises that you’ve not played with for a year.

Not Model Answers and things to avoid

I’ve heard some pretty poor answers in my time.  The moment you mention any of the following keywords you’ve lost this question

  • Query Language/SQL
  • Data
  • Storage
  • Query
  • Index
  • Sharding

People really do say these things. They panic. You have to be able to succinctly describe databases then decompose that to a toddler level.  I think sometimes people get stuck at the translation.  Take hope that it genuinely isn’t an easy question if you’re not prepared for it, but if you do crush it then you’ll score serious brownie points.  Take your time answering this one. There’s no rush. Imagine a small child actually standing in front of you. What would you say?


Take a look at some other things and come up with Explain-like-I’m-5 descriptions: start with Message Bus and Object Oriented Programming.


Image from Ryan McGuire