Skip to content

Instantly share code, notes, and snippets.

@press0
Last active April 23, 2018 01:00
Show Gist options
  • Save press0/98e55f6e2fba5b083dbd0fe4b0c276af to your computer and use it in GitHub Desktop.
Save press0/98e55f6e2fba5b083dbd0fe4b0c276af to your computer and use it in GitHub Desktop.
javaPuzzles
alias tdebug='cd /opt/tomcat; bin/catalina.sh jpda start; cd - > /dev/null'
alias tlogd='rm /opt/tomcat/logs/*'
alias tstart='cd /opt/tomcat; bin/startup.sh; cd - > /dev/null'
alias tstat='ps -ef|grep tomcat|grep -v grep'
alias tstop='/opt/tomcat/bin/shutdown.sh'
//void arrays - Which of the following doesn’t compile
void[] voids1 = new void[1]; (1)
Void[] voids2 = new Void[1]; (2)
Void[] voids3 = { }; (3)
Object voids4 = Array.newInstance(void.class, 1); (4)
//null reference - What does this do?
Thread t = null;
t.yield();
//compiler error
//runtime error
//JVM crashes
//JVM pauses briefly
//Which of the following creates an array of a generic type T which extends Object.
T[] ts1 = new T[1]; (1)
T[] ts2 = { new T(); }; (2)
T[] ts3 = (T[]) new Object[1]; (3)
T[] ts4 = Array.newArray(T.class, 1); (4)
//The following code compiles but what does it print?
char ch = '1';
ch /= 0.9;
System.out.println(ch);
//1
//1.111111111111111
//1.9
//6
//Which of the following prints 0.3
int x = 3;
System.out.println(x / 10); (1)
System.out.println(x * 0.1); (2)
System.out.println(x / 10.0); (3)
System.out.println(0 + '.' + x); (4)
System.out.println(0 + "." + x); (5)
//What is NOT true about this code?
public static void main(String... args) {
try (PrintWriter pw = null) { }
}
//doesn’t compile.
//compiles but it doesn’t if you replace PrintWriter with Writer.
//produces no error at compile time or runtime.
//code won’t compile if { } is replaced with ;.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment