Wednesday, November 26, 2014

Some information about java

What was the original name of Java?
  • Oak
What is the name of the Java mascot?
  • Duke
What is not true about JavaBeans?
  • They're fully compiled to native code.
Which is not an official edition?
  • BE
Which is never true for all possible values of x?
  • (x===x)
JavaFX is:
  • A language for building browser-based content
OpenJDK is not:
  • An open source tool for running Java in your browser or through Web Start
What does the letter "E" do when you create an interface with a generic specification like this:        public void interface List(){ }
  • "E" is a placeholder for the type.
10 Swing is to AWT as:
  • nio is to io
11 Which is not part of the Java EE 6 platform?
  • JavaFX
12 The Serialization API was created as:
  • A technique for converting objects to a well-defined sequence of bytes
13 Java Web Start is:
  • A set of tools for starting up JAR files directly from Web pages
14 Java Hot Spot is:
  • A just-in-time compiler that lets the JVM optimize byte code
15 Which platform doesn't run Java out of the box?
  • PC
16 What is the difference between an int and an Integer?
  • One is a primitive represented with four bytes, and the other is an object.
17 The Collection interface is used:
  • To have a standard interface for different ways to store collections of objects
18 Which is not true of a Java exception?
  • Exceptions can only jump over three blocks in order to make code easier to debug.
19 The Java sandbox:
  • Controls which classes run with the ClassLoader object




Tuesday, November 25, 2014

StringBuffer example


 public class BufferDemo  
 {  
      public static void main(String args[])  
      {  
           String foo="foo";  
           String a="abc"+foo+"def"+Integer.toString(47);  
           System.out.println(a);  
           StringBuffer ab= new StringBuffer("abc");  
           ab.append(foo);  
           ab.append("def");   
           ab.append(Integer.toString(47));  
           System.out.println(ab);  
      }  
 }  

Breaking loop in java

In example, Test class has a main method and a for loop inside it and printing the looped value on console and break syntax will hault the execution of loop.
 public class test2  
 {  
      public static void main(String args[])  
      {  
           for(int x=5;x<=10;x++)  
           {  
                if(x%10==0)  
                {  
                     System.out.println(x);  
                     break;  
                     System.out.println(x);  
                }  
           }  
      }  
 }  

String Manipulation in java

In example, Test class has a main method and local string variable with few string manipulation i.e length of string, character at given position and string comparison.
 public class Test1  
 {  
      public static void main(String args[])  
      {  
           String result1="hello java";  
           int result2=result1.length()%3;  
           char result3=result1.charAt(3);  
           String result4="result1"+"result1";  
           System.out.println(result1.equals("hello java"));  
           System.out.println(result2);  
           System.out.println(result3);  
           System.out.println(result4);  
           System.out.println(result1.lastIndexOf('w'));  
      }  
 }  

For loop example in java

In example, Test class has a main method and local variable with a for loop inside it and printing the looped value on console.
 public class Test   
 {  
      public static void main(String args [])  
      {  
           int total=0;  
           int a=0;  
           int num=4321;  
           for(int x=0;x<4;x++)  
           {  
                a=num/10;  
                num=num/10;  
                System.out.println(a);  
                total +=a;  
           }  
                System.out.println(total);  
      }  
 }