Friday, August 1, 2014

JavaFX 8: Introduction by Example, 2nd edition

JavaFX 8: Introduction by Example shows you how to use your existing Java skills to create graphically exciting client applications with the JavaFX 8 platform. The book is a new and much improved edition of JavaFX 2.0: Introduction by Example, taking you through a series of engaging, fun-to-work examples that bring you up to speed on the major facets of the platform. It will help you to create applications that look good, are fun to use, and that take advantage of the medium to present data of all types in ways that engage the user and lead to increased productivity.

Entirely example-based, JavaFX 8: Introduction by Example begins with the fundamentals of installing the software and creating a simple interface. From there, you'll move in progressive steps through the process of developing applications using JavaFX’s standard drawing primitives. You'll then explore images, animations, media, and web. This new edition incorporates the changes resulting from the switch to Java 8 SDK. It covers advanced topics such as custom controls, JavaFX 3D, gesture devices, and embedded systems.  Best of all, the book is full of working code that you can adapt and extend to all your future projects.

  • Entirely example-based
  • Filled with fun and practical code examples
  • Covers all that's new in Java 8 relating to JavaFX such as Lambda expressions and Streams
  • Covers gesture devices, 3D display, embedded systems, and other advanced topics

What you’ll learn
  • Install JavaFX 8 and configure your environment
  • Work with touch-based interfaces such as in Windows 8
  • Interpret gesture-based events the Leap Motion Controller and similar hardware
  • Integrate JavaFX with embedded systems such as Arduino and Raspberry Pi
  • Develop modern GUI implementations of business forms
  • Work with shapes, color, text, and animation
  • Add audio and video to your projects
  • Create custom controls using SVG and Canvas
  • Learn to style a user-interface via CSS
  • Communicate bidirectionally using Java and Javascript with HTML5

Who this book is for

JavaFX 8: Introduction by Example is for Java developers who are interested in developing rich, client-side applications to run on PCs, phones, tablets, Arduino controllers, the Raspberry Pi, and more. Whether enterprise developer or hobbyist, anyone wanting to develop a polished user-interface from Java will find much to like in this book.

Table of Contents
1. Getting started
2. JavaFX Fundamentals
3. Java 8 Lambda Expressions
4. Layout & UI Controls
5. Graphics with JavaFX
6. Custom Controls
7. Media with JavaFX
8. JavaFX on the Web
9. JavaFX 3D
10. JavaFX and Arduino
11. JavaFX on the Raspberry Pi
12. Gesture-based Interfaces
13. Appendix A. References

Monday, July 28, 2014

Convert integer to String base on various radix


package java_stringof;

/**
 *
 * @web http://java-buddy.blogspot.com/
 */
public class Java_StringOf {

    public static void main(String[] args) {
        int src = 0xFF;
        System.out.println("radix=2: " + Integer.toString(src, 2));
        System.out.println("radix=8: " + Integer.toString(src, 8));
        System.out.println("radix=10: " + Integer.toString(src, 10));
        System.out.println("radix=16: " + Integer.toString(src, 16));
    }
    
}

Sunday, July 27, 2014

Divide a number (int, float, double) by zero

Here show that if you divide a int by zero, it will throw ArithmeticException of by zero. But it you divide a float or double by zero, no exception will be thrown. It return Infinity or -Infinity, and equal to POSITIVE_INFINITY or NEGATIVE_INFINITY.


package java_dividebyzero;

/**
 *
 * @web http://java-buddy.blogspot.com/
 */
public class Java_DivideByZero {

    public static void main(String[] args) {
        
        System.out.println("\n--- Test Divide By Zero on int: 100/0 ---");
        int int1 = 100;
        int intResult;
        
        try{
            intResult = int1/0;
            System.out.println(intResult);
        }catch (ArithmeticException ex){
            System.out.println("catched: " + ex);
        }
        
        System.out.println("\n--- Test Divide By Zero on float: 100/0 ---");
        float float1 = 100;
        float resultFloat;
        
        try{
            resultFloat = float1/0;
            System.out.println(resultFloat);
            System.out.println("resultFloat == Float.POSITIVE_INFINITY : " + (resultFloat == Float.POSITIVE_INFINITY));
            System.out.println("resultFloat == Float.NEGATIVE_INFINITY : " + (resultFloat == Float.NEGATIVE_INFINITY));
            System.out.println("resultFloat == Float.NaN : " + (resultFloat == Float.NaN));
        }catch (ArithmeticException ex){
            System.out.println("catched: " + ex);
        }
        
        System.out.println("\n--- Test Divide By Zero on double: -100/0 ---");
        double double1 = 100;
        double resultDouble;
        try{
            resultDouble = -1 * double1/0;
            System.out.println(resultDouble);
            System.out.println("resultDouble == Double.POSITIVE_INFINITY : " + (resultDouble == Double.POSITIVE_INFINITY));
            System.out.println("resultDouble == Double.NEGATIVE_INFINITY : " + (resultDouble == Double.NEGATIVE_INFINITY));
            System.out.println("resultDouble == Double.NaN : " + (resultDouble == Double.NaN));
        }catch (ArithmeticException ex){
            System.out.println("catched: " + ex);
        }
    }
    
}