Tuesday, July 30, 2013

JAVA PROGRAM TO GENERATE MULTIPLICATION TABLE



Example-1: To print the multiplication table for the particular number.
(consider number is 4)-

public class multiply
{
public multiply(int a) //parameterized constructor
{
for(int i=1;i<=10;i++)
System.out.println(a+" * "+i+" = "+(a*i));
}

public static void main(String[] s)
{
multiply m=new multiply(4); //calling constructor with the value 4 (parameterized contructor)
}
}

Note: after compiling and using "java" statement, if anyone get "Error: could not find or load main class", then use "java -cp . filename".

Output:
javac multiply.java
java multiply


JAVA GLOBAL CERTIFICATION

Good evening, Now I am going to post about Global certification details of Java.We know that Oracle is conducting the Global certification exams for the java developers.I think This post helps You to know little bit  about it.

Oracle Certified Master Java SE Developer (OCMJD) (formerly Sun Certified Java Developer)

The Oracle Certification Program are IT Professional certifications for Oracle and Sun Microsystems products. There are three levels of Oracle Certification in several disciplines: Oracle Certified Associate (OCA), Oracle Certified Professional (OCP), and Oracle Certified Master (OCM). These certification are particularly designated for administrators and developers.

Oracle Certified Professional Java EE Web Component Developer (formerly Sun Certified Web Component Developer)

The Sun Certified Web Component Developer (SCWCD) certification targets information regarding Java components related to web-applications, specifically Servlets and Java Server Pages(JSPs). To achieve this certification, the candidate must pass a computer-based test available world-wide.


Oracle Certified Professional Java EE Business Component Developer (formerly Sun Certified Business Component Developer)

The Sun Certified Business Component Developer (SCBCD) certification targets information regarding Java components related to distributed applications, specifically Enterprise Java Beans(EJBs). To achieve this certification, the candidate must pass a computer-based test available world-wide at Prometric test centers.

Oracle Certified Expert Java Platform, EE Web Services Developer (formerly Sun Certified Developer for Java Web Services)

The Sun Certified Developer for Java Web Services 5 (SCDJWS) certification exam (designated CX-310-230) is for developers who have been Developer Pack, JAX-WS and JAXB. Other topics like XML, JSON, REST and security are covered too.



 Java SE 6 Programmer Certified Professional Exam
Exam Number:1Z0-851
Associated Certifications:Oracle Certified Professional, Java SE 6 Programmer
Exam Product Version:Java SE,
Exam Price:Rs 8014 More on exam pricing
Duration:150 minutes
Number of Questions:60
Passing Score:61% 
Validated Against:This exam has been validated against SE 5 and SE 6.
format:Multiple Choice
·         EXAM TOPIC FOR JAVA SE 6 PROGRAMMER CERTIFIED PROFESSIONAL EXAM

