Java Classes and Object Basics
Java Classes and Object Basics
A class defines a new type of data. In this case, the new type is called Box.
To create a Box object, you will use a statement like the following:
Box myBox = new Box(); // create a Box object called mybox
myBox is an instance of Box.
myBox contains its own copy of each instance variable, width, height, and depth, defined by the
class. To access these variables, you will use the dot (.) operator.
Example:
class Box
{
int width;
int height;
int depth;
}
class demobox
{
public static void main(String args[])
{
Box myBox = new Box();
[Link] = 10;
[Link]("[Link]:"+[Link]);
}
}
The output: [Link]
Objects:
An entity that has state and behavior is known as an object e.g., chair, bike, marker, pen, table,
car, etc. It can be physical or logical (tangible and intangible). The example of an intangible
object is the banking system.
Declaring Objects:
Object creation is a two-step process.
● declare a variable of the class type.
● acquire a physical copy of the object and assign it to that variable using the new operator.
The new operator dynamically allocates memory for an object and returns a reference to it. The
following lines are used to declare an object of type Box:
Box mybox; // declare reference to object
mybox = new Box(); // allocate a Box object
or
Box mybox = new Box();
The first line declares mybox as a reference to an object of type Box.
Object Instance
The following program declares two Box objects:
class Box
{
int width;
int height;
int depth;
}
class demobox
{
public static void main(String args[])
{
Box myBox1 = new Box();
Box myBox2 = new Box();
[Link] = 10;
[Link] = 20;
[Link]("[Link]:"+ [Link]);
[Link]("[Link]:" + [Link]);
}
}
The output produced by this program is shown here
: [Link] [Link]
The new operator has this general form:
classVariable = new classname( );
The class name followed by parentheses specifies the constructor for the class. A constructor
defines what occurs when an object of a class is created.
Assigning objects reference variables
Consider the following code:
Box b1 = new Box();
Box b2 = b1;
b1 and b2 will refer to the same object.
Any changes made to the object through b2 will affect the object b1. If b1 is been set to null, b2
will still point to the original object.
Box b1 = new Box();
Box b2 = b1;
// ...
b1 = null;
Assigning one object reference variable to another only creates a copy of the reference.
Methods
The word method is commonly used in object-oriented programming. It is similar to a function
in any other programming language. Many programmers use different terms, especially function,
but we will stick to the term methods. None of the methods can be declared outside the class. All
methods have a name that starts with a lowercase character.
Why Use Methods?
To Make the Code Reusable: If you need to do the same thing or almost the same thing, many
times, write a method to do it and then call the method each time you have to do that task.
To Parameterize the Code: You will often use parameters to change the way the method
behaves.
For Top-down Programming: You can easily solve a bigger problem or a complex one (the
‘top’) by breaking it into smaller parts. For the same purpose, we write methods. The entire
complex problem (functionality) can be broken down into methods.
To Simplify the Code: Because the complex code inside a method is hidden from other parts of
the program, it prevents accidental errors or confusion.
Method Type
There are two types of methods in Java: instance methods and class methods. Instance methods
are used to access/manipulate the instance variables but can also access class variables. Class
methods can access/manipulate class variables but cannot access the instance variables unless
and until they use an object for that purpose.
Method Declaration
The combined name and parameter list for each method in a class must be unique. The
uniqueness of a parameter is decided based on the number of parameters as well as the order of
the parameters. So,
int methodOne (int x, String y)
is unique from
int methodOne (String y, int x).
Let us take a look at the general syntax of a method declaration:
[modifi ers] return_typemethod_name (parameter_list)
[throws_clause] {
[statement_list]
}
The parameters enclosed within square brackets [ ] are optional. The square brackets are not a
part of the code; they are included here to indicate optional items. We will discuss only those
parts that are required at the moment and leave the rest for the later chapters. The method
declaration includes
Modifiers If you see the syntax of the method declaration carefully, there is an optional part of
it, modifiers. There are a number of modifiers (optional) that can be used with a method
declaration.
Return Type It can be either void (if no value is returned) or if a value is returned, it can be
either a primitive type or a class. If the method declares a return type, then before it exits, it must
have a return statement.
Method Name The method name must be a valid Java identifier.
Parameter List Zero or more type/identifi er pairs make up a parameter list. Each parameter in
the parameter list is separated by a comma.
Curly Braces The method body is contained in a set of curly braces. Methods contain a
sequence of statements that are executed sequentially. The method body can also be empty.
class Circle
{
float pi = 3.14f;
float radius;
//setter method to change the instance variable: radius
void setRadius(float rad)
{
radius = rad;}
float calculateArea()
{
float area = pi * radius * radius;
return (area);
}}
}
But Java has a simple and concise method of doing it. It has a mechanism for automatically
initializing the values for an object, as soon as the object is created. The mechanism is to use
constructors.
Difference between constructor and methods:
Constructors have the same name as the class they reside in and they are syntactically similar to
a method. Constructors are automatically called immediately after the object for the class is
created by a new operator. Constructors have no return type, not even void, as the implicit return
type of a constructor is the class type itself.
class Room{
double length, breadth, height, volume;
//No Argument Constructor
Room(){
length = 14;
breadth = 12;
height = 10;
}
// Computation of volume of the room
double volComp(){
volume = length * breadth * height;
return volume;
}
public static void main (String args[ ]){
Room r1 = new Room();
Room r2 = new Room();
[Link]("The volume of the room is " +[Link]());
[Link]("The volume of the room is " +[Link]());
}
}
Output
The volume of the room is 1680.0
The volume of the room is 1680.0
Parameterized Constructors
Just like methods, arguments can be passed to the constructors, in order to initialize the instance
variables of an object. The above example had a limitation. Each Room has its own length,
breadth, and height and it is very unlikely that each room is of the same size. In the previous
example, all objects of Room class will have the same volume because the values for length,
breadth and height are fixed for all objects. You can explicitly change them using an object
instance, e.g.,
[Link] = 30
and then invoke the method volComp for calculating volume of the Room. But there should be a
mechanism for specifying different values of instance variables for different objects of a class, as
soon as the object is created. For example, if different dimensions can be specified for a Room
then each Room will have its own volume. For this, the instance variables should be assigned a
different set of values for different objects of the class. Hence we need to create a parameterized
constructor that accepts arguments to initialize the instance variables with the arguments. Let us
take an example to see how parameterized constructors can be used.
class Room2 {
double length, breadth, height, volume;
Room2(double l, double b, double h) {
length = l;
breadth = b;
height = h;
}
// Computation of volume of the room
double volComp(){
Programming in Java
volume = length * breadth * height;
return volume;
}
public static void main (String args[ ]) {
Room2 r1 = new Room2(14, 12, 10);
Room2 r2 = new Room2(16, 15, 11);
[Link]("The volume of the room is " +[Link]());
[Link]("The volume of the room is " +[Link]());
}
}
Output
The volume of the room is 1680.0
Local Variables Local variables are declared inside a method, constructor, or a block of code.
When a method is entered, its contents (values of local variables) are pushed onto the call stack.
When the method exits, its contents are popped off the stack and the memory in stack is now
available for the next method. Parameters passed to the method are also local variables which are
initialized from the actual parameters. The scope of local variables is limited to the method in
which they have been defined. They have to be declared and initialized before they are used.
Access specifiers like private, public, and protected cannot be used with local variables.
Instance Variables Instance variables are declared inside a class, but outside a method. They are
also called data member, field, or attributes. An object is allotted memory for all its instance
variables on the heap memory. As objects instance variables remain live as long as the object is
active. They are accessible directly in all the instance methods and constructors of the class in
which they have been defined. By default, they are initialized to their default values according to
their respective types.
Class/static Variables Class/static variables declaration is preceded with the keyword static.
They are also declared inside a class, but outside a method. The most important point about static
variables is that there exists only a single copy of static variables per class. All objects of the
class share this variable. Static variables are normally used for constants. By default, static
variables are initialized to their default values according to their respective types.
Static Variables
Java does not allow global variables. The closest thing we can get to a global variable in Java is
to make the instance variable in the class static. The effect of doing this is that when we create
multiple objects of that class, every object shares the static variable, i.e. there is only one copy of
the variable declared as static. To make an instance variable static we simply precede the
declaration with the keyword static.
static int var = 0;
In effect, what we are really doing is that this instance variable, var, no matter how many objects
are created, should always reside in the same memory location, regardless of the object. This
then simulates like a ‘global variable.’ We usually declare a variable as final and static as well,
since it makes sense to have only one instance of a constant. It is worthwhile to note that people
refer to static instance variables as ‘class variables.’ Before proceeding further, let us take an
example to depict how static variables are declared.
class Test1 {
int x = 0; // instance variable
static int y = 0; // class variable
//setter methods
void setX (int n) {x = n;}
void setY (int n) {y = n;}
//getter methods
int getX() { return x;}
int getY() { return y;}
}
class Test2 {
public static void main(String[] arg){
Test1 t1 = new Test1();
Test1 t2 = new Test1();
[Link](9);
[Link](10); // object t1 and t2 have separate copies of x
[Link]("Instance variable of object t1 : " +[Link]());
[Link]("Instance variable of object t2 : " +[Link]());
// class variable can be accessed directly through Class Name
// (if changed to Test2.x, it won't compile)
[Link]("Value of y accessed through class Name: " +Test1.y);
Test1.y = 7;
[Link]("Changed value of y accessed through class Name: " +Test1.y);
// class variable can be manipulated thru methods as usual
[Link](Test1.y+1);
// class variable can be accessed through objects also
[Link]("Value of y accessed through object t2:" +[Link]());
}
}
Output
Instance variable of object t1 : 9
Instance variable of object t2 : 10
Value of y accessed through class Name: 0
Changed value of y accessed through class Name: 7
Value of y accessed through object t2: 8
Static Methods
Like static variables, we do not need to create an object to call our static method. Simply using
the class name will suffice. Static methods however can only access static variables directly.
Variables that have not been declared static cannot be accessed by the static method directly, i.e.,
the reason why we create an object of the class within the main (which is static) method to access
instance variables and call instance methods. To make a method static, we simply precede the
method declaration with the keyword static.
class Area {
static int area; // class variable
static int computeArea (int width, int height){
area = width * height;
return area;
}
}
class CallArea{
public static void main(String args[]){
[Link]([Link](4,3));
}
}
Output
12
this KEYWORD
The keyword this is used in an instance method to refer to the object that contains the method,
i.e., it refers to the current object. Whenever and wherever a reference to an object of the current
class type is required, this can be used. It can also differentiate between instance variables and
local variables.
Room2(double l, double b, double h){
[Link] = l;
[Link] = b;
[Link] = h;
}
Constructor Chaining It means a constructor can be called from another constructor.
/* First Constructor */
Room2( )
{
// constructor chained
this(14,12,10);
}
/* Second Constructor */
Room2 (double l, double b, double h)
{
length = l;
breadth = b;
height = h;
}
In the above code, two constructors have been created: one without arguments and another with
three arguments. In the first constructor, we have used this keyword to call the second
constructor and passed the required arguments in the call to second constructor. Whenever we
create an object of the class Room2 as,
Room2 r1 = new Room2();
the first constructor will be invoked which is chained to the second constructor.
ARRAYS
The allocation of memory space, when a variable is declared, cannot further be sub-divided to
store more than one value. There are situations where we might wish to store a group of similar
type of values in a variable. It can be achieved by a special kind of data structure known as
arrays.
An array is a memory space allocated that can store multiple values of same data type in
contiguous locations. This memory space, which can be perceived to have many logical
contiguous locations, can be accessed with a common name. For example, we can define an
array as ‘marks’ to represent a set of marks of a group of students. Now the next question is how
to access a particular value from a particular location? A specific element in an array is accessed
by the use of a subscript or an index used inside the brackets, along with the name of the array.
For example, marks would store the marks of the fifth student. While the complete set of values
is called an array, the individual values are known as elements. Arrays can be two types:
● one dimensional array
● multi-dimensional array
One-dimensional Arrays
In a one-dimensional array, a single subscript or index is used, where each index value refers to
an individual array element. The indexation will start from 0 and will go up to n –1, i.e., the first
value of the array will have an index of 0 and the last value will have an index of n –1, where n is
the number of elements in the array. So, if an array named marks has been declared to store the
marks of five students, the computer reserves five contiguous locations in the memory.
Suppose, the five marks to be assigned to each array element are 60, 58, 50, 78, and 89. It
will be done as follows:
Marks[0] = 60;
Marks[1] = 58;
Marks[2] = 50;
Marks[3] = 78;
Marks[4] = 89;
Creation of Array
Creating an array, similar to an object creation, can inherently involve three steps:
● Declaring an array
● Creating memory locations
● Initializing/assigning values to an array
Declaring an Array Declaring an array is same as declaring a normal variable except that you
must use a set of square brackets with the variable type. There can be two ways in which an array
can be declared.
type arrayname[];
type[] arrayname;
So the above marks array having elements of integer type can be declared either as
int marks[];
or
int[] marks;
Creating Memory Locations An array is more complex than a normal variable, so we have to
assign memory to the array when we declare it. You assign memory to an array by specifying its
size. Interestingly, our same old new operator helps in doing the job, just as shown below:
Arrayname = new type [size];
So, allocating space and size for the array named as marks can be done as,
marks = new int[5];
Both (declaration of array and creation of memory location), help in the creation of an array.
These can be combined as one statement, for example,
type arrayname[] = new type[];
or
type[] arrayname = new type[];
It is interesting to know what the JVM actually does while executing the above syntax. During
the declaration phase, int marks[];
marks Null
The marks array after memory is allocated to the array on execution of the following statement:
marks = new int[5];
Here is an example to show how to create an array that has 5 marks of integer type.
class Array{
public static void main(String[] args){
int[] marks = new int[5];
}
}
Initializing/ assigning Values to an Array Assignment of values to an array, which can also be
termed as initialization of array, can be done as follows:
Arrayname[index] = value;
class Array {
public static void main(String[] args){
int[] marks = new int[5];
marks[0] = 60;
marks[1] = 58;
marks[2] = 50;
marks[3] = 78;
marks[4] = 89;
}
}
Arrays can alternately be assigned values or initialized in the same way as the variables, i.e., at
the time of declaration itself. The syntax for the same can be,
type arrayname[] = {list of values};
For example, int marks[] = {60, 58, 50, 78, 89}
Here, the marks array is initialized at the time of creation of array itself.
class Array
{
public static void main(String[] args){
int[] marks = {60, 58, 50, 78, 89};
}
}
How to Use for Loops with Arrays?
The for loops can be used to assign as well as access values from an array. To obtain the number
of values in an array, i.e., the length of the array, we use the name of the array followed by the
dot operator and the variable length. This length property is associated with all the arrays in Java.
For example,
[Link]("There are " + [Link] + "in the array");
will print the number of elements in the marks array, i.e., 5. Example shows how to use a for
loop to set all the values of an array to 0 which, you will see, is much easier than setting all the
values to 0 separately.
class Array {
public static void main(String[] args){
int[] marks = new int[5];
for (int i = 0; i<[Link]; i++)
marks[i] = 0;
}
}
Two-dimensional Arrays
Sometimes values can be conceptualized in the form of a table that is in the form of rows and
columns. Suppose we want to store the marks of different subjects. We can store it in a
onedimensional array. There can be enumerable such situations where we can use a two-
dimensional structure. Java provides a solution for the storage of such a structure in the form of
two-dimensional arrays.
If you want a multidimensional array, the additional index has to be specified using another set
of square [Link] following statements create a two-dimensional array, named as marks,
which would have 4 rows and 5 columns.
int marks[][] //declaration of a two-dimensional array
marks = new int[4][5]; //reference to the array allocated, stored in marks variable
This is done in the same way as it has already been explained while discussing one-dimensional
arrays. The two statements, used for array creation, can be merged into one as,
int marks[][] = new int[4][5];
Code:
class Echo {
public static void main(String args[]){
int x = [Link];
for (int i = 0; i< x; i++)
[Link](args[i]);
}
}
After compiling the program, when it is executed, you can pass the command-line arguments as
follows:
Output
A
B
C
Inheritance
INHERITANCE VS AGGREGATION
Inheritance aids in the reuse of code, i.e., a class can inherit the features of another class and add
its own modification. The parent class is known as the superclass and the newly created child
class is known as the subclass. A subclass inherits all the properties and methods of the super
class, and can have additional attributes and methods.
On the other hand, the term aggregation is used when we make up objects out of other objects.
The behavior of the bigger object is defined by the behavior of its component objects separately
and in conjunction with each other. For example, cars contain an engine which in turn contains
an ignition system and starter motor. Basically it is different from inheritance in the sense that
there exists a whole-part relationship in aggregation, car being the whole and engine being its
part.
Types of Inheritance
There are five different types of inheritance:
● Single inheritance
● Multilevel inheritance
● Multiple inheritance
● Hierarchical inheritance
● Hybrid inheritance
Single Inheritance In single inheritance, classes have only one base class.
Multilevel Inheritance C not only inherits from its immediate superclass, i.e., B, but also from
B’s superclass, A. Thus, class C will have all the attributes and behavior that A and B possesses
in addition to its own. There is no limit to this chain of inheritance (known as multilevel
inheritance) but getting down deeper to four or five levels makes the code excessively complex.
Multiple Inheritance In multiple inheritance, a class can inherit from more than one unrelated
class. Class C inherits from both A and B.
Hierarchical Inheritance In hierarchical inheritance, more than one class can inherit from a
single class, as shown in Fig. Class C inherits from both A and B.
Hybrid Inheritance Hybrid inheritance is any combination of the above defined inheritances as
shown in Fig.
Code:
class MotorVehicle{
int maxSpeed; // miles per hour
String modelName; // e.g. "Fiat"
int modelYear; // e.g. 2006,2007,2008
int numberOfPassengers; // 2, 4, 6
// we can add some more properties, as above, like the
// engineCapacity etc. but we would leave it as an
// exercise for you.
// constructor
MotorVehicle()
{
maxSpeed = 200;
modelName = "";
modelYear=1997;
numberOfPassengers=2;
}
MotorVehicle(int maxSpeed, String modelName, int modelYear, int numberOfPassengers)
{
[Link] = maxSpeed;
[Link] = modelName;
[Link] = modelYear;
[Link] = numberOfPassengers;
}
}
class Bike extends MotorVehicle {
boolean kickStart;
boolean buttonStart;
/* A kick start bike may or may not be a button start bike but a button start bike
will always have an option of kick starting */
// constructor
Bike()
{
kickStart = true;
buttonStart = false;
}
Bike(boolean ks, boolean bs)
{
kickStart = ks;
buttonStart = bs;
}
public static void main(String args[]) {
Bike b = new Bike ();
}}
OVERRIDING METHOD
When a method in a subclass has the same name and type signature as a method in its superclass,
then the method in the subclass is said to override the method in the superclass. Like
overloading, it is a feature that supports polymorphism.
When an overridden method is called from within a subclass, it will always refer to the version
of the method defined by the subclass. The superclass version of the method is hidden.
Code:
class A {
int i = 0;
void doOverride (int k) {
i = k;
}}
// Subclass defi nition starts here
class B extends A { // Method Overriding
void doOverride(int k){
i = 2 * k;
[Link]("The value of i is: " +i);
}
public static void main (String args[])
{
B b = new B(); // Create an instance of class B
[Link](12); // class B method doOverride() will be called
}}
Output
The value of i is: 24
super KEYWORD
The super keyword refers to the parent class of the class in which the keyword is used. It is used
for the following three purposes:
1. For calling the methods of the superclass.
2. For accessing the member variables of the superclass.
3. For invoking the constructors of the superclass.
Case 1: Calling the Methods of the Superclass
super.<methodName>() represents a call to a method of the superclass. This call is particularly
necessary while calling a method of the superclass through the subclass object that is overridden
in the subclass.
Code:
class A {
void show()
{
[Link]("Superclass show method");
}}
class B extends A { // Method Overriding
void show()
{
[Link]("Subclass show method");
}
public static void main (String args[]){
A s1 = new A(); // call to show method of Superclass A.
[Link]();
B s2 = new B();
[Link](); // call to show method of Subclass B
}}
Output
Superclass show method
Subclass show method
Case 2: Accessing the Instance Member Variables of the Superclass
The keyword is particularly useful when the variable of the superclass is shadowed by the
subclass variable. The concept of shadowing occurs when variables in super class and subclass
have same name. The superclass variables in this case will be hidden in the subclass and only
subclass variables will be accessible within the subclass. To access the shadowed variable of
superclass super keyword is used as shown below.
Code:
class Super_Variable {
int b = 30; //instance Variable
}
class SubClass extends Super_Variable {
int b = 12; // shadows the superclass variable
void show()
{
[Link]("subclass class variable:" + b);
[Link]("superclass instance variable:" + super.b);
}
public static void main (String args[]) {
SubClass s = new SubClass();
[Link](); // call to show method of Subclass B
}}
Output
subclass class variable: 12
superclass instance variable: 30
Case 3: Invoking the Constructors of the Superclass
super as a standalone statement (i.e., super()) represents a call to a constructor of the superclass.
This call can be made only from the constructor of the subclass and that too it should be
the first statement of the constructors. The default constructors implicitly include a call to the
super class constructor using the super keyword.
Code:
class Constructor_A {
Constructor_A()
{
[Link]("Constructor A");
}}
class Constructor_B extends Constructor_A {
Constructor_B() {
[Link]("Constructor B");
}}
class Constructor_C extends Constructor_B {
Constructor_C() {
[Link]("Constructor C");
}
public static void main (String args[]) {
Constructor_C a = new Constructor_C();
}}
Output
Constructor A
Constructor B
Constructor C
final KEYWORD
The keyword final is used for the following purposes:
1. To declare constants (used with variable and argument declaration)
2. To disallow method overriding (used with method declaration)
3. To disallow inheritance (used with class declaration)
Basically, it is used to prevent inheritance and create constants. Let us take an example.
Code:
class Final_Demo {
final int MAX = 100; //constant declaration
// final m0ethod declaration with final arguments
final void show(fi nal int x) {
// MAX++; illegal statement as MAX is final
// x++; illegal statement as x argument is final
[Link]("Superclass show method:" +x);
}}
class Final_Demo_1 extends Final_Demo {
// cannot override show method as it is final in
// parent class,that is why we have commented it
public static void main (String args[]){
Final_Demo_1 f2 = new Final_Demo_1();
//show of the parent class will be called
[Link](12);
}}
Output
Superclass show method: 12
ABSTRACT CLASS
Abstract classes are classes with a generic concept, not related to a specific class. They define the
partial behavior and leave the rest for the subclasses to provide. Abstract classes contain one or
more abstract methods. It does not make any sense to create an abstract class without abstract
methods, but if done, the Java compiler does not complain about it. An abstract method is a
method that is declared, but contains no implementation, i.e., no body.
Abstract classes cannot be instantiated, and they require subclasses to provide implementation
for their abstract methods by overriding them and then the subclasses can be instantiated. If the
subclasses do not implement the methods of the abstract class, then it is mandatory for the
subclasses to tag itself as abstract, making way for its own subclasses to override the abstract
methods.
Code:
abstract class Animal
{
String name;
String species;
// constructor of the abstract class
Animal(String n, String s)
{
name = n;
species = s;
}
void eat(String fooditem)
{
[Link](species + " " + name + " likes to have " + fooditem);
}
abstract void sound();
}
class Lion extends Animal
{
Lion() {
super("Lion","Asiatic Lion");
}
void sound() {
[Link] ("Lions Roar! Roar!");
}
public static void main(String args[])
{
Lion l = new Lion();
[Link]("flesh");
[Link]();
}}
Output
Asiatic Lion likes to have flesh
Lions Roar! Roar!
Some key features of an abstract class are as follows:
1. They cannot be instantiated, but they can have a reference variable.
2. A class can inherit only one abstract class, as multiple inheritance is not allowed amongst
classes.
3. They can have abstract methods as well as non-abstract methods.
4. It is mandatory for a subclass to override the abstract methods of the abstract class, otherwise
the subclass also need to declare itself as abstract. Overriding other methods (non-abstract) is up
to the requirement of the subclass.
5. Abstract classes can have constructors and variables, just like other normal classes.
CIA only portion:
Introduction to DevOps
DevOps is more than just a set of tools or practices. It’s an organizational change that focuses on
collaboration, automation, and continuous delivery. It breaks down the divisions that generally
separate development and operations teams, encouraging shared responsibility for the entire
software lifecycle.
Need of DevOps
Imagine a scenario where the software development team puts in a lot of effort to make cool
apps. But when it’s time to launch, the operations team faces problems. This causes delays, and
errors, and messes up the smooth flow from making the app to [Link] division may
restrict progress and hinder a company’s ability to stay competitive in the market.
Why DevOps? Why not other methods?
DevOps addresses these challenges by encouraging collaboration, communication, and
integration between development and operations teams. It aims to break down the barriers that
traditionally exist between these two separate entities. By promoting a cultural shift and utilizing
cutting-edge tools and practices, DevOps works to achieve critical objectives, such as sSpeed up
delivery, enhancing reliability, and encouraging innovation.
DevOps LifeCycle
DevOps focuses on bringing all the development, operations, and IT infrastructure guys,
including developers, testers, system admins, and QAs, under one roof. Hence, all these people
together are called DevOps engineers.
DevOps engineers share the end-to-end responsibility of gathering information, setting up the
infrastructure, developing, testing, deploying, continuously monitoring, and fetching feedback
from end-users.
Code: The first step in the DevOps life cycle is coding, where developers build the code on any
platform
Build: Developers build the version of their program in any extension depending upon the
language they are using it.
Test: For DevOps to be successful, the testing process must be automated using any DevOps
automation tool like Selenium
Release: A process for managing, planning, scheduling, and controlling the build in different
environments after testing and before deployment
Deploy: This phase gets all artifacts/code files of the application ready and deploys/executes
them on the server
Operate: The application is run after its deployment, where clients use it in real-world scenarios.
Monitor: This phase helps in providing crucial information that basically helps ensure service
uptime and optimal performance
Plan: The planning stage gathers information from the monitoring stage and, as per feedback,
implements the changes for better performance
These stages are basically the aspects of achieving the DevOps goal.
Continuous Development
In the Waterfall model, our software product gets broken into multiple pieces or sub-parts for
making the development cycles shorter, but in this stage of DevOps, the software is getting
developed continuously.
Tools used: As we code and build in this stage, we can use GIT to maintain different versions of
the code. To build/package the code into an executable file, we can use a reliable tool, namely,
Maven.
Continuous Integration
In this stage, if our code is supporting new functionality, it is integrated with the existing code
continuously. As the continuous development keeps on, the existing code needs to be integrated
with the latest one ‘continuously,’ and the changed code should ensure that there are no errors in
the current environment for it to work smoothly.
Tools used: Jenkins is the tool that is used for continuous integration. Here, we can pull the
latest code from the GIT repository, of which we can produce the build and deploy it on the test
or the production server.
Continuous Testing
In the continuous testing stage, our developed software is getting tested continuously to detect
bugs using several automation tools.
Tools used: For the QA/Testing purpose, we can use many automated tools, and the tool used
widely for automation testing is Selenium as it lets QAs test the codes in parallel to ensure that
there is no error, incompetencies, or flaws in the software.
Continuous Monitoring
It is a very crucial part of the DevOps life cycle where it provides important information that
helps us ensure service uptime and optimal performance. The operations team gets results from
reliable monitoring tools to detect and fix the bugs/flaws in the application.
Tools used: Several tools such as Nagios, Splunk, ELK Stack, and Sensu are used for
monitoring the application. They help us monitor our applications and servers closely to check
their health and whether they are operating actively. Any major issue detected by these tools is
forwarded to the development team to fix in the continuous development phase.
DevOps Tools
The most popular DevOps tools are discussed below.
Puppet: Puppet is one of the widely-used DevOps tools. It allows delivering and releasing
technology changes quickly and frequently. It has features of versioning, automated testing, and
continuous delivery.
Docker: Docker is a high-end DevOps tool that allows building, shipping, and running
distributed applications on multiple systems. It helps assemble the applications quickly and is
typically suitable for container management.
Jenkins: Jenkins is one of the most popular DevOps tools that allow monitoring of the execution
of repeated jobs. Apart from this, Jenkins lets us integrate the changes and access the results
easily and quickly.
Ansible: This tool helps automate the entire life cycle of an application, and manages
complicated deployments, and enhances productivity.
Nagios: This DevOps tool helps monitor the IT infrastructure. It is capable of determining errors
and rectifying them with the help of the standard network, server, and log monitoring systems.
Advantages of DevOps
● Faster Delivery: DevOps practices enable fast deployment, reducing time-to-market for
software.
● Improved Collaboration: DevOps encourages better communication and collaboration
among development, operations, and other teams.
● Continuous Integration and Deployment: CI/CD pipelines enables effortless code
integration, testing, and deployment, ensuring a continuous delivery cycle.
● Enhanced Quality and Stability: DevOps emphasizes automated testing, leading to
higher software quality and more stable releases.
● Scalability and Flexibility: DevOps facilitates scalability and flexibility, allowing
systems to adapt and grow with evolving requirements.
Disadvantages of DevOps
● Complexity: Implementing DevOps methodologies can be complex, requiring
comprehensive understanding and expertise.
● Initial Setup Challenges: Setting up an effective DevOps environment might involve
initial challenges in integration and tooling.
● Resistance to Change: Resistance from teams familiar with traditional methods can
hinder the implementation of DevOps principles.
● Security Concerns: Rapid iterations and frequent deployments might raise security
vulnerabilities if not managed properly.
● Dependency on Tools: Dependency on various tools and technologies might create a
challenge in terms of tool compatibility and maintenance.
Roles and Responsibilities of a DevOps Engineer
DevOps is more of a culture that is being incorporated by the giants in the IT world currently.
DevOps, when practiced the right way keeping certain roles and responsibilities in mind, helps
overcome the gap between development and operations teams.
The roles and responsibilities of DevOps Engineers are as follows:
● Project planning and management: In addition to monitoring software and regulating
and updating tools, DevOps Engineers need to have expertise in keeping track of the
costs, benefits, risks, and much more of various DevOps projects.
● Design, development, and deployment: DevOps Engineers are required to design,
develop, and deploy automated modules for smooth functioning within the production
environment, by utilizing risk-management techniques, tests, etc.
● Communication and support: DevOps Engineers should have exceptional
communication skills that come in handy when they need to work and coordinate with
different departments and provide support.
● Technical skills: Some basic technical experience and familiarity with configuration
tools are a must.
● Interpersonal skills: Since DevOps Engineers are in constant interaction with other
departments in the organization, they should be approachable, organized, and foresighted
team players with an ability to multitask.
● Troubleshooting: Last but not least, one of the major responsibilities of DevOps
Engineers is to troubleshoot and come up with apt solutions for various errors to benefit
the firm with speed and efficiency.
Job Opportunities in DevOps
DevOps opens up a huge world of career options. If we are skillful enough and certified, we can
go for any of the below-mentioned profiles and bag high salaries.
● DevOps Evangelist: Identifies the benefits coming from DevOps and thus aids in the
promotion of DevOps
● Code Release Manager: Understands the Agile methodology and supervises the overall
progress
● Automation Architect: Designs and builds automated tools and systems to implement
continuous and smooth deployments
● Experience Assurance: Enhances user experience by finding bugs and including all the
essential features in the applications
● Software Developer/Tester: Makes sure that the code meets all the original business
requirements, along with performs testing and monitoring
● Security Engineer: Integrates security into the applications and products to keep the
business safe