Skip to main content

Posts

Exercise 1: 99 Bottles of Beer

Let’s put all your new Java skills to good use with something practical. We need a class with a main(), an int and a String variable, a while loop, and an if test. A little more polish, and you’ll be building that business backend in no time. But before you look at the code on this page, think for a moment about how you would code that classic children’s favorite, “99 bottles of beer.” There’s still one little flaw in our code. It compiles and runs, but the output isn’t 100% perfect. See if you can spot the flaw , and fix it. public class BeerSong { public static void main (String[] args) { int beerNum = 99; String word = “bottles”; while (beerNum > 0) { if (beerNum == 1) { word = “bottle”; // singular, as in ONE bottle. } System.out.println(beerNum + “ ” + word + “ of beer on the wall”); System.out.println(beerNum + “ ” + word + “ of beer.”); System.out.println(“Take one down.”); System.out.println(“Pass it around.”); beerNum = beerNum - 1; if (...
Recent posts

Hey! Do you know Interface can implement method?

In Java 8 , among a lot of rich features, one of the feature you should know about is related to Interface, you can implement method by using keyword: default. This is more easier when you think about multi-inheritance.

Let's Learn Java - JavaEE Sample and Vaadin Sample

Please find two presentations recently made during Barcamp Phnom Penh last weekend. JavaEE With Server and Client test to illustrate how Java Enterprise works with EJB 3. Find presentation and source at:  https://github.com/JavaCambodia/JavaEE-Sample Vaadin The sample and presentation to illustrate how power of Vaadin for those who has even basic knowledge in Java. Vaadin is about UI which you can code a very nicely interface for business application. You can find the presentation and source at:  https://github.com/JavaCambodia/Vaadin-ContactSystem Community Get in touch together: - Community: at Google+ Community - JavaCambodia @ Slack, to submit here to get invitation to join the chat.

Happy 20th Birthday, Java Programming language

Let's celebrate 20th Birthday of Java programming language and technology. Let's see how from 1995 to 2015 happens to Java via here. This infographic is from the eXo Platform blog:

Java Heap Space Exception, One of Weired Issue for Java Developer

Running Java application requires a lot of memory to load, execute and running. When you run one of the Java application, it does not only your application need memory but the web container such as Tomcat also required. It is more annoyed for you as a developer that you use many development tools that running on JVM such as Maven, Eclipse IDE, Tomcat and other stuffs. The memory firstly is about your RAM, regularly, you might have only 8GB RAM as normal as mine that I though it's enough but usually, it's not. Let's look to your Eclipse, the autocomplete code there, number of Java files and other automatic stuffs you do on the IDE that keeps you slowing everytimes; So that by theory, 8GB still not enough to go. Java heap issue can be solved by setting the right use of the memory as following way: -Xms<size> - Set initial Java heap size -Xmx<size> - Set maximum Java heap size Example: java -Xms512m -Xmx1024m JavaApp But never forget to calculate ho...

Java OOP - The Design Pattern [Image]