0% found this document useful (0 votes)
11 views29 pages

Unit-1 and Unit-2

Java is a versatile programming language used for various applications, requiring a class definition and a main method. The document explains the roles of JVM, JRE, and JDK, as well as concepts like inheritance, method overriding, and access modifiers. Additionally, it covers the Software Development Life Cycle (SDLC) stages and types of Database Management Systems (DBMS).

Uploaded by

karmjoshi992
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views29 pages

Unit-1 and Unit-2

Java is a versatile programming language used for various applications, requiring a class definition and a main method. The document explains the roles of JVM, JRE, and JDK, as well as concepts like inheritance, method overriding, and access modifiers. Additionally, it covers the Software Development Life Cycle (SDLC) stages and types of Database Management Systems (DBMS).

Uploaded by

karmjoshi992
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 29

Java

Java is a popular programming language.


Java is used to develop mobile apps, web apps, desktop apps, games and much more.

Every Java application has a class definition, and the name of the class should match the filename in Java.

Every application in Java must contain the main method. The Java compiler starts executing the code from the
main method.

Java JDK, JRE and JVM


What is JVM?
JVM (Java Virtual Machine) is an abstract machine that enables your computer to run a Java program.
When you run the Java program, Java compiler first compiles your Java code to bytecode. Then, the JVM
translates bytecode into native machine code (set of instructions that a computer's CPU executes directly).
Java is a platform-independent language. It's because when you write Java code, it's ultimately written for JVM
but not your physical machine (computer). Since JVM executes the Java bytecode which is platform-
independent, Java is platform-independent.

What is JRE?
JRE (Java Runtime Environment) is a software package that provides Java class libraries, Java Virtual Machine
(JVM), and other components that are required to run Java applications.
JRE is the superset of JVM.
What is JDK?
JDK (Java Development Kit) is a software development kit required to develop applications in Java. When you
download JDK, JRE is also downloaded with it.
In addition to JRE, JDK also contains a number of development tools (compilers, JavaDoc, Java Debugger,
etc).

Relationship between JVM, JRE, and JDK.


Difference Between JVM and DVM

DVM(Dalvik Virtual Machine)


DVM is a virtual machine to execute Android applications. The Java bytecode(.class file) generated by javac
compiler is converted into Dalvik bytecode to make the application source files executable on the DVM. Since
Android devices have a definite processing capacity, memory, and battery life, the DVM design principle aims
to optimize itself so that it can load fastly and run smoothly even on low memory/powered devices. This virtual
machine is very efficient in running multiple instances on the same device.

JVM(Java Virtual Machine) DVM(Dalvik Virtual Machine)

Stack-based VM that performs arithmetic and


logic operations through push and pop Register-based VM that uses registers located in the CPU to
operands. The result of operations is stored in perform arithmetic and logic operations.
stack memory.
Source code files are first of all compiled into Java bytecode
Java source code is compiled into Java
format like JVM. Further, the DEX compiler(dx tool) converts
bytecode format(.class file) that further
the Java bytecode into Dalvik bytecode(classes.dex) file that will
translates into machine code.
be used to create the .apk file.
More information is required to the VM for
Instruction size is larger as it needs to encode the source and
data loading and manipulation as well as
destination register of the VM.
method loading in the stack data structure.
Compiled bytecode size is compact because
Compiled bytecode size is larger as each instruction needs all
the location of the operand is implicitly on
implicit operands.
the operand stack.
The executable file for the device is .jar file. The executable file for the device is .apk file.
A single instance of JVM is configured with
The device runs multiple DVM instances with a separate process
shared processes and memory space in order
in shared memory space to deploy the code of each application.
to run all deployed applications.
Supports multiple operating systems like
Support only the Android operation system.
Linux, Windows, and Mac OS.
Java Class
A class is a blueprint for the object.

In Java, there are two types of methods:


• User-defined Methods: We can create our own method based on our requirements.
• Standard Library Methods: These are built-in methods in Java that are available to use.
The complete syntax of declaring a method is
Standard Library Methods
The standard library methods are built-in methods in Java that are readily available for use. These standard
libraries come along with the Java Class Library (JCL) in a Java archive (*.jar) file with JVM and JRE.
For example,
• print() is a method of java.io.PrintSteam. The print("...") method prints the string inside quotation
marks.
• sqrt() is a method of Math class. It returns the square root of a number.

Method overloading

In Java, two or more methods may have the same name if they differ in parameters (different number of
parameters, different types of parameters, or both). These methods are called overloaded methods and this
feature is called method overloading. For example:
What is a Constructor?
A constructor in Java is similar to a method that is invoked when an object of the class is created.
Unlike Java methods, a constructor has the same name as that of the class and does not have any return type.
For example,
Types of Constructor
In Java, constructors can be divided into 3 types:
1. No-Arg Constructor No-Arg Constructor
2. Parameterized Constructor
3. Default Constructor
No-Arg Constructor
If a constructor does not accept any parameters, it is known as a no-argument constructor.
Parameterized Constructor
A Java constructor can also accept one or more parameters. Such constructors are known as parameterized
constructors (constructor with parameters).
Java Default Constructor
If we do not create any constructor, the Java compiler automatically create a no-arg constructor during the
execution of the program. This constructor is called default constructor.
Constructors Overloading in Java
Similar to Java method overloading, we can also create two or more constructors with different parameters.
This is called constructors overloading.

Java Access Modifiers


In Java, access modifiers are used to set the accessibility (visibility) of classes, interfaces, variables, methods,
constructors, data members, and the setter methods.
Default Access Modifier
If we do not explicitly specify any access modifier for classes, methods, variables, etc, then by default the
default access modifier is considered. For example,

Private Access Modifier


When variables and methods are declared private, they cannot be accessed outside of the class. For example,
Protected Access Modifier
When methods and data members are declared protected, we can access them within the same package as well
as from subclasses.
Public Access Modifier
When methods, variables, classes, and so on are declared public, then we can access them from anywhere. The
public access modifier has no scope restriction. For example,

Java this Keyword


In this article, we will learn about this keyword in Java, how and where to use them with the help of examples.
this Keyword
In Java, this keyword is used to refer to the current object inside a method or a constructor. For example

Why use this keyword

In Java, it is not allowed to declare two or more variables having the same name inside a scope (class scope or
method scope). However, instance variables and parameters may have the same name. For example,
In the above example, we have passed 8 as a value to the constructor. However, we are getting 0 as an output.
This is because the Java compiler gets confused because of the ambiguity in names between instance the
variable and the parameter.

Java final keyword


In this tutorial, we will learn about Java final variables, methods and classes with examples.
In Java, the final keyword is used to denote constants. It can be used with variables, methods, and classes.
Once any entity (variable, method or class) is declared final, it can be assigned only once. That is,
• the final variable cannot be reinitialized with another value
• the final method cannot be overridden
• the final class cannot be extended
Java Inheritance
Inheritance is one of the key features of OOP
that allows us to create a new class from an
existing class.
The new class that is created is known as subclass (child or derived class) and the existing class from where the
child class is derived is known as superclass (parent or base class).
The extends keyword is used to perform inheritance in Java. For example,

Why use inheritance?


• The most important use of inheritance in Java is code reusability. The code that is present in the parent
class can be directly used by the child class.
• Method overriding is also known as runtime polymorphism. Hence, we can achieve Polymorphism in
Java with the help of inheritance.
Java Method Overriding
Inheritance is an OOP property that allows us to derive a new class (subclass) from an existing class
(superclass). The subclass inherits the attributes and methods of the superclass.
Now, if the same method is defined in both the superclass and the subclass, then the method of the subclass
class overrides the method of the superclass. This is known as method overriding.

Notice the use of the @Override annotation in our example. In Java, annotations are the metadata that we used
to provide information to the compiler. Here, the @Override annotation specifies the compiler that the method
after this annotation overrides the method of the superclass.
It is not mandatory to use @Override. However, when we use this, the method should follow all the rules of
overriding. Otherwise, the compiler will generate an error.

Java Overriding Rules


• Both the superclass and the subclass must have the same method name, the same return type and the
same parameter list.
• We cannot override the method declared as final and static.
• We should always override abstract methods of the superclass.

Super Keyword

A common question that arises while performing overriding in Java is:

Can we access the method of the superclass after overriding?


Well, the answer is Yes. To access the method of the superclass from the subclass, we use the super keyword.
The super keyword in Java is used in subclasses to access superclass members (attributes, constructors and
methods).

Uses of super keyword


1.To call methods of the superclass that is overridden in the subclass.

2.To access attributes (fields) of the superclass if both superclass and subclass have attributes with the same
name.

3.To explicitly call superclass no-arg (default) or parameterized constructor from the subclass constructor.

Java Abstract Class


The abstract class in Java cannot be instantiated (we cannot create objects of abstract classes). We use
the abstract keyword to declare an abstract class.

An abstract class can have both the regular methods and abstract methods.

Java Abstract Method


A method that doesn't have its body is known as an abstract method. We use the same abstract keyword to
create abstract methods.
Here, display() is an abstract method. The body of display() is replaced by ;.

If a class contains an abstract method, then the class should be declared abstract. Otherwise, it will generate an
error.

Though abstract classes cannot be instantiated, we can create subclasses from it. We can then access members
of the abstract class using the object of the subclass. For example,
The major use of abstract classes and methods is to achieve abstraction in Java.

Java Interface
An interface is a fully abstract class. It includes a group of abstract methods (methods without a
body).
We use the interface keyword to create an interface in Java. For example,
Like abstract classes, we cannot create objects of interfaces.

To use an interface, other classes must implement it. We use the implements keyword to implement
an interface.

Software Development Life Cycle (SDLC)


The Software Development Life Cycle (SDLC) is a structured process that enables the production of high-
quality, low-cost software, in the shortest possible production time. The goal of the SDLC is to produce
superior software that meets and exceeds all customer expectations and demands.
The SDLC defines and outlines a detailed plan with stages, or phases, that each encompass their own process
and deliverables. Adherence to the SDLC enhances development speed and minimizes project risks and costs
associated with alternative methods of production.

Why is the SDLC important?


⚫ It provides a standardized framework that defines activities and deliverables
⚫ It aids in project planning, estimating, and scheduling
⚫ It makes project tracking and control easier
⚫ It increases visibility on all aspects of the life cycle to all stakeholders involved in the development process
⚫ It increases the speed of development
⚫ It improves client relations
⚫ It decreases project risks
⚫ It decreases project management expenses and the overall cost of production
Different stages of the Software Development Life Cycle.

Stages and Best Practices


Following the best practices and/or stages of SDLC ensures the process works in a smooth, efficient, and
productive way.

1. Identify the Current Problems


“What are the current problems?” This stage of the SDLC means getting input from all stakeholders, including
customers, salespeople, industry experts, and programmers. Learn the strengths and weaknesses of the current
system with improvement as the goal.

2. Plan
“What do we want?” In this stage of the SDLC, the team determines the cost and resources required for
implementing the analyzed requirements. It also details the risks involved and provides sub-plans for softening
those risks.
In other words, the team should determine the feasibility of the project and how they can implement the project
successfully with the lowest risk in mind.

3. Design
“How will we get what we want?” This phase of the SDLC starts by turning the software specifications into a
design plan called the Design Specification. All stakeholders then review this plan and offer feedback and
suggestions. It’s crucial to have a plan for collecting and incorporating stakeholder input into this document.
Failure at this stage will almost certainly result in cost overruns at best and the total collapse of the project at
worst.

4. Build
“Let’s create what we want.”
At this stage, the actual development starts. It’s important that every developer sticks to the agreed blueprint.
Also, make sure you have proper guidelines in place about the code style and practices.
For example, define a nomenclature for files or define a variable naming style such as camelCase. This will
help your team to produce organized and consistent code that is easier to understand but also to test during the
next phase.

5. Code Test
“Did we get what we want?” In this stage, we test for defects and deficiencies. We fix those issues until the
product meets the original specifications.
In short, we want to verify if the code meets the defined requirements.

6. Software Deployment
“Let’s start using what we got.”

At this stage, the goal is to deploy the software to the production environment so users can start using the
product. However, many organizations choose to move the product through different deployment environments
such as a testing or staging environment.

This allows any stakeholders to safely play with the product before releasing it to the market. Besides, this
allows any final mistakes to be caught before releasing the product.

Extra: Software Maintenance


“Let’s get this closer to what we want.” The plan almost never turns out perfect when it meets reality. Further,
as conditions in the real world change, we need to update and advance the software to match.

The most common SDLC examples or SDLC models are listed below.
◼ Waterfall Model
◼ Agile Model
◼ Iterative Model
◼ Iterative Model
◼ Spiral Model

Data Flow Diagram (DFD)


A data flow diagram (DFD) is a graphical or visual representation using a standardized set of symbols and
notations to describe a business's operations through data movement. They are often elements of a formal
methodology such as Structured Systems Analysis and Design Method
All DFD notions will represent the following:
⚫ External entities: information enters from or exits to the system being described
⚫ Flows: define the movement of information to, from and within the system being described
⚫ Stores: places where information is maintained or held, most often databases or database tables
⚫ Processes: transform information

Different DFD methodologies use different symbol conventions.

What are the different DFD levels and layers?


Levels or layers are used in DFDs to represent progressive degrees of detail about the system or process. These
levels include:
◼ Level 0: Also known as a "context diagram," this is the highest level and represents a very simple,
top-level view of the system being represented.
◼ Level 1: Still a relatively broad view of the system, but incorporates subprocesses and more detail.
◼ Level 2: Provides even more detail and continues to break down subprocesses as needed.
◼ Level 3: While this amount of detail is uncommon, complex systems can benefit from
representation at this level.
Database Management Systems (DBMS)
A database is an organized collection of data so that it can be easily accessed. To manage these databases,
Database Management Systems (DBMS) are used.

Types of DBMS
In general, there are two common types of databases:
⚫ Non-Relational
⚫ Relational
Non-Relational Database Management System (Non-RDBMS)
In Non-RDBMS, data is stored in key-value pairs. For example:

Here, customers' data are stored in key-value pairs.


Commonly used Non-RDBMS: MongoDB, Amazon DynamoDB, Redis, etc.

Relational Database Management System (RDBMS)


In RDBMS, data is stored in tabular format. For example,

Here, customers is a table inside the database.

The first row is the attributes of the table. Each row after that contains the data of a customer.
In RDBMS, two or more tables may be related to each other. Hence the term "Relational". For example,
Here, orders and customers are related through customer_id.
Commonly used RDBMS: MySQL, PostgreSQL, MSSQL, Oracle etc.
Note: To access data from these relational databases, SQL (Structured Query Language) is used.

You might also like