Monday, 21 July 2014

Top 15 Logical Puzzles and BrainTeasers :Tips and Tricks of Java Programming Puzzles

op investment banks or reputed companies  asked many Java Programming Puzzles  as well as brainteasers questions to the candidates. These logical puzzles in java interview are used to check whether candidate can think out of box if facing difficult and complex problems.Let us discuss the tips to tackle such kind of questions in effective way. 

Tips to Solve Java Programming Puzzles and Brainteasers  

1. While answering Java Programming Puzzles ,remember that the obvious answer is almost never the right answer.

2. If the solution that seems logical is wrong, you made a false assumption.Categorize your assumptions, and try to identify those that are false.

3. Don’t be intimidated by complexity. Try a subproblem, a simplified version,or some examples. Be patient, keep working, and keep talking.

4. When you’re stuck on a simple, restricted problem, brainstorm all the possibilities to identify the one you’re missing.


Java Programming Puzzles and Brainteaser Questions 

logical puzzles java interview question
Q1  You are standing in a hallway next to three light switches  switches, all of which are off. Each switch operates a different incandescent light bulb in the room at the end of the hall. You cannot see the lights from where the switches are. Determine which light corresponds to each switch. You may go into the room with the lights only once.


Q2  How do you cut a rectangular cake into two equal pieces when someone has already removed a rectangular piece from it ? The removed piece can be of any size or orientation. You are allowed just one straight cut .




Q3   You have eight marbles and a two-pan scale. All the marbles weigh the same, except for one which is heavier than all the others. The marbles are otherwise indistinguishable. You may make no assumptions about how much heavier the heavy marble is. What is the minimum number of weighing needed to be certain of identifying the heavy marble? Now generalize the question. What is the minimum number of weighing to find a heavy marble among n marbles?



Q4  Christine and Siri have 21$ between them. Christine has 20$ more than Siri. How much does each have. You cant use fractions in the answer 



Q5  A party of four travelers comes to a rickety bridge at night. The bridge can hold the weight of at most two of the travelers at a time, and it cannot be crossed without using a flashlight. The travelers have one flashlight among them. Each traveler walks at a different speed: The first can cross the bridge in 1 minute, the second in 2 minutes, the third in 5 minutes, and the fourth takes 10 minutes to cross the bridge. If two travelers cross together, they walk at the speed of the slower traveler. What is the least amount of time in which all the travelers can cross from one side of the bridge to the other?

Q6  You have 10 Jars filled with marbles. Each marble weighs 10 gm, except one Jar which contains defective marbles which weighs 9 gm. Given a scale to weigh, How do you find Jar with defective marbles in just one measurement. Here scale is modern day electronic scale to measure weight.



Q7  A person shoots her wife. Then holds her under water for 5 minutes. Finally, he hangs her. But after 10 minutes they both go out together and enjoy a wonderful dinner together. How can this be?


Q8  A father and son are going in a car and suddenly there car met accident. Father died on the spot but the child rushed to the hospital. When he arrives in the hospital, doctor says, "I can't operate on this child, he is my son!" How can this be?


Q9  There are three ants on different vertices of a triangle. What is the probability of collision (between any two or all of them) if they start walking on the sides of the triangle? Similarly find the probability of collision with ‘n’ ants on an ‘n’ vertex polygon.


Q10  Starting from one end , one complete burn (burning from one end to other end)  requires 1 hour each for two sticks.Assuming that sticks do not burn at constant rate i.e some part may burn faster then the other part of the stick. You need to measure 45 minutes by using these two sticks and  a lighter.


More Difficult Questions 

Q11  A small school with only 100 lockers  has this ritual on the last day of school: The student go into the hall and stand by their closed lockers. At the first blow of a whistle, the students open every locker. At the second whistle, the students close every second locker(lockers 2,4,6 etc. are slammed shut). At the third whistle , the students toggle every third locker. To "toggle" means to close if it's open, and to open if it's closed. They toggle lockers 3,6,9 etc.to 99. At whistle four, they toggle every fourth locker. At whistle five , they toggle every fifth locker and so on.
At the hundreth whistle , the student standing next to locker 100 (and only that student) toggles his locker. How many lockers are then open.

Q12  Every man in a village of fifty couples has been unfaithful to his wife. Every woman in the village instantly knows when a man other than her husband has philandered (meaning a man who easily enter into casual sexual relationships with women ) but not when her own husband has ("always the last to know").The village's no tolerance  adultery statute  requires that a woman who can prove her husband is unfaithful must kill him that very day.No woman would dream of disobeying this law.One day , the Queen , who is known to be infallible(meaning incapable of making mistakes or being wrong) , visits the village . She announces that atleast one husband has been unfaithful. What happens ?

Q13  Five pirates on an island have one hundred gold coins to split among themselves. They divide the loot as follows : The senior pirate proposes a division, and everyone votes on it. Provided at least half the pirates vote for the proposal , they split the coins that way.If not , they kill the senior pirate and start over. The most senior (surviving) pirate proposes his own division plan , and they vote by same rules and either divide the loot or kill the senior pirate, as the case may be. The process continues until one plan is accepted. Suppose you are the senior pirate.What division do you propose? (The pirates are all extremely logical and greedy, and all want to live).


Q14  You are in a boat in the exact center of a perfectly circular lake. There is a goblin on the shore of the lake. The goblin wants to do bad things to you. The goblin cant swim and doesn't have a boat.Provided  you can make it to the shore - and the goblin isn't there,waiting to grab you - you can always outrun him on land and get away.
The problem is this: The goblin can run four times as fast as the maximum speed of your boat.He has perfect eyesight,never sleeps and is extremely logical. He will do everything in his power to catch you. How would you escape the goblin?


Q15  One of your employees insists on being paid daily in gold. You have a gold bar whose value is that of seven days salary for this employee. The bar is already segmented into seven equal pieces. If you are allowed to make just two cuts in the bar and must settle with the employee at the end of each day, how do you do it?

 # Weird Logical Thinking Question 

1. How many gas stations are there in United States(Your country) ?

2. How would you locate a specific book in a big library? There's no cataloging system and no librarian to help you ?

We will share the answers shortly  in the mean time try to solve questions by yourself. If you solve any questions then Please mention answers in the comment . 
Reference;---

Friday, 18 July 2014

10 Articles Every Java Programmer Must Read

Being a Java programmer and Software developer, I have learned a lot from articles titled as What Every Programmer Should Know about ..... , they tend to give a lot of useful and in-depth information about a particular topic, which otherwise is very hard to discover. In my quest of learning I have come across some very useful articles, which I have bookmarked for reference and multiple reading. I personally think that all programmer can benefit by reading these articles, which makes me write this post and share all of these "What Every Programmer Should Know" articles with you guys. These are from my personal bookmarks. In this article, you will see classic what every programmer should know article from topics like memoryUnicodefloating point arithmeticnetworkingobject oriented designtimeURL EncodingString and many more. This list is very important for beginner and newcomers, as they are the ones, who lacks practical knowledge. Since most of these post are actually driven by practical knowledge, beginner and intermediate programmers can take a lot from it. Also gaining knowledge of fundamentals early in career helps to avoid mistakes, which has done by other programmers and software developers on their course of learning. Though it’s not easy to grasp all knowledge given in these articles in just one reading. You probably won't understand some details about floating point number or get confused with subtle details of memory, but it’s important to keep these list handy and refer them time to time with a context. So Good luck and Enjoy reading these wonderful articles.  By the way, don't forget to share any What Every Programmer Should know article, if it’s not already in this list.


What Every Programmer Should Know about Memory
This is one of the classic article, which will take you through may lanes of memory, some old, some new, some known and some unknown. Despite being so conman and omnipresent, not every programmer have enough knowledge of Memory. Knowledge of memory in modern system becomes even more important if you are in space of writing high performance application. Hardware designers have come up with ever more sophisticated memory handling and acceleration techniques–such as CPU caches–but these cannot work optimally without some help from the programmer. I am still reading this article, and I can't tell you how much I have learned from this about RAM, CPU Caches e.g. L1 and L2 cache, different types of memory, direct memory access, memory controller designs and Memory in general. In short, a must read for programmers of all level of experience.


