Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
SlideShare a Scribd company logo
CORE JAVA - BUG HUNT QUIZ
ganesh@codeops.tech
Ganesh Samarthyam
Programmer’s world :)
java.lang.NullPointerException
at org.eclipse.jface.dialogs.DialogSettings.load(DialogSettings.java:278)
at org.eclipse.jface.dialogs.DialogSettings.load(DialogSettings.java:306)
at org.eclipse.jface.dialogs.DialogSettings.load(DialogSettings.java:247)
at org.eclipse.jface.dialogs.DialogSettings.load(DialogSettings.java:264)
at org.eclipse.ui.plugin.AbstractUIPlugin.loadDialogSettings(AbstractUIPlugin.java:411)
at org.eclipse.ui.plugin.AbstractUIPlugin.getDialogSettings(AbstractUIPlugin.java:232)
at org.eclipse.jdt.internal.ui.JavaPlugin.getDialogSettingsSection(JavaPlugin.java:1012)
at org.eclipse.jdt.internal.ui.packageview.PackageExplorerPart.<init>(PackageExplorerPart.java:436)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at java.lang.Class.newInstance0(Unknown Source)
at java.lang.Class.newInstance(Unknown Source)
at org.eclipse.core.internal.registry.osgi.RegistryStrategyOSGI.createExecutableExtension(RegistryStrategyOSGI.java:170)
at org.eclipse.core.internal.registry.ExtensionRegistry.createExecutableExtension(ExtensionRegistry.java:867)
at org.eclipse.core.internal.registry.ConfigurationElement.createExecutableExtension(ConfigurationElement.java:243)
at org.eclipse.core.internal.registry.ConfigurationElementHandle.createExecutableExtension(ConfigurationElementHandle.java:51)
at org.eclipse.ui.internal.WorkbenchPlugin$1.run(WorkbenchPlugin.java:267)
at org.eclipse.swt.custom.BusyIndicator.showWhile(BusyIndicator.java:70)
at org.eclipse.ui.internal.WorkbenchPlugin.createExtension(WorkbenchPlugin.java:263)
at org.eclipse.ui.internal.registry.ViewDescriptor.createView(ViewDescriptor.java:63)
at org.eclipse.ui.internal.ViewReference.createPartHelper(ViewReference.java:328)
at org.eclipse.ui.internal.ViewReference.createPart(ViewReference.java:230)
at org.eclipse.ui.internal.WorkbenchPartReference.getPart(WorkbenchPartReference.java:594)
at org.eclipse.ui.internal.Perspective.showFastView(Perspective.java:2053)
at org.eclipse.ui.internal.Perspective.setActiveFastView(Perspective.java:1835)
at org.eclipse.ui.internal.Perspective.setActiveFastView(Perspective.java:1848)
at org.eclipse.ui.internal.Perspective.toggleFastView(Perspective.java:2241)
at org.eclipse.ui.internal.WorkbenchPage.toggleFastView(WorkbenchPage.java:3824)
at org.eclipse.ui.internal.ShowFastViewContribution.showView(ShowFastViewContribution.java:157)
at org.eclipse.ui.internal.ShowFastViewContribution.access$1(ShowFastViewContribution.java:155)
at org.eclipse.ui.internal.ShowFastViewContribution$3.widgetSelected(ShowFastViewContribution.java:138)
at org.eclipse.swt.widgets.TypedListener.handleEvent(TypedListener.java:228)
at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:84)
at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1003)
at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.java:3823)
at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3422)
at org.eclipse.ui.internal.Workbench.runEventLoop(Workbench.java:2382)
at org.eclipse.ui.internal.Workbench.runUI(Workbench.java:2346)
at org.eclipse.ui.internal.Workbench.access$4(Workbench.java:2198)
at org.eclipse.ui.internal.Workbench$5.run(Workbench.java:493)
at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:288)
at org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:488)
at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:149)
at org.eclipse.ui.internal.ide.application.IDEApplication.start(IDEApplication.java:113)
at org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandle.java:193)
at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:110)
at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:79)
at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:382)
at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:179)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:549)
at org.eclipse.equinox.launcher.Main.basicRun(Main.java:504)
at org.eclipse.equinox.launcher.Main.run(Main.java:1236)
SNAFU!
Question #0
Which browser does this code open?
a) Internet Explorer
b) Opera
c) FireFox
d) Safari
class Google {
public static void main(String []args) {
http://www.google.com
System.out.println("Hello world");
}
}
Question #1
Core Java - Quiz Questions - Bug Hunt
Question #2
“95% of the folks out there
are completely clueless
about floating-point”
-James Gosling (in 1998
JavaOne keynote address)
Floating-point Numbers are Tricky!
Another Example
class FloatCompare {
public static void main(String []args) {
double x = 2.0;
double y = Math.sqrt(x) ;
System.out.println( (y * y) == x);
}
}
Question #3
Question #4
Which one of the following best describes the behavior of this code?
a) This code segment will give compiler error(s)
b) This code segment will return 1 to the caller
c) This code segment will return null to the caller
d) This code segment will result in throwing a NullPointerException
Question #5
class Append {
public static void main(String []args) {
StringBuffer sb = new StringBuffer('H');
sb.append('i');
System.out.println(sb);
}
}
Which one of the following best describes the behavior of this code?
a) This code segment will give compiler error(s)
b) This code segment will print “Hi”
c) This code segment will print “H”
d) This code segment will print “i”
Question #6
class ReplaceAll {
public static void main(String []args) {
String date = "18-03-2017" ;
String date1 = date.replaceAll( "-" , "." ) ;
String date2 = date1.replaceAll( "." , "/" ) ;
System.out.println(date2);
}
}
What is the output of this program?
a) 18-03-2017
b) ----------
c) ……….
d) //////////
Question #7
Question #8
Question #9
class Base {
public Base() {
System.out.println("In Base ctor");
}
}
class Derived extends Base {
public Derived() {
System.out.println("In Derived ctor");
}
}
class UseArray {
public static void main(String []args) {
Base [] array = new Derived[2];
array[0] = new Base();
array[1] = new Derived();
}
}
Question #10
class Stack {
private final int CAPACITY = 100;
private Object[] array = new Object[CAPACITY];
private int size = 0;
public void push(Object val) {
if (size < CAPACITY)
array[size++] = val;
else
throw new StackFullException();
}
public Object pop() {
if (size == 0)
throw new StackEmptyException();
else
return array[--size];
}
}
ganesh@codeops.tech @GSamarthyam
www.codeops.tech slideshare.net/sgganesh
+91 98801 64463 bit.ly/sgganesh

