Geek Time with Josh Bloch
Tuesday, April 12, 2011 | 9:00 AM
Labels: Java
In addition to being known as “The Mother of Java,” Josh Bloch is also the Chief Java Architect at Google. Josh sat down with fellow Open Source Programs Office colleague Jeremy Allison to chat about APIs, the importance of openness, and the successes and failures of Java.
Some highlights from their conversation:
(0:45) Josh describes what he does for Java and at Google.
(1:59) Jeremy expresses his disappointments with Java, based on the early potential that it showed. Josh responds with an explanation of some of the difficulties that Java faced.
(4:48) Josh and Jeremy talk about some of the factors that contributed to Java’s successes.
(9:51) Josh’s explains his philosophy towards creating APIs.
(14:30) Josh talks about the APIs that he’s most proud of.
(19:45) Josh and Jeremy discuss the importance of reading other people’s code, and the impact of Sun’s decision to put the code and bug database for Java on the web.
(24:00) Josh explains how he came to be in his current position and gives advice for others who are looking for ways to get started programming.
(27:32) Josh wrote the standard Java best-practices guide, Effective Java, and co-authored two other Java books: Java Puzzlers, and Java Concurrency in Practice. As a special treat for this blog’s readers, Josh is offering signed copies of his books for the first two people with correct responses to the following puzzle. Submit your answer as a comment on this post, then use the same Blogger ID to leave a separate comment with your contact info and inscription request (for your privacy, the comment with your contact info will not be published).
Josh’s Puzzle: “The Story of O”
The following Java program is not quite complete; it’s missing a parameter declaration for o. Can you provide a declaration that makes the program print “
O noes!”? (The program must compile without generating any warnings.)(<you provide the declaration> o)
public class Story {
public static void main(String[] args) {
Object o = null;
story(o);
}
private static void story{
if (o != null)
System.out.println("O noes!");
}
}
Remember to leave your answer and contact info as two separate comments!
By Ellen Ko, Open Source Team

41 comments:
tingley said...
private static void story(Object... o)
April 12, 2011 9:21 AM
Thomas Kappler said...
public class Story {
public static void main(String[] args) {
Object o = null;
story(o);
}
private static void story(Object ... o) {
if (o != null)
System.out.println("O noes!");
}
}
April 12, 2011 9:22 AM
Robin said...
Easy: Use "Object..."
April 12, 2011 9:28 AM
Alex said...
Object...
April 12, 2011 9:35 AM
Piotr Jaroszyński said...
Object...
April 12, 2011 9:37 AM
jvdneste said...
Object...
April 12, 2011 9:41 AM
Gianmarco said...
public class Story {
public static void main(String[] args) {
Object o = null;
story(o);
}
private static void story(Object... o) {
if (o != null)
System.out.println("O noes!");
}
}
April 12, 2011 9:42 AM
Michael said...
Object...
April 12, 2011 9:47 AM
Jeremy said...
Object...
April 12, 2011 9:48 AM
Colin said...
The declaration would be:
Object...
April 12, 2011 9:48 AM
Konrad Rudolph said...
private static void story(Object... o)
April 12, 2011 9:49 AM
Tareq Abedrabbo said...
private static void story(Object... o)
April 12, 2011 9:52 AM
Max said...
Unfortunately, the computer I'm using doesn't have Java 6. But the solution for Java 6+ is "NullType o".
April 12, 2011 9:52 AM
Matthew Flint said...
Object... o
April 12, 2011 9:53 AM
Don said...
public class Story {
public static void main(String[] args) {
Object o = null;
story(o);
}
private static void story(Object... o) {
if (o != null)
System.out.println("O noes!");
}
}
April 12, 2011 9:53 AM
Logan said...
logan@lakitu:~$
public class Story {
public static void main(String[] args) {
Object o = null;
story(o);
}
private static void story(Object... o) {
if (o != null)
System.out.println("O noes!");
}
}
April 12, 2011 9:53 AM
Matthew Flint said...
Object... o
April 12, 2011 9:53 AM
Logan Johnson said...
public class Story {
public static void main(String[] args) {
Object o = null;
story(o);
}
private static void story(Object... o) {
if (o != null)
System.out.println("O noes!");
}
}
April 12, 2011 9:54 AM
Peter Severin said...
Object...
April 12, 2011 9:55 AM
Bohdan said...
public class Story {
public static void main(String[] args) {
Object o = null;
story(o);
}
private static void story(Object... o) {
if (o != null)
System.out.println("O noes!");
}
}
April 12, 2011 9:56 AM
goddard said...
public class Story {
public static void main(String[] args) {
Object o = null;
story(o);
}
private static void story(Object... o) {
if (o != null)
System.out.println("O noes!");
}
}
April 12, 2011 9:56 AM
Spencer said...
Object... o
will result in "O noes!" being printed (with no compiler errors or warnings).
April 12, 2011 9:57 AM
Bohdan said...
My contact email: ( bohdan at popovych dot info )
April 12, 2011 9:57 AM
Emmanuel Lécharny said...
private static void story(Object... o) {
...
April 12, 2011 9:58 AM
Hayden said...
Object...
April 12, 2011 9:59 AM
Greg Schueler said...
Answer: "Object..."
April 12, 2011 9:59 AM
Hayden said...
Object...
April 12, 2011 9:59 AM
Stephanie Taylor said...
Congratulations, we have our 2 winners! tingley and Thomas Kappler were the first two people to come up with the correct response. They have both won a signed copy of one of Josh's books.
We had such an overwhelming response in the first hour that Josh is now going to come up with a more difficult puzzle that we will post soon and will again offer one of Josh's books to the first 2 people to decipher the puzzle.
Keep watching the OSPO blog for more puzzles!
April 12, 2011 9:59 AM
Fabio Mancinelli said...
Object...
Fabio
April 12, 2011 10:04 AM
mikoch said...
Object...
April 12, 2011 10:04 AM
Fabio Mancinelli said...
private static void story(Object... o) {
...
}
April 12, 2011 10:05 AM
Pavel Rappo said...
Object... o
April 12, 2011 10:05 AM
Bede said...
This code doesn't actually print "O noes"
To print the message "O noes!", either:
1/ Instantiate o:
Object o = new Object();
2/ change the if conditional statement:
if (o == null)
April 12, 2011 2:52 PM
Nirmal_160 said...
public class Story {
public static void main(String[] args) {
Object o = null;
story(o);
}
private static void story(Object... o) {
if (o != null)
System.out.println("O noes!");
}
}
April 13, 2011 6:14 AM
Nirmal_160 said...
public class Story {
public static void main(String[] args) {
Object o = null;
story(o);
}
private static void story(Object o) {
if (o != null)
System.out.println("O noes!");
}
}
April 13, 2011 6:14 AM
Siddique said...
This is also valid
private static void story(final Object... o)
...
April 13, 2011 7:16 AM
John Glassmyer said...
Object... declares an array of references.
I love the puzzlers. Keep 'em coming, Mr. Bloch!
April 13, 2011 10:52 PM
John Glassmyer said...
Or rather, Object... *instantiates* an array of references.
April 13, 2011 11:09 PM
lakshman said...
java ! a "pure" object oriented language.
ruby is. take a moment and go through objects model in ruby. you will never turn back.
April 14, 2011 2:21 AM
李峰 said...
I try
Story
then
Object...
April 14, 2011 11:01 AM
musthafa said...
Object parameter as vararg.
private static void story(Object... o){
System.out.println("O noes");
}
May 23, 2012 9:27 AM
Post a Comment