Thursday, 27 August 2015

Inheritance:
Inheritance can be defined as the process where one class acquires the properties (methods and fields) of another. With the use of inheritance the information is made manageable in a hierarchical order.
The class which inherits the properties of other is known as subclass (derived class, child class) and the class whose properties are inherited is known as superclass (base class, parent class).

extends Keyword

extends is the keyword used to inherit the properties of a class. Below given is the syntax of extends keyword.
class Super{
.....
.....
}

class Sub extends Super{
.....
.....

}

Sample Code

Below given is an example demonstrating Java inheritance. In this example you can observe two classes namely Calculation and My_Calculation.
Using extends keyword the My_Calculation inherits the methods addition() and Subtraction() of Calculation class.
Copy and paste the program given below in a file with name My_Calculation.java
class Calculation{ 
   int z;
   public void addition(int x, int y){
      z=x+y;
      System.out.println("The sum of the given numbers:"+z);
   }
   public void Substraction(int x,int y){
      z=x-y;
      System.out.println("The difference between the given numbers:"+z);
   }
   
}

public class My_Calculation extends Calculation{    
  
   public void multiplication(int x, int y){
      z=x*y;
      System.out.println("The product of the given numbers:"+z);
   }
   public static void main(String args[]){
      int a=20, b=10;
      My_Calculation demo = new My_Calculation();
      demo.addition(a, b);
      demo.Substraction(a, b);
      demo.multiplication(a, b);      
      
   }

}
What is Decision making in java?
Decision making structures have one or more conditions to be evaluated or tested by the program, along with a statement or statements that are to be executed if the condition is determined to be true, and optionally, other statements to be executed if the condition is determined to be false.
Following is the general form of a typical decision making structure found in most of the programming languages:
Learn  more Click here
Java Tutorial

Wednesday, 15 July 2015

Overloading Methods

In the Simple theory is that the same name method is use two or more than in a CLASS but the Data type and the number of argument should be different always.
In Java it is possible to define two or more methods within the same class that share the
same name, as long as their parameter declarations are different. When this is the case, the
methods are said to be overloaded, and the process is referred to as method overloading. Method overloading is one of the ways that Java supports polymorphism. If you have never used a language that allows the overloading of methods, then the concept may seem strange at first. But as you will see, method overloading is one of Java’s most exciting and useful features.
                          When an overloaded method is invoked, Java uses the type and/or number of arguments as its guide to determine which version of the overloaded method to actually
call. Thus, overloaded methods must differ in the type and/or number of their parameters.
While overloaded methods may have different return types, the return type alone is insufficient to distinguish two versions of a method. When Java encounters a call to an
overloaded method, it simply executes the version of the method whose parameters match
the arguments used in the call.

Here is a simple example that illustrates method overloading:
// Demonstrate method overloading.
class Demo {
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 Overload {
public static void main(String args[]) {
OverloadDemo ob = new OverloadDemo();
double result;
// call all versions of test()
ob.test();
ob.test(10);
ob.test(10, 20);
result = ob.test(123.25);
System.out.println("Result of ob.test(123.25): " + result);
}

}

OUTPUT:

No parameters
a: 10
a and b: 10 20
double a: 123.25

Result of ob.test(123.25): 15190.5625

As you can see, test( ) is overloaded four times. The first version takes no parameters,
the second takes one integer parameter, the third takes two integer parameters, and the
fourth takes one double parameter. The fact that the fourth version of test( ) also returns a
value is of no consequence relative to overloading, since return types do not play a role in
overload resolution.
When an overloaded method is called, Java looks for a match between the arguments
used to call the method and the method’s parameters. However, this match need not always

be exact. In some cases, Java’s automatic type conversions can play a role in overload resolution.
HOW TO CREATE JAVA ENVIRONMENT IN WINDOW 7/8/8.1.



Step 1: First make to download the jdk(Java Development Kit). From the Oracle Site for the appropriate system 64bit or 32bit. 

 (http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html)
                
Step 2:  If you do not have the IDE of java. You can download the IDE (Eclipse) as a compiler.
You can download from here for your appropriate windows need.
https://eclipse.org/downloads/packages/release/juno/sr2.

                             OR

If you do not want to download eclipse you can write the program in notepad but i am suggested that it is the best or time saving is to work on IDE.

Step 3:  If you download the IDE you can start work on it. Or if you donot download and work on notepad. Than you must go in the                     

  • PROGRAM FILE
  • In JAVA 
  • Go to BIN folder
  • open the PROPERTIES of First APPLET FILE.
  • Copy the PATH of the APPLET FILE.
  • Go to the MY COMPUTER PROPERTIES.
  • Than GO In the ADVANCE SETTING SYSTEM.
  • Than go in the ENVIRONMENT VARIABLES.
  • Go to the NEW and NAME ALOT as PATH and PASTE the Path of applet file and save.
  • Than you go in COMMAND PROMPT and Write java
  • Than you got the details of the java.
write the program in NOTEPAD.
EXAMPLE::

class TEST{
public static void main(String args[]){
System.out.println("Hello World");
}
}



  • Save this file as the same name of the class name.
  • than save as TEST.JAVA on the desktop.
  • and Than go to Command Prompt
  • Write javac TEST.JAVA{For the compile and check errors in the program}.
  • than you want to run you can write as java TEST.

Java World: How to resolve merge conflicts after git rebase ?

Java World: How to resolve merge conflicts after git rebase ?

Tuesday, 14 July 2015

LOOP CONTROL:

There may be a situation when we need to execute a block of code several number of times and is often referred to as a loop. Java has very flexible three looping mechanisms. You can use one of the following three loops: 

  1.  while Loop 
  2.  do...while Loop 
  3.  for Loop
while Loop:

A while loop is a control structure that allows you to repeat a task a certain number of times.
While loop always check before entering the loop is that the condition is to be true or not.

Syntax

while(boolean Experssion){
//statements//
}

do...while Loop: 

A do...while loop is similar to a while loop, except that a do...while loop is guaranteed to execute at least one time.
In do while first time do loop goes but after completing the one time run they check the for loop is true or not if not true they go out from the loop
THE MAIN DIFFERENCE IS THAT BETWEEN While AND Do...While LOOP.

Syntax

do{
//statements//
}
while(boolean Expression);

For Loop:

A for loop is a repetition control structure that allows you to efficiently write a loop that needs to execute a specific number of times. A for loop is useful when you know how many times a task is to be repeated. 

Syntax

for(initialize;boolean expression;increment/decrement){
//statement//
}