Java Tutorial| Java Training| simple programs or coding| Cochin- Kerala- Enhance your carrier as a java programmer. Study the basics here with examples...
2. 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
}
3. Constructor
A 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){
}
}
4. 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.
5. Eg1: the variable var is declared
int 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();
}
6. 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(){
}
}
7. Method
Eg 2: a method, myMethod is defined within class myClass that returns a
boolean.
public class myClass{
public boolean myMethod(){
return true;
}
}
8. 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){
}
}
9. Eg 2:
myMethod is called.
int myInteger = 2;
double myDouble = 5.0;
myMethod(myInteger, myDouble);
10. 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.
11. 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.java
public 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;
12. Java Training in
Kerala
Cozak Technologies
Ernakulam, Thrissur, Palakkad& Trivandrum
E-mail: mail@cozaktechnologies.in
Website: 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