What Every Computer Scientist Should Know About Floating-Point Arithmetic
Floating point arithmetic is a tricky topic, and it’s not easy to master. Even many Java programmer doesn't know what can go wrong when comparing float/double value with == operator. Many of us often makes mistake of doing monetary calculation in float and double. This article is another gem of this series and must read for all software developers and programmers. As your experience grows, you are expected to know subtle details of common things, and floating point arithmetic is one of them. As as senior Java developer, you must know how do perform monetary calculation, when to use floatdouble or BigDecimal classes, how to round floating point numbers etc. Even if you know fundamentals of floating point arithmetic, You will learn something new about floating point calculation by reading this article.


What Every Developer Should know about Unicode
Character encoding is another area, where many programmer struggle, and "The Absolute Minimum Every Software Developer Absolutely, Positively Must Know About Unicode and Character Sets (No Excuses!)" aims to fill that gap. On side note, Yes that's the full title of that article. It was written by Joel Spolsky, one of the founder ofstatckoverflow.com. Joel has written this post on his blog almost 10 years back, but it is still relevant in today’s world. This article will teach you about What is Unicode, What is character encoding, how characters are represented using bytes and many more. One of the best thing about this article is language and flow, even if you don't know anything about Unicode, you can easily follow. In short, one more must read for all programmers, coders and software engineers.


What Every Programmer Should know about Time
Apart from Character encoding, time and date is another area, where many programmers struggle, including me. Even senior developers lost between GMT, UTC, day light saving and between leap seconds. Frankly speaking, It's not easy to deal with time zones without making any mistake, then add day light savings and effect of that. Problems becomes worse if you using trial and error method, because you will never able to solve your problem by doing that. There are so many things which can go wrong and there are equal number of misconceptions. Things like, whether date contains time-zone or not can confuse you like hell, converting UNIX time to other time-zone can freak you out, forget about clock synchronization and delays. I hope many of your misconception about time will go away and you will build sound fundamental about Time, by reading this classic article.


What every web developer must know about URL encoding
This article describes common misconceptions about Uniform Resource Locator (URL) encoding, then attempts to clarify URL encoding for HTTP, before presenting frequent problems and their solutions. While this article is not specific to any programming language, it illustrate the problems in Java) and finish by explaining how to fix URL encoding problems in Java, and in a web application at several levels. You will learn basics of URL grammar, general URL syntax in HTTP and other protocol. This article also explores common pitfalls of URLs e.g. character encoding, reserved character at different part of URL, and URL encoding/decoding issues. If you are a Java programmer, then you will also learn about how to handle URLs in Java application, the right way. How to construct URL and using Apache commons HTTP client library. Finally it also suggest best practices or dealing with URLs e.g. you should encode URLs when you build them, making sure your URL-rewrite filters deal with your URL correctly and many more. In short, a must read article for any web developer and programmer.



What should every programmer know about web development?
What Every Programmer and Devleper Should know Memory, Time, Date, String,UnicodeThis is an interesting article from programmers stack exchange, about what should every programmer implementing the technical details of a web application consider before making the site public. This includes things ranging from Interface design and User ExperienceSecurityWeb standardsPerformance,Search Engine Optimization(SEO), Technology involved, and about several important resources. Since today's world is hugely dependent upon internet and programmer having their personal site, blog is quite common. Experience learned on this article will not even help in your professional work but also in your personal work. You will learn about all key technology e.g. HTTP, HTML, XML, CSS, JavaScript, browsers compatibility, tips to reduce loading time of your website, XML sitemaps, W3C specifications and several other key details.


What Every Programmer Should Know About SEO
This is another article, which is very important for web developers, programmers and blogger. SEO is too big to ignore, since many programmers are also blogger, it’s important to learn few basics of Search Engine Optimization to help Google find their content and present to other fellow programmers. Since no company can survive without web presence in today's inter-connected world, SEO becomes even more important. If you own start-up, selling any product, then SEO is something to care about. All programmers, especially web developers can largely benefit from this article. Remember, Search Engine Optimization is vast and very dynamic subject, and also varies between different search engines e.g. Google, Yahoo, and others. So, In order to master this topic you will always need to update your knowledge.


