12
Java Tutorial For Beginners

Java tutorial and advanced training Kerala

  • Upload
    merin

  • View
    129

  • Download
    2

Embed Size (px)

Citation preview

Page 1: Java tutorial and advanced training Kerala

Java TutorialFor Beginners

Page 2: Java tutorial and advanced training Kerala

Class A class depicts a specific sort of article. It can contain related strategies and information individuals (variables).

A class must have the same name as the document it is contained in.

Eg:

public class myClass(){ //data members

//constructors

//methods

}

Page 3: Java tutorial and advanced training Kerala

ConstructorA special type of instance system that makes another item. In Java, constructors have the same name as their class and have no arrival esteem in their presentation.

Eg: public class myClass{ // a constructor that takes no parameters public myClass(){ } // a constructor that takes one parameter public myClass(int var){ }

}

Page 4: Java tutorial and advanced training Kerala

Declaration

An statement that makes a variable, system, or class identifier and its related traits however doesn't fundamentally distribute capacity for variables or characterize an execution for strategies.

Class can't be declared and afterward have its body defined somewhere else.

Page 5: Java tutorial and advanced training Kerala

Eg1: the variable var is declaredint var;

Eg 2: the object myObject is declared as an instance of the MyClass class.MyClass myObject;

Eg 3: abstract methods, found in abstract classes, can be declared but not defined.public abstract class myAbstractClass(){ // abstract methods are declared. public abstract myMethod()}

Eg 4: methods found in interfaces can be declared but not defined.public interface myInterface(){ // methods in an interface are declared public void myMethod();}

Page 6: Java tutorial and advanced training Kerala

Method

A collection of code found within a class. If the data members of a class are nouns, the methods are the verbs (the action).

Eg 1: a method, myMethod is defined within class myClass that does NOT return a value.public class myClass{public void myMethod(){}}

Page 7: Java tutorial and advanced training Kerala

Method Eg 2: a method, myMethod is defined within class myClass that returns a boolean. public class myClass{ public boolean myMethod(){ return true; }

}

Page 8: Java tutorial and advanced training Kerala

Object

The principal code building block of Java programs. Each object in a program consists of both variables (data) and methods (functionality).

Parameter – a variable or object passed into a method.

Eg 1: a method, myMethod is defined which takes 2 parameters.public class MyClass{public void myMethod(int var1, double var2){}

}

Page 9: Java tutorial and advanced training Kerala

Eg 2:

myMethod is called. int myInteger = 2; double myDouble = 5.0; myMethod(myInteger, myDouble);

Page 10: Java tutorial and advanced training Kerala

Primitive

A variable defined with a primitive data type: byte, short, int, long, float, double, char, or boolean.

Typecast – (1) to demote a variable from a larger capacity data type to a smaller one. (2) to re-establish the class of an object. The cast associates itself with the expression to its immediate right.

Page 11: Java tutorial and advanced training Kerala

Eg 1: A double var is created and then typecast via “(int)” to a variable of integer type ans.

double var = 3; int ans = (int) var;Eg 2: All objects extend the Java Object class.

// define class MyClass in file MyClass.javapublic class MyClass{}// in the main method of another class…// instantiate MyClass, but store it in a variable of type Object.Object o = new MyClass();// typecast object o, back into an instance of MyClass.

MyClass myObject = (MyClass) o;

Page 12: Java tutorial and advanced training Kerala

For Advanced Java Training in Kerala

Cozak TechnologiesErnakulam, Thrissur, Palakkad& Trivandrum

E-mail: [email protected]: www.cozaktechnologies.in

Tel: 0491 2553320, 0484 6053320

Mobile: +91 9037 427 420,+91 9037 428 420, +91 9037 429 420

Java projects and Training Kerala| Web developers| Mobile app development,etc