Section 1: Declarations, Initialization and Scoping
·         Develop code that declares classes (including abstract and all forms of nested classes), interfaces, and enums, and includes the appropriate use of package and import statements (including static imports).
·         Develop code that declares an interface. Develop code that implements or extends one or more interfaces.
·         Develop code that declares an abstract class. Develop code that extends an abstract class.
·         Develop code that declares, initializes, and uses primitives, arrays, enums, and objects as static, instance, and local variables. Also, use legal identifiers for variable names.
·         Given a code example, determine if a method is correctly overriding or overloading another method, and identify legal return values (including covariant returns), for the method.
·         Given a set of classes and superclasses, develop constructors for one or more of the classes. Given a class declaration, determine if a default constructor will be created, and if so, determine the behavior of that constructor. Given a nested or non-nested class listing, write code to instantiate the class.
Section 2: Flow Control
·         Develop code that implements an if or switch statement; and identify legal argument types for these statements.
·         Develop code that implements all forms of loops and iterators, including the use of for, the enhanced for loop (for-each), do, while, labels, break, and continue; and explain the values taken by loop counter variables during and after loop execution.
·         Develop code that makes use of assertions, and distinguish appropriate from inappropriate uses of assertions.
·         Develop code that makes use of exceptions and exception handling clauses (try, catch, finally), and declares methods and overriding methods that throw exceptions.
·         Recognize the effect of an exception arising at a specified point in a code fragment. Note that the exception may be a runtime exception, a checked exception, or an error.
·         Recognize situations that will result in any of the following being thrown: ArrayIndexOutOfBoundsException,ClassCastException, IllegalArgumentException, IllegalStateException, NullPointerException, NumberFormatException, AssertionError, ExceptionInInitializerError, StackOverflowError or NoClassDefFoundError. Understand which of these are thrown by the virtual machine and recognize situations in which others should be thrown programatically.
Section 3: API Contents
·         Develop code that uses the primitive wrapper classes (such as Boolean, Character, Double, Integer, etc.), and/or autoboxing & unboxing. Discuss the differences between the String, StringBuilder, and StringBuffer classes.
·         Given a scenario involving navigating file systems, reading from files, writing to files, or interacting with the user, develop the correct solution using the following classes (sometimes in combination), from java.io: BufferedReader, BufferedWriter, File, FileReader, FileWriter, PrintWriter, and Console.
·         Use standard J2SE APIs in the java.text package to correctly format or parse dates, numbers, and currency values for a specific locale; and, given a scenario, determine the appropriate methods to use if you want to use the default locale or a specific locale. Describe the purpose and use of the java.util.Locale class.
·         Write code that uses standard J2SE APIs in the java.util and java.util.regex packages to format or parse strings or streams. For strings, write code that uses the Pattern and Matcher classes and the String.split method. Recognize and use regular expression patterns for matching (limited to: . (dot), * (star), + (plus), ?, \d, \s, \w, [], ()). The use of *, +, and ? will be limited to greedy quantifiers, and the parenthesis operator will only be used as a grouping mechanism, not for capturing content during matching. For streams, write code using the Formatter and Scanner classes and the PrintWriter.format/printf methods. Recognize and use formatting parameters (limited to: %b, %c, %d, %f, %s) in format strings.
Section 4: Concurrency
·         Write code to define, instantiate, and start new threads using both java.lang.Thread and java.lang.Runnable.
·         Recognize the states in which a thread can exist, and identify ways in which a thread can transition from one state to another.
·         Given a scenario, write code that makes appropriate use of object locking to protect static or instance variables from concurrent access problems.
Section 5: OO Concepts
·         Develop code that implements tight encapsulation, loose coupling, and high cohesion in classes, and describe the benefits.
·         Given a scenario, develop code that demonstrates the use of polymorphism. Further, determine when casting will be necessary and recognize compiler vs. runtime errors related to object reference casting.
·         Explain the effect of modifiers on inheritance with respect to constructors, instance or static variables, and instance or static methods.
·         Given a scenario, develop code that declares and/or invokes overridden or overloaded methods and code that declares and/or invokes superclass, or overloaded constructors.
·         Develop code that implements "is-a" and/or "has-a" relationships.
Section 6: Collections / Generics
·         Given a design scenario, determine which collection classes and/or interfaces should be used to properly implement that design, including the use of the Comparable interface.
·         Distinguish between correct and incorrect overrides of corresponding hashCode and equals methods, and explain the difference between == and the equals method.
·         Write code that uses the generic versions of the Collections API, in particular, the Set, List, and Map interfaces and implementation classes. Recognize the limitations of the non-generic Collections API and how to refactor code to use the generic versions. Write code that uses the NavigableSet and NavigableMap interfaces.
·         Develop code that makes proper use of type parameters in class/interface declarations, instance variables, method arguments, and return types; and write generic methods or methods that make use of wildcard types and understand the similarities and differences between these two approaches.
·         Use capabilities in the java.util package to write code to manipulate a list by sorting, performing a binary search, or converting the list to an array. Use capabilities in the java.util package to write code to manipulate an array by sorting, performing a binary search, or converting the array to a list. Use the java.util.Comparator and java.lang.Comparable interfaces to affect the sorting of lists and arrays. Furthermore, recognize the effect of the "natural ordering" of primitive wrapper classes and java.lang.String on sorting.
Section 7: Fundamentals
·         Given a code example and a scenario, write code that uses the appropriate access modifiers, package declarations, and import statements to interact with (through access or inheritance) the code in the example.
·         Given an example of a class and a command-line, determine the expected runtime behavior.
·         Determine the effect upon object references and primitive values when they are passed into methods that perform assignments or other modifying operations on the parameters.
·         Given a code example, recognize the point at which an obje ct becomes eligible for garbage collection, determine what is and is not guaranteed by the garbage collection system, and recognize the behaviors of the Object.finalize() method.
·         Given the fully-qualified name of a class that is deployed inside and/or outside a JAR file, construct the appropriate directory structure for that class. Given a code example and a classpath, determine whether the classpath will allow the code to compile successfully.
·         Write code that correctly applies the appropriate operators including assignment operators (limited to: =, +=, -=), arithmetic operators (limited to: +, -, *, /, %, ++, --), relational operators (limited to: <, <=, >, >=, ==, !=), the instanceof operator, logical operators (limited to: &, |, ^, !, &&, ||), and the conditional operator ( ? : ), to produce a desired result. Write code that determines the equality of two objects or two primitives

SOURCE:

VIEW OTHER ORACLE'S JAVA BASED CERTIFICATIONS CLICK HERE

Sunday, July 28, 2013

PROGRAM FOR MULTILEVEL INHERITANCE