What Every C Programmer Should Know About Undefined Behaviour #1/3
C programming language have the concept of "undefined behaviour". Undefined behaviour is a broad topic with a lot of nuances and that's one reason of Why I like Java, less number of undefined behaviour, less confusion, more stability and more peace. Many seemingly reasonable things in C actually have undefined behaviour, and this is a common source of bugs in programs. Beyond that, any undefined behaviour in C gives license to the implementation (the compiler and runtime) to produce code that formats your hard drive, does completely unexpected things, or worse. Read this excellent article to deep dive on sea of undefined behaviour


What Every Programmer Need to know about networking
From the article itself "You’re a programmer. Have you ever wondered how multi-player games work? From the outside it seems magical: two or more players sharing a consistent experience across the network like they actually exist together in the same virtual world. But as programmers we know the truth of what is actually going on underneath is quite different from what you see. It turns out that it’s all an illusion." This is very interesting article about networking, written for game programmers but I think every programmer and developer can benefit from this.


What Every Java Developer Should Know about String
This is my article on java.lang.String and what I personally thing every Java programmer should know about it. String is very important in day to day programming in Java and that's why good knowledge is must for any Java developer. This article touches many important areas of String including string pool, string literal, comparing String using == vs equals(), converting bytes to String, Why String is immutable, properly concatenating Strings and many more. Advanced programmer may already know all these stuffs but even then it’s good to revise them.


What should every programmer know about security?
This question was ask by one computer programming student in StackOverFlow. Just like we learn a lot about general programming concepts e.g. operating system, algorithm, data-structure, computer architecture, and other stuff, its also important to know about security. Though Security is vast topic ranging from encryption/decryption, SSL, web security, obfuscation, authentication, authorization etc, a basic minimum knowledge is must for every programmer. I personally didn't know much about Security when I started my career, its when I start writing Servlet/JSP based Java web application, I come to know about web security and several security threats like SQL InjectionDenial of ServiceXML InjectionCross site scripting and others. As Java developer, now I follow secure Java coding practices provided by fortify, PMP and other static code analysis providers.  This article is very good collection of topics and links about Security and whether you are doing coding or not, you will surely benefit from this resource.


Latency Numbers Every Programmer Should Know
This is the bonus article, but must read for every Programmer. In order to write high performance application in any programming language e.g. Java or C++, you ought to know fundamental latency numbers e.g. how much time it take to read a variable from memory, from L1 Cache, from L2 cache, from random read in SSD and from disk. How much time it take to lock unlock on mutex, to send a data packet from one city to another or doing a roundtrip on same data centre. These latency numbers are independent of any programming language and part of core knowledge, a developer must have to write high frequency low latency applications. Good thing about this link is that it also provides you comparative analysis of how these latency numbers have evolved over the years. You can see what these latency numbers were in 2006 and what they are now.


That's all in this list of article every Programmer must read. By reading articles titles as What Every Programmer or Developer Should know, you gain in-depth knowledge of a particular topic. Frankly speaking there are too many things to learn for programmers, learning a programming language like Java is just a tip of iceberg, but isn't it many of us have passion for learning. Programming is a challenging job, and only things which help you all along your career is fundamental knowledge e.g. things about MemoryUnicodefloating point numberstimesecurity is very important for any programmer. Few things are programming language specific e.g. my post about Java String and What every C programmer should know about undefined behaviour, but they are still good to learn for many beginner and developers.

Reference: http://javarevisited.blogspot.com/2014/05/10-articles-every-programmer-must-read.html#ixzz37pQU8B2z

SCALA vs JAVA

Scala is new generation JVM language, which is generating popularity as alternative of arguable one of the most popular language Java. It's not yet as popular as Java, but slowly getting momentum. As more and more Java developers are learning Scala and inspired by Twitter, more and more companies are using Scala, it's future looks very bright. To start with, Scala has several good feature, which differentiate it from Java, but same time it has lot of similarities as well e.g. both Scala and Java are JVM based language, You can code Scala in Java way and Scala can use any Java library, which in my opinion a great decision made by designers of Scala. Since tremendous works has already been done in form of open source framework and library in Java, it's best to reuse them, rather than creating a separate set for Scala. Out of several differences, one of the main difference between Scala and Java is it's ability to take advantage of Functional programming paradigm and multi-core architecture of current  CPU. Since current CPU development trend is towards adding more cores, rather than increasing CPU cycles, it also favors functional programming paradigm. Though this differences may not be significant, once Java 8 will introduce lambdas, but it might be too early to comment. Apart from functional programming aspect, there are many other differences as well. One of the obvious one is improved readability and succinct code. Java is always on firing line for being too verbose, I thing Scala does take care of that and code which took 5 to 6 lines in Java, can be written in just 2 to 3 lines in Scala. Well Grounded Java Developer has some nice introduction on JVM languages like ScalaGroovy and Closure, which is worth reading.  In this article, we will see such kind of similarities and differences between Scala and Java.

Similarities between Scala and Java

Following are some of the major similarities between Scala and Java programming language :

1) Both are JVM based language, Scala produce same byte code as Java and runs on Java Virtual Machine. Similar to Java compiler javac, Scala has a compiler scalac, which compiles Scala code into byte code. At this level, all JVM language like GroovyJRubyScala becomes equals to Java, because they use same memory space, type system and run inside same JVM.

2) You can call Scala from Java and Java from Scala, it offers seems less integration. Moreover, you can reuse existing application code and open source Java libraries in Scala.

3) Major Java programming IDE like Eclipse, Netbeans and InetelliJ supports Scala.

4) One more similarity between Scala and Java is that both are Object Oriented, Scala goes one steps further and also supports functional programming paradigm, which is one of it's core strength.


Differences between Scala and Java

1) First and Major difference you will notice between Scala and Java is succinct and concise code. Scala drastically reduce number of lines from a Java application by making clever use of type inference, treating everything as object, function passing and several other features.

2) Scala is designed to express common programming patterns in elegant, concise and type-safe way. Language itself encourage you to write code in immutable style, which makes applying concurrency and parallelism easily.

3) One difference, which some might not notice is learning curve. Scala has steep learning curve as compared to Java, my opinion may be slightly biased because I am from Java background, but with so much happening with little code, Scala can be really tricky to predict. Syntax of Scala looks confusing and repulsive as compared to Java, but I am sure that is just the starting hurdle. One way to overcome this hurdle is following a good Scala book like  Programming in Scala or Scala in Action, both are excellent books for a Java developer, who wants to learn Scala

4) One of Scala's cool feature is built-in lazy evaluation, which allows to defer time consuming computation, until absolutely needed and you can do this by using a keyword called "lazy" as shown in below code :
 
// loading of image is really slow, so only do it if need to show image
lazy val images = getImages()  //lazy keyword is used for lazy computation

if(viewProfile){
    showImages(images)
}
else(editProfile){
    showImages(images)
    showEditor()
}
else{
    // Do something without loading images.
}

If you love to learn by following examples, then I guess Scala CookBook is a another good buy, contains tons of examples on different features of Scala.

5) Some one can argue that Java is more readable than Scala, because of really nested code in Scala. Since you can define functions inside function, inside another functions, inside of an object inside of a class. Code can be very nested. Though some time it may improve clarity, but if written poorly it can be really tricky to understand.

6) One more difference between Scala and Java is that Scala supports Operator overloading. You can overload nay operator in Java and you can also create new operators for any type, but as you already know, Java doesn't support Operator Overloading.

7) Another major difference between Java and Scala is that functions are objects in Java. Scala treats any method or function as they are variables. When means, you can pass them around like Object. You might have seen code, where one Scala function is accepting another function. In fact this gives the language enormous power.

8) Let's compared some code written in Scala and Java to see How much different it look:


Java:

List<Integer> iList = Arrays.asList(279810);
List<Integer> iDoubled = new ArrayList<Integer>();
for(Integer number: iList){
    if(number % 2 == 0){
        iDoubled.add(number  2);
    }
}

Scala:

val iList = List(279810);
val iDoubled = iList.filter(_ % 2 == 0).map(_  2)

You can see that Scala version is lot succinct and concise than Java version. You will see more of such samples, once you start learning functional programming concepts and patterns. I am eagerly waiting for Scala Design Patterns: Patterns for Practical Reuse and Design by John Hunt, which is not yet released and only available for pre order. This book is going to release this month. 