More Related Content

Core Java - Quiz Questions - Bug Hunt

  • 1. CORE JAVA - BUG HUNT QUIZ ganesh@codeops.tech Ganesh Samarthyam
  • 2. Programmer’s world :) java.lang.NullPointerException at org.eclipse.jface.dialogs.DialogSettings.load(DialogSettings.java:278) at org.eclipse.jface.dialogs.DialogSettings.load(DialogSettings.java:306) at org.eclipse.jface.dialogs.DialogSettings.load(DialogSettings.java:247) at org.eclipse.jface.dialogs.DialogSettings.load(DialogSettings.java:264) at org.eclipse.ui.plugin.AbstractUIPlugin.loadDialogSettings(AbstractUIPlugin.java:411) at org.eclipse.ui.plugin.AbstractUIPlugin.getDialogSettings(AbstractUIPlugin.java:232) at org.eclipse.jdt.internal.ui.JavaPlugin.getDialogSettingsSection(JavaPlugin.java:1012) at org.eclipse.jdt.internal.ui.packageview.PackageExplorerPart.<init>(PackageExplorerPart.java:436) at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source) at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source) at java.lang.reflect.Constructor.newInstance(Unknown Source) at java.lang.Class.newInstance0(Unknown Source) at java.lang.Class.newInstance(Unknown Source) at org.eclipse.core.internal.registry.osgi.RegistryStrategyOSGI.createExecutableExtension(RegistryStrategyOSGI.java:170) at org.eclipse.core.internal.registry.ExtensionRegistry.createExecutableExtension(ExtensionRegistry.java:867) at org.eclipse.core.internal.registry.ConfigurationElement.createExecutableExtension(ConfigurationElement.java:243) at org.eclipse.core.internal.registry.ConfigurationElementHandle.createExecutableExtension(ConfigurationElementHandle.java:51) at org.eclipse.ui.internal.WorkbenchPlugin$1.run(WorkbenchPlugin.java:267) at org.eclipse.swt.custom.BusyIndicator.showWhile(BusyIndicator.java:70) at org.eclipse.ui.internal.WorkbenchPlugin.createExtension(WorkbenchPlugin.java:263) at org.eclipse.ui.internal.registry.ViewDescriptor.createView(ViewDescriptor.java:63) at org.eclipse.ui.internal.ViewReference.createPartHelper(ViewReference.java:328) at org.eclipse.ui.internal.ViewReference.createPart(ViewReference.java:230) at org.eclipse.ui.internal.WorkbenchPartReference.getPart(WorkbenchPartReference.java:594) at org.eclipse.ui.internal.Perspective.showFastView(Perspective.java:2053) at org.eclipse.ui.internal.Perspective.setActiveFastView(Perspective.java:1835) at org.eclipse.ui.internal.Perspective.setActiveFastView(Perspective.java:1848) at org.eclipse.ui.internal.Perspective.toggleFastView(Perspective.java:2241) at org.eclipse.ui.internal.WorkbenchPage.toggleFastView(WorkbenchPage.java:3824) at org.eclipse.ui.internal.ShowFastViewContribution.showView(ShowFastViewContribution.java:157) at org.eclipse.ui.internal.ShowFastViewContribution.access$1(ShowFastViewContribution.java:155) at org.eclipse.ui.internal.ShowFastViewContribution$3.widgetSelected(ShowFastViewContribution.java:138) at org.eclipse.swt.widgets.TypedListener.handleEvent(TypedListener.java:228) at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:84) at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1003) at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.java:3823) at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3422) at org.eclipse.ui.internal.Workbench.runEventLoop(Workbench.java:2382) at org.eclipse.ui.internal.Workbench.runUI(Workbench.java:2346) at org.eclipse.ui.internal.Workbench.access$4(Workbench.java:2198) at org.eclipse.ui.internal.Workbench$5.run(Workbench.java:493) at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:288) at org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:488) at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:149) at org.eclipse.ui.internal.ide.application.IDEApplication.start(IDEApplication.java:113) at org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandle.java:193) at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:110) at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:79) at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:382) at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:179) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) at java.lang.reflect.Method.invoke(Unknown Source) at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:549) at org.eclipse.equinox.launcher.Main.basicRun(Main.java:504) at org.eclipse.equinox.launcher.Main.run(Main.java:1236) SNAFU!
  • 3. Question #0 Which browser does this code open? a) Internet Explorer b) Opera c) FireFox d) Safari class Google { public static void main(String []args) { http://www.google.com System.out.println("Hello world"); } }
  • 7. “95% of the folks out there are completely clueless about floating-point” -James Gosling (in 1998 JavaOne keynote address) Floating-point Numbers are Tricky!
  • 8. Another Example class FloatCompare { public static void main(String []args) { double x = 2.0; double y = Math.sqrt(x) ; System.out.println( (y * y) == x); } }
  • 10. Question #4 Which one of the following best describes the behavior of this code? a) This code segment will give compiler error(s) b) This code segment will return 1 to the caller c) This code segment will return null to the caller d) This code segment will result in throwing a NullPointerException
  • 11. Question #5 class Append { public static void main(String []args) { StringBuffer sb = new StringBuffer('H'); sb.append('i'); System.out.println(sb); } } Which one of the following best describes the behavior of this code? a) This code segment will give compiler error(s) b) This code segment will print “Hi” c) This code segment will print “H” d) This code segment will print “i”
  • 12. Question #6 class ReplaceAll { public static void main(String []args) { String date = "18-03-2017" ; String date1 = date.replaceAll( "-" , "." ) ; String date2 = date1.replaceAll( "." , "/" ) ; System.out.println(date2); } } What is the output of this program? a) 18-03-2017 b) ---------- c) ………. d) //////////
  • 15. Question #9 class Base { public Base() { System.out.println("In Base ctor"); } } class Derived extends Base { public Derived() { System.out.println("In Derived ctor"); } } class UseArray { public static void main(String []args) { Base [] array = new Derived[2]; array[0] = new Base(); array[1] = new Derived(); } }
  • 16. Question #10 class Stack { private final int CAPACITY = 100; private Object[] array = new Object[CAPACITY]; private int size = 0; public void push(Object val) { if (size < CAPACITY) array[size++] = val; else throw new StackFullException(); } public Object pop() { if (size == 0) throw new StackEmptyException(); else return array[--size]; } }