Amazon Interview Question for Software Engineer / Developers


Country: India
Interview Type: In-Person




Comment hidden because of low score. Click to expand.
0
of 0 vote

1. Program
import java.nio.ByteOrder;

public class Endian {
	public static void main(String argv[]) {
		ByteOrder b = ByteOrder.nativeOrder();
		if (b.equals(ByteOrder.BIG_ENDIAN)) {
			System.out.println("Big-endian");
		} else {
			System.out.println("Little-endian");
		}
	}
}

2. Example usage taken from <doc>ByteOrder#nativeOrder</doc>
/**
 * Retrieves the native byte order of the underlying platform.
 *
 * <p> This method is defined so that performance-sensitive Java code can
 * allocate direct buffers with the same byte order as the hardware.
 * Native code libraries are often more efficient when such buffers are
 * used.  </p>
 *
 * @return  The native byte order of the hardware upon which this Java
 *          virtual machine is running
 */
public static ByteOrder nativeOrder() {
return Bits.byteOrder();
}

- kartikaditya December 04, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

@kartik:We cannot use inbuild methods,We need to write a algo/code to detect it :)

- akshay.shetye December 04, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

I too feel sometimes, it is much easier to code in C than in Java, anyway inbuilt functions are not allowed in interviews. For example, string manipulation is much easier in C than in Java if we do not have to use inbuilt function.

- Abhi December 04, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

How does being a java guy give you immunity from worrying about endianness if you want to send a string from a windows machine to a mainframe system?

- fountainh December 04, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

Rightly pointed out. If it is a pure java guy thing, then I believe buffer stream's are big endian'd in any platform and all works well.

The problem comes when native-C and java interactions end-up in say little-endian platform where java miread's the little endian byte stream as big endian using the java io lib methods.

- kartikaditya December 04, 2011 | Flag


Add a Comment
Name:

Writing Code? Surround your code with {{{ and }}} to preserve whitespace.

Books

is a comprehensive book on getting a job at a top tech company, while focuses on dev interviews and does this for PMs.

Learn More

Videos

CareerCup's interview videos give you a real-life look at technical interviews. In these unscripted videos, watch how other candidates handle tough questions and how the interviewer thinks about their performance.

Learn More

Resume Review

Most engineers make critical mistakes on their resumes -- we can fix your resume with our custom resume review service. And, we use fellow engineers as our resume reviewers, so you can be sure that we "get" what you're saying.

Learn More

Mock Interviews

Our Mock Interviews will be conducted "in character" just like a real interview, and can focus on whatever topics you want. All our interviewers have worked for Microsoft, Google or Amazon, you know you'll get a true-to-life experience.

Learn More