That's all on this article about similarities and differences between Scala and Java.  Though they are two separate programming language, they have lot in common, which is not a bad thing at all and in my opinion that's the only thing, which will place Scala as Java alternative, if at all it happens in future. As I had mentioned in my post10 reason to learn Java programming, that Java tools, libraries, and community is it's biggest strength and if Scala can somehow reuse that, it will be well ahead, forget about competing though, it will take years to build such community and code. For a Java programmer, I would say nothing harm in learning Scala, most likely you will learn few good practices, which you can even apply in Java, as corporate sector is still on Java, and Scala in it's early days, you can be well ahead, if you learn Scala now. On closing note, at high  level Scala looks very promising, all design decision made are really good and they came after several years of experience with Java. 

Recommended Books on Scala for Java Programmers
Books are best way to learn a new programming language, first of all they contains complete information but also in much more readable and authentic form. I strongly recommend to follow at-least one book, before jumping on blogs and online articles. One reading any Scala Programming book is must to build fundamental, which is indeed necessary, given rather steep learning curve of Scala. Following are my list of some books from which you can choose one.

Programming in Scala: A Comprehensive Step-by-Step Guide, 2nd Edition by Martin Odersky, Lex Spoon and Bill Venners 
Scala for the Impatient by Cay S. Horstmann
Scala in Depth by Joshua D. Suereth and Martin Odersky

Thanks folks, Enjoy learning Scala.
find the tutorial
http://www.tutorialspoint.com/scala/

Reference http://javarevisited.blogspot.com/2013/11/scala-vs-java-differences-similarities-books.html#ixzz37pKpd4tw

10 Examples of HotSpot JVM Options in Java

There are hundreds of JVM parameters or JVM Options exists inside sun JDK and its virtually impossible to keep track of every single JVM option and based on my experience we don't even use most of JVM flags except couple of important JVM option related to java heap size, java options for printing garbage collection details and most likely JVM switches for setting up remote debugging in Java. but there are many other useful category of JVM parameters which you at least like to be familiar even if not intending to use it more frequently. In this article we will see examples of 10 different categories of JVM parameter which I found useful and use more frequently than other. I would recommend to get a full knowledge of what does a particular JVM options does by referring official list of JVM options.

JVM parameters in Java

On the basis of how we specify JVM option it can be divided into two parts, JVM Options which starts with –X and those which starts with -XX:
1)    JVM Options that begin with -X are non-standard (thy are not guaranteed to be supported on all JVM implementations), and are subject to change without notice in subsequent releases of the JDK.
2)    JVM Options or parameters which are specified with -XX are not stable and are not recommended for casual use. These options are subject to change without notice also.

Frequently used JVM parameters for heap, GC and debugging
I was thinking about writing post on JVM options when I completed my post on Java Heap Size and Java Garbage Collection because these are two main area where we see usages of various JVM flags. But it didn’t happened even after I covered OutOfMemoryError post which has some JVM option to solve OutOfMemoryError in Java. Now I am happy that I have completed this piece of information and its ready to be published. As always I look for your feedback, suggestions and any other JVM flags which I have missed and you guys find useful to share. 

Good knowledge of JVM options specially related to GC tuning is important for time critical application e.g. high volume low latency electronic trading platform where every micro seconds matter. though getting right combination requires lot of profiling and trial and error and depends heavily on nature of trading application.

Important Points about JVM Options:


1)    Boolean JVM options can be  turned on with -XX:+ and can be turned off with -XX:-.
2)    Numeric JVM Options can be set with -XX:=. Numbers can include 'm' or 'M' for megabytes, 'k' or 'K' for kilobytes, and 'g' or 'G' for gigabytes (for example, 32k is the same as 32768).
3)    String JVM options can be set by using -XX:=, and usually used to specify a file, a path, or a list of commands.


The command java -help lists the standard options (standard across different JVM implementations) for the Java application launcher. The command java -X can be used to see the Java application launcher's non-standard (X for extension specific to that JVM) arguments.The -X options are non-standard and subject to change without notice. If you wish to detect which JVM arguments your currently running Java application is using, you can use the ManagementFactory.getRuntimeMXBean().getInputArguments()

Now here is my list of important JVM flags, switches, options or parameters which is most commonly used while running Java applications:


1) JVM memory options related to java heap size
Following three JVM options are used to specify initial and max heap size and thread stack size while running Java programs.

 -Xms        set initial Java heap size
 -Xmx        set maximum Java heap size
 -Xss>         set java thread stack size

2) JVM option to print gc details
-verbose:gc logs garbage collector runs and how long they're taking. I generally use this as my first tool to investigate if GC is a bottleneck for a given application.

-XX:+PrintGCDetails includes the data from -verbose:gc but also adds information about the size of the new generation and more accurate timings.

-XX:-PrintGCTimeStamps  Print timestamps at garbage collection.



3) JVM parameters to specify Java Garbage collector
-XX:+UseParallelGC      Use parallel garbage collection for scavenges
-XX:-UseConcMarkSweepGC Use concurrent mark-sweep collection for the old generation. (Introduced in 1.4.1)
-XX:-UseSerialGC        Use serial garbage collection. (Introduced in 5.0.)

beware when you use GC Parameters if you are working on time critical application e.g. high frequency trading application. As  GC is time consuming operation and its desired to create a balance.

4) JVM debug options JVM options for remote debugging
-Xdebug -Xnoagent -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=8000
to read more about remote debugging check How to Setup Java remote debugging in Eclipse and 10 Java debugging tips in Eclipse 

5) JVM options related to profiling
-Xprof
-Xrunhprof

6) JVM options related to java classpath
Xbootclasspath specifies classpath entries you want loaded without verification. The JVM verifies all classes it loads to ensure they don't try to dereference an object with an int, pop extra entries off the stack or push too many, and so on. This verification is part of the reason why the JVM is very stable, but it's also rather costly, and responsible for a large part of start up delay. Putting classes on the bootclasspath skips this cost, but should only be used when you know the classes have been verified many times before. In JRuby, this reduced startup time by half or more for a simple script. The -Xbootclasspath option can be used to either prepend (/p) or append (/a) resources to the bootstrap classpath. You Can read more about Java Classpath in my articles How Classpath Works in Java and How to Solve ClassNotFoundException in Java

7) JVM options to change  Perm Gen Size
These JVM optiosn are quite useful to solve java.lang.OutOfMemoryError:Perm Gen Space.

-XX:PermSize and MaxPermSize
-XX:NewRatio=2  Ratio of new/old generation sizes.
-XX:MaxPermSize=64m     Size of the Permanent Generation.

8) JVM parameters to trace classloading and unloading
-XX:+TraceClassLoading and -XX:+TraceClassUnloading are two JVM options which we use to print logging information whenever classes loads into JVM or unloads from JVM. These JVM flags are extremely useful if you have any memory leak related to classloader and or suspecting that classes are not unloading or garbage collected.

9) JVM switches related to logging
-XX:+TraceClassLoading and -XX:+TraceClassUnloading print information class loads and unloads. Useful for investigating if you have a class leak or if old classes (like JITed Ruby methods in JRuby) are getting collected or not. You can read more about logging in Java on my post 10 Tips while logging in Java

-XX:+PrintCompilation prints out the name of each Java method Hotspot decides to JIT compile. The list will usually show a bunch of core Java class methods initially, and then turn to methods in your application. In JRuby, it eventually starts to show Ruby methods as well

10) JVM Switches for debugging purpose
-XX:HeapDumpPath=./java_pid.hprof  Path to directory or file name for heap dump.
-XX:-PrintConcurrentLocks       Print java.util.concurrent locks in Ctrl-Break thread dump.
-XX:-PrintCommandLineFlags   Print flags that appeared on the command line.

That’s all on JVM Options, I understand its not possible to remember all JVM flags but at-least having an idea of what kind of JVM flags are available is good asset. Image for JVM parameters is from Java tuning and Nutshell.  For full list of JVM options you can refer these link from Oracle Java site: Java Hotspot VM Options

Other Java programming tutorials you may like
Why character array is better than String for storing password 
How to convert String to Date in Java with Example 
How to split String in java with Example


Reference:

http://javarevisited.blogspot.sg/2011/11/hotspot-jvm-options-java-examples.html