a.java:
~~~~~
public class a
{
int x,y;
a(int x1, int y1)
{
x=x1;
y=y1;
}
void displaya()
{
System.out.println("Value of x at class a is "+x);
System.out.println("Value of y at class a is "+y);
}
}

b.java:
~~~~

public class b extends a
{
int m;
b(int x1, int y1, int m1)
{
super(x1,y1);
m=m1;
}
void displayb()
{
System.out.println("Value of m at class b is "+m);
}
}

c.java
~~~~
public class c extends b 
{
int a;
c(int x1, int y1, int m1, int a1)
{
super(x1,y1,m1);
a=a1;
}
void displayc()
{
displaya();
displayb();
System.out.println("Value of a at class c is "+a);
}
}

demomultilevel.java:
~~~~~~~~~~~~~
public class demomultilevel 
{
public static void main(String[] args) 
{
c objc=new c(23,5,4,8);
objc.displayc();
}

}

Saturday, July 27, 2013

Single inheritance example program


class emp1
{
        private int eno;
        private String ename;
        emp1(int no,String name)
        {
                System.out.println("Base Constructor");
                eno = no;
                ename=  name;
        }
        public void putemp()
        {
                System.out.println("Empno : " + eno);
                System.out.println("Empname : " + ename);
        }
}
class dept1 extends emp1
{
        private int dno;
        private String dname;
        dept1(int no,String name,int eno,String ename)
        {
                super(eno,ename);
                System.out.println("Derived Constructor");
                dno = no;
                dname = name;
        }
        public void putdept()
        {
                System.out.println("Deptno : " + dno);
                System.out.println("Deptname : " + dname);
        }
        public static void main(String args[])
        {
                dept1 d = new dept1(20,"Sales",100,"Kirthika");
                d.putemp();
                d.putdept();
        }
}

SINGLE INHERITANCE USING SUPER KEYWORD

a.java:
~~~~~

public class a
{
int a=10;
String abc="LEARN JAVA";

void display()
{
System.out.println("Value of 'a' is "+a);
System.out.println("Value of 'abc' is "+abc);
}
}


b.java:
~~~~
public class b extends a
{
int j=a;
String cba=abc;        //assigning the value of variable abc to cba

void display()
{
super.display();             //accessing the members of the main class using super keyword
System.out.println("Value of 'j' is "+j);
System.out.println("Value of 'cba' is "+cba);
}
}

inheritmain.java:
~~~~~~~~~~~
public class inheritmain
{
public static void main(String[] args)
{
b ob= new b();        // creating tthe object reference to the last created class
ob.display();     //here we are calling the display() of b class
}

}



Friday, July 26, 2013

PROGRAM FOR SINGLE INHERITANCE

A.java                           /file name
~~~~~
public class A                        //parent class (or) superclass
{
int i,j;
void showij()
{
System.out.println("i and j : "+i+" "+j);
}
}


B.java                                   //filename
~~~~~
public class B extends A                                  //child class
{
int k;
void showk()
{
System.out.println("K : "+k);
}
void sum()
{
System.out.println("i+j+k="+(i+j+k));
}
}


C.java:
~~~~~
public class simpleinheritance 
{
public static void main(String args[])
{
A superob=new A();              //creating object for parent class 
B subob=new B();                       //object creation for child class
superob.i=10;
superob.j=20;                           // assigning vales to super class variables
               System.out.println("Contents of superob :");
superob.showij();
System.out.println();
subob.i=7;
subob.j=8;
subob.k=9;
System.out.println("Contents of subob : ");
subob.showij();                                             // calling parent class function at child class
subob.showk();
System.out.println();
System.out.println("Sum of i,j and k in subob : ");
subob.sum();
}
}


Thursday, July 25, 2013

INHERITANCE

Inheritance can be defined as the process where one object acquires the properties of another. With the use of inheritance the information is made manageable in a hierarchical order.
we use the key words super and extend .

  • super-its used for acessing parent class variable and method
  • extend-its used for acessing the parent class.
1) Single InheritanceSingle Inheritance


Below are Various types of inheritance in Java. We will see each one of them one by one with the help of examples and flow diagrams.
Single inheritance is damn easy to understand. When a class extends another one class only then we  call it a single inheritance. The below flow diagram shows that class B extends only one class which is A. Here A is a parent class of B and B would be  a child class of A.
2) Multiple Inheritance
Multiple Inheritance” refers to the concept of one class extending (Or inherits) more than one base class. The inheritance we learnt earlier had the concept of one base class or parent. The problem with “multiple inheritance” is that the derived class will have to manage the dependency on two base classes.
Multiple-Inheritance
Note 1: Multiple Inheritance is very rarely used in software projects. Using Multiple inheritance often leads to problems in the hierarchy. This results in unwanted complexity when further extending the class.
Note 2: Most of the new OO languages like Small Talk, Java, C# do not support Multiple inheritance. Multiple Inheritance is supported in C++.
3) Multilevel Inheritance
Multilevel inheritance refers to a mechanism in OO technology where one can inherit from a derived class, thereby making this derived class the base class for the new class. As you can see in below flow diagram C is subclass or child class of B and B is a child class of A.
Multilevel-Inheritance
4) Hierarchical Inheritance
In such kind of inheritance one class is inherited by many sub classes. In below example class B,C and D inherits the same class A. A is parent class (or base class) of B,C & D
Hierarchical-Inheritance

5) Hybrid Inheritance

In simple terms you can say that Hybrid inheritance is a combination of Single and Multipleinheritance. A typical flow diagram would look like below. A hybrid inheritance can be achieved in the java in a same way as multiple inheritance can be!! Using interfaces. yes you heard it right. By usinginterfaces you can have multiple as well as hybrid inheritance in Java
Hybrid-inheritance
LET US SEE THE PROGRAMS FROM NEXT POST.

Wednesday, July 24, 2013

METHOD OVERLOADING


  1. method with same  name but different parameter list or return type are called overloaded method
  2. the overloaded method can be in same class or extended class.It is one of the way of polymorphism in java
PROGRAM:
````````````````

class a 
void test() 
System.out.println("No parameters"); 
// Overload test for one integer parameter. 
void test(int a) 
System.out.println("a: " + a); 
// Overload test for two integer parameters. 
void test(int a, int b) 
System.out.println("a and b: " + a + " " + b); 
// overload test for a double parameter 
double test(double a)
System.out.println("double a: " + a); 
return a*a; 
class ab
public static void main(String args[]) 
a ob = new a(); 
double result; 
// call all versions of test() 
ob.test(); 
ob.test(10); 
ob.test(10, 20); 
result = ob.test(123.2); 
System.out.println("Result of ob.test(123.2): " + result); 
}


OUTPUT:
~~~~~~~
No parameters
a: 10
a and b: 10 20
double a: 123.2
Result of ob.test(123.2): 15178.240000000002

Tuesday, July 23, 2013

CONSTRUCTOR


Constructor is a special method, that initializes an object immediately upon creation this automatic initialization is performed through the use of constructor.

KEY POINTS ABOUT CONSTRUCTOR:
``````````````````````````````````````````````````````

  1. It should have same name as that of class.syantactically similar to a method
  2. once defined and automatically called immediately after allocating memory
  3. it does not have any return type.
TYPES OF CONSTRUCTOR:
``````````````````````````````````````
  • Default Constructor:
    • every class has its default constructor
    • if default constructor is not provided then compiler creates its own& initializes the default value.
    • no vales can be sent through default constructor
  • Parameterized Constructor:
    • Here values are set by specifically set as parameters.
    • This is for various initializing values. 
PROGRAM:
~~~~~~~~~

public class room
{
int width ;
int length;

room( )                         // DEFAULT CONSTRUCTOR
{
width=5;
length=5;
}

room ( int w,int l)            //PARAMETERIZED CONSTRUCTOR
{
width=w;
length=l;
}
int area( )
{
return(width*length);
}
}
 class room1
 {
public static void main(String a[])
{
room r=new room( );
room r1=new room( 50,50);//passing parameters to the parameterized constructor
r.width=10;   //assigning values to the variables
r.length=20;

int result=r.area( );
System.out.println("AREA IS: "+result);// calling method from another class using object
System.out.println("AREA IS: "+r1.area( ));
}

}

OUTPUT:
~~~~~~~~
AREA IS: 200                //by default constructor
AREA IS: 2500             //by parameterized constructor

The Nested if-else statements

The Nested if-else statements are used where we want to make series of decision making. Thus one if-else is nested within another if-else. Therefore nested if-else give us to make a decision within a decision already taken. Lets look at the syntax of nested if-else statements

SYNTAX:


if(boolean-expression 1)
{
  if(boolean-expression 2)
  {
    statement 1;
  }
  else
  {
     statement 2;
  }
}
else
{
  statement 3;
}
rest-of-code;
FLOW CHART:
EXAMPLE PROGRAM:

class nested
{
public static void main(String args[])
{
char grade = ‘A’;

if ( grade == ‘A’)

  System.out.println( “Excellent student”);

else

   if ( grade == ‘B’ )

     System.out.println( “Good student”);

   else

     if ( grade == ‘C’ )

       System.out.println( “Average student”);

     else

       if ( grade == ‘D’ )

         System.out.println( “Bad student”);

       else System.out.println(“Failed student”);
}
}
 


Animated Social Gadget - Blogger And Wordpress Tips