Tuesday, April 15, 2014

Java Programming Interviews Exposed

Java Programming Interviews Exposed

If you are a skilled Java programmer but are concerned about the Java coding interview process, this real-world guide can help you land your next position

Java is a popular and powerful language that is a virtual requirement for businesses making use of IT in their daily operations. For Java programmers, this reality offers job security and a wealth of employment opportunities. But that perfect Java coding job won't be available if you can't ace the interview. If you are a Java programmer concerned about interviewing, Java Programming Interviews Exposed is a great resource to prepare for your next opportunity. Author Noel Markham is both an experienced Java developer and interviewer, and has loaded his book with real examples from interviews he has conducted.


  • Review over 150 real-world Java interview questions you are likely to encounter
  • Prepare for personality-based interviews as well as highly technical interviews
  • Explore related topics, such as middleware frameworks and server technologies
  • Make use of chapters individually for topic-specific help
  • Use the appendix for tips on Scala and Groovy, two other languages that run on JVMs

  • Veterans of the IT employment space know that interviewing for a Java programming position isn't as simple as sitting down and answering questions. The technical coding portion of the interview can be akin to a difficult puzzle or an interrogation. With Java Programming Interviews Exposed, skilled Java coders can prepare themselves for this daunting process and better arm themselves with the knowledge and interviewing skills necessary to succeed.

    Tuesday, April 8, 2014

    nashorn JavaScript exercise, call Java method from JavaScript

    This example show how to call Java javaStaticMethod() in "javatestnashornjavascript.JavaTestNashornJavascript" class.

    JavaTestNashornJavascript.java
    package javatestnashornjavascript;
    
    import java.io.FileNotFoundException;
    import java.io.FileReader;
    import java.net.URISyntaxException;
    import java.util.logging.Level;
    import java.util.logging.Logger;
    import javax.script.Invocable;
    import javax.script.ScriptEngine;
    import javax.script.ScriptEngineManager;
    import javax.script.ScriptException;
    
    /**
     * @web http://java-buddy.blogspot.com/
     */
    public class JavaTestNashornJavascript {
        
        final String myJavascript = "<path to myjavascript.js>";
        
        JavaTestNashornJavascript(){
            ScriptEngineManager scriptEngineManager = new ScriptEngineManager();
            ScriptEngine nashorn = scriptEngineManager.getEngineByName("nashorn");
    
            try {
                FileReader fileReader = new FileReader(myJavascript);
                nashorn.eval(fileReader);
    
                Invocable invocable = (Invocable) nashorn;
    
                Object jsResult = invocable.invokeFunction(
                        "javascriptFunction", "Java-Buddy");
                System.out.println("result returned to Java from JavaScript: " + jsResult);
    
            } catch (FileNotFoundException 
                    | ScriptException 
                    | NoSuchMethodException ex) {
                Logger.getLogger(JavaTestNashornJavascript
                        .class.getName()).log(Level.SEVERE, null, ex);
            }
        }
        
        public static String javaStaticMethod(String para){
            System.out.println("javaStaticMethod("+para+") called");
            String rev = new StringBuilder(para).reverse().toString();
            return rev;
        };
    
        public static void main(String[] args) throws URISyntaxException {
            
            JavaTestNashornJavascript javaTestNashornJavascript = 
                    new JavaTestNashornJavascript();
    
        }
    
    }
    


    myjavascript.js
    var javascriptFunction = function(para){
        
        print("para passed from Java to JavaScript: " + para);
        
        var myClass = Java.type("javatestnashornjavascript.JavaTestNashornJavascript");
        var revPara = myClass.javaStaticMethod(para);
        
        return "Hello " + revPara;
    };
    



    Monday, April 7, 2014

    nashorn JavaScript exercise, call JavaScript function from Java

    Example to call function and get result in Javascript, from Java code:

    JavaTestNashornJavascript.java
    package javatestnashornjavascript;
    
    import java.io.FileNotFoundException;
    import java.io.FileReader;
    import java.net.URISyntaxException;
    import java.util.logging.Level;
    import java.util.logging.Logger;
    import javax.script.Invocable;
    import javax.script.ScriptEngine;
    import javax.script.ScriptEngineManager;
    import javax.script.ScriptException;
    
    /**
     * @web http://java-buddy.blogspot.com/
     */
    public class JavaTestNashornJavascript {
        
        final String myJavascript = "<path to myjavascript.js>";
        
        JavaTestNashornJavascript(){
            ScriptEngineManager scriptEngineManager = new ScriptEngineManager();
            ScriptEngine nashorn = scriptEngineManager.getEngineByName("nashorn");
    
            try {
                FileReader fileReader = new FileReader(myJavascript);
                nashorn.eval(fileReader);
    
                Invocable invocable = (Invocable) nashorn;
    
                Object jsResult = invocable.invokeFunction(
                        "javascriptFunction", "Java-Buddy");
                System.out.println("result returned to Java from JavaScript: " + jsResult);
    
            } catch (FileNotFoundException 
                    | ScriptException 
                    | NoSuchMethodException ex) {
                Logger.getLogger(JavaTestNashornJavascript
                        .class.getName()).log(Level.SEVERE, null, ex);
            }
        }
    
        public static void main(String[] args) throws URISyntaxException {
            
            JavaTestNashornJavascript javaTestNashornJavascript = 
                    new JavaTestNashornJavascript();
    
        }
    
    }
    


    myjavascript.js
    var javascriptFunction = function(para){
        print("para passed from Java to JavaScript: " + para);
        return "Hello " + para;
    }
    



    more nashorn JavaScript exercise: