Computing Magazine

Java Trivia : 10 Bullet Points

Posted on the 04 April 2013 by Abhishek Somani @somaniabhi

  1. String are made immutable in java because Java maintains a String pool in perm gen space of memory. If the strings are mutable then it will be impossible to maintain the constant string pool in java.
  2. Calling Thread.sleep will not release the lock which is held by the object whereas calling wait on the object releases the lock
  3. Finalizer is the method which is run when before object is getting garbage collected and is totally different from Finally Block
  4. System.gc() method suggest the jvm to run grabage collector , although it is not necessary for jvm to run it
  5. We can tell JVM to execute some code after calling System.exit() by registering shutdown hook[Runtime.getRunTime().addShutdownHook(Thread)]
  6. System.exit() method terminates the jvm properly by executing registered shutdown hooks and running finalizers whereas Runtime.getRuntime.halt() shuts down the jvm immediately without running any shutdown hook or finalizer
  7. System.loadLibrary(String lib) loads the native library files from system(for windows it is dll).It searches the library in paths defined in System property "java.library.path". You will get "java.lang.UnsatisfiedLinkError: Can't load IA 32-bit x.dll on a AMD 64-bit platform" if you try to load a 32 bit library in 64 bit jvm process
  8. Java is always pass by value.References are copied when you pass from one method to another
  9. Null is a special type[apart from primitive and reference type] in java which has no name.You can not declare variable as null type and can not cast anything to null .It is neither class nor instance.
  10. Daemon Threads are background threads which do not prevent the jvm to wait for them to finish. If there is even a single non daemon thread running , JVM will not exit.
Post Comments and suggestions !! Java Trivia : 10 bullet points

Back to Featured Articles on Logo Paperblog

Magazines