Java program Concepts 1

What is a Variable?
A variable is a named entity within a program that stores a value. A variable is fundamental to every program (in any language).

Example: Char CarType [Sedan, Sptorts, Van, Electrical, Hybrid]
                CarType is a variable which has 5 array variable. Variable could be defined as a single        
                variable or an array variable.

What is a Type?
Each variable within a Java program has a type. The type could be a primitive such as a number,a built-in class such a string, or a user-defined class.
Char, int, number, float, string etc.

A primitive data type: A char (for character), a byte (for a single 8-bit value), an int (for 32-bit integer), a short (for a 16-bit integer), a long (for a 64-bit integer), a float (single-precision floating point number) or a

double (double-precision floating point number).
A built-in Java class: For example, String is a built-in Java class used for storing and manipulating strings.

To represent a more complex type and relationship among multiple types thus declared, user can create a Class which can be called a user defined class;

     Example:

    public Class carMillennium{

Char Color[w,b,r,y,o,p,bl,gr]
Char Type[sedan, sports,van,electrical]
int make[2018, 2019]
int model[L, L1,L2]
Double Price[""]

}

What is an Object?
An object is an instance of a class. The class definition serves as a blueprint for instantiating an object within a running Class.

What is a Method?
A method is an implementation of a specific behavior. It might compute and return a value, in which case it is defined with a return type.

What is a Constructor?
A constructor is a special method within a class which is invoked when an object is being created. It is invoked with the arguments passed in during the construction.

What is a Declaration?
To declare the type of a variable Initialization

What is Initialization?
Initialization is the assignment of a value to a variable at the time of declaration

Example of Declaration initialization: -
byte anyStream;
short visitByHour;
long totalNumberOfStars;
double priceOfCar;

What is an Instance?
To create a similar one of any class.

What is Instantiation?
To create a new instance of a class is Instantiation.
Example:
In below example Person is a class; Nperson is an instantiation of class Person
public class Person {

public String fullName;
public String getFullName()

public static void main (String[] args) {


return fullName;

     }
 }
}

Nperson Person = new Nperson();


What is Inheritance? I am new in programming how do you want me to write code with inheritance, then ??
It's easy !! Think more than what you read 😄
Inheritance is a process of Inheriting or simply re-using the class members(Variables and Methods) from one class to another.
--not sure yet ? Keep in mind (Copy n paste) ........... and continue reading below:

Rule 1:
Non-static class members only can be Inherited (if you want to re-use them.)

Now.... what is Non-static or Static thing?
OKAY!! - Look, I said whatever you do in script, every time you want to create an object you               must go thru the process of instantiation of the object.

But wait, if you want to write the word Static in your class/ method,then it's a different story!

     When you use the word static, meaning next times when you need this class/ method, you don't           need to create a separate method or object(thru inheritance), and you will directly use the member       of static method/ object from here.

Rule 2:
The class where the class members are getting Inherited is called as Super class/Parent class/Base class.

Rule 3:
The class to which the class members are getting Inherited is called as Sub class/Child class/derived class.

Rule 4:
The Inheritance between Super class and Sub class is achieved using "extends" keyword.

Three types of inheritance:
a) Single inheritance,
b) multi level inheritance
c) Multiple inheritance (not in Java)


What is  polymorphism?
Wow! what is the meaning of polymorphismm ? Polymorphism means multi tasking...

Definition:
Two types of polymorphism in JAVA:-
a) Compile time polymorphism (AKA method overloading)
Within a class if more than two methods are available with same name but with different argument, then it is a polymorphism,
i) Number of Arguments is different
ii) Type of Arguments is different

b) Run time polymorphism (AKA method overriding)
If two or more methods with same name available in the Super class and Sub class.

i) two or more methods with same name in a class
ii) two or more methods with same name in sub class

Comments

Popular posts from this blog

How to Create an Issue in JIRA (2)

Fundamentals of Accessibility Testing ... 2