KEMBAR78
JAVA & TCS Mid Sem | PDF | Inheritance (Object Oriented Programming) | Class (Computer Programming)
0% found this document useful (0 votes)
20 views6 pages

JAVA & TCS Mid Sem

Uploaded by

King Kong
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)
20 views6 pages

JAVA & TCS Mid Sem

Uploaded by

King Kong
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/ 6

Moore and Mealy machines Diff :

Moore Machine: 1)The output depends only on the current


state.2)The output is stable and changes only when the state
changes.3)Typically requires more states to produce the same
output behaviour because each output is associated with a specific
state.4)Simpler to design and understand because the output is
purely a function of the state.5)Slower response to input changes
since the output only changes when the state changes.6)The output
is associated with the states in the state diagram.
Mealy Machine: 1) The output depends on both the current state
and the current input. 2) The output can change immediately when
the input changes, even without a state change. 3)Usually requires
fewer states since the output can change based on inputs without
needing additional states. 4) More complex to design due to the
dependency on both state and input for determining the output.
5)Faster response to input changes because the output can change
as soon as the input changes. 6)The output is associated with the
transitions (arcs) in the state diagram.
Differences between DFA & NFA:
DFA: 1)For each state and input symbol, there is exactly one
possible transition. 2)The next state is uniquely determined by the
current state and input symbol. 3)DFA does not allow ε (epsilon)
transitions 4) DFAs can be more complex to implement since every
state and input must be explicitly defined. 5) DFAs are generally
more efficient in execution since they don't involve backtracking or
multiple paths.
NFA 1)For each state and input symbol, there can be multiple
possible transitions. 2)The automaton can transition to any of the
possible next states, leading to multiple potential paths. 3) NFA
allows ε (epsilon) transitions, which means the automaton can
change states without consuming any input. 4) NFAs can be simpler
to represent as they allow multiple paths and transitions without
explicitly defining every possible path. 5) NFAs may involve
backtracking or exploring multiple paths simultaneously to
determine acceptance.
Automata are abstract models that help us understand how
systems or machines process data or perform calculations. They
describe how a system can be in one of several states and how it
moves from one state to another based on certain inputs.
Finite Automaton is a simple computational model used in
computer science to represent and simulate sequential logic. It
consists of a finite number of states, transitions between those
states, and actions that occur based on input symbols. Finite
automata are used to recognize patterns within input data, such as
strings of characters, and can be categorised into two main types:
Deterministic Finite Automata Nondeterministic Finite Automata
Difference between Procedure-Oriented Programming &
Object -Oriented Programming
POP: 1) Centers around functions or procedures that operate on
data. The primary emphasis is on what the program does.
2) Data and functions are separate; functions operate on data
passed to them. 3) Follows a linear, top-down approach, where
tasks are broken down into procedures. 4) Code reusability is
limited, as functions and data structures are often not designed to
be reused across different parts of the program. 5) Maintenance
can be more challenging due to tightly coupled functions and data,
making it harder to track changes and debug.
OOP : 1) Centers around objects that combine data and methods.
The primary emphasis is on modelling real-world entities and their
interactions. 2) Data and functions are encapsulated within objects,
with methods operating on the object's own data. 3) Follows a
modular, top-down or bottom-up approach, focusing on creating and
interacting with objects. 4) High code reusability through inheritance
and composition, allowing objects and classes to be reused and
extended. 5) Easier maintenance due to encapsulation and
modularity, which helps isolate changes and reduces side effects.
Object-Oriented Programming (OOP) is a programming paradigm
that organizes software design around objects, rather than functions
or logic. An object in OOP is a self-contained unit that combines
data (attributes) and functions (methods) that operate on the data.
Advantages: 1)Divides programs into classes, making code easier
to manage and understand. 2)Classes can be reused across
different projects, saving time and effort.
3)Changes in one class automatically update related parts of the
program. 4)Easily add or extend features by creating or modifying
classes. 5)Different team members can work on separate classes
simultaneously without interfering.

OOP Concepts 1)Classes: Blueprints for creating objects, defining


their attributes and methods. 2)Objects: Instances of classes,
representing specific items with their own data and behaviours.
3)Encapsulation: Bundling data and methods into a single unit and
controlling access to some of the data. 4)Inheritance: Mechanism
by which one class can inherit attributes and methods from another,
promoting code reuse. 5)Polymorphism: Ability to define methods
with the same name but different implementations in different
classes. 6)Data Abstraction: Hiding complex implementation
details and exposing only the necessary features of an object.

Features Of JAVA 1) Object-Oriented: Java uses objects and


classes to organize code, promoting modularity and reusability.
2) Platform-Independent: Java code runs on any device with a
Java Virtual Machine (JVM), thanks to its "write once, run
anywhere" capability. 3)Robust: Java has strong error-checking
mechanisms, such as exception handling and garbage collection,
which help prevent crashes and memory leaks.
4)Secure:Java provides a secure environment through features like
the Java sandbox and bytecode verification, which help protect
against malicious code. 5)Multithreaded: Java supports
multithreading, allowing concurrent execution of multiple threads,
which enhances performance and responsiveness in applications.
Classes in JAVA: 1) Concrete Classes: Regular classes that can
be instantiated and have complete implementations of their
methods. 2)Abstract Classes: Classes that cannot be instantiated
and may contain abstract methods (methods without
implementations) that must be implemented by subclasses.
3)Interface Classes: Special types of classes that define methods
but do not provide implementations. Classes that implement
interfaces must provide the method implementations.
4) Nested Classes or inner classes: Classes defined within another
class. They can be static or non-static
Constructors: a constructor is a special method used to initialise
objects when they are created. A constructor has the same name
as the class and does not have a return type
Types of Constructor: Default Constructor: A constructor that
takes no arguments and is automatically provided by Java if no
other constructors are explicitly defined. It Initialises object
attributes with default values
Parameterized Constructor: A constructor that takes one or more
arguments to initialise object attributes with specific values provided
at the time of object creation. It allows for the initialization of an
object with custom values rather than default ones.
Constructor Overloading in Java refers to the ability to define
multiple constructors within the same class, each with a different
parameter list. This allows a class to be initialised in various ways
depending on the arguments passed during object creation.
Static Variable: A static variable belongs to the class, not to any
specific object. This means all objects of the class share the same
static variable. It's declared using the static keyword
Static Methods: A static method belongs to the class rather than
any object of the class. It can be called without creating an instance
of the class. Static methods can only access static variables
directlyConstructor Overloading: This is when a class has more
than one constructor with different parameter lists. It allows for
different ways of initialising objects.
Predefined Classes in Java are built-in classes provided by the
Java Standard Library. These classes are part of the Java
Development Kit (JDK) and offer various functionalities that simplify
programming tasks. Here are some classes
1)Object Class The root class of the Java class hierarchy. Every
class in Java implicitly inherits from the Object class. It provides
basic methods that are common to all objects, such as toString(),
equals(), hashCode(), and clone().
2)String Class A class used to represent and manipulate
immutable sequences of characters. It provides methods for string
manipulation, such as concatenation, substring extraction, and
searching.
3. StringBuffer Class: A class that provides a mutable sequence
of characters, allowing modifications without creating new objects.
It is used for efficiently building and modifying strings, especially in
scenarios with frequent updates.
4)Wrapper Classes: Classes that wrap primitive data types into
objects. It provides methods to convert between primitive types and
objects, and offers additional functionality for primitives.

Packages are a way to organise and group related classes and


interfaces into a single namespace. Packages help manage and
organise code by grouping related classes, interfaces, and
sub-packages. They also avoid naming conflicts and provide
access control. A package is essentially a directory structure where
classes and interfaces are stored. To use classes from a package,
you either import them into your code or refer to them using their
fully qualified name
Types of inheritance: 1)Single Inheritance: A class (subclass)
inherits from only one parent class (superclass).
2)Multilevel Inheritance: A class inherits from another class, which
itself is a subclass of another class, forming a chain of inheritance.
3)Hierarchical Inheritance: Multiple classes inherit from a single
parent class. Each subclass shares the common properties and
methods of the superclass.
Inheritance is a fundamental concept in Object-Oriented
Programming (OOP) that allows one class to inherit properties and
behaviours from another class. This mechanism promotes code
reuse and establishes a hierarchy between classes.
A subclass is a specialised version of a superclass that extends or
enhances its functionality. It inherits all non-private fields and
methods from the superclass and can also have additional fields
and methods of its own. Member Access refers to the ability to
access or modify the fields (variables) and methods (functions) of a
class from different parts of a program. In Java, member access is
controlled by access modifiers, which specify the visibility and
accessibility of class members. Method Overriding is a feature in
object-oriented programming that allows a subclass to provide a
specific implementation for a method that is already defined in its
superclass. This is a way to modify or extend the behaviour of
methods inherited from the superclass. When a subclass provides
its own implementation of a method that is already defined in its
superclass, it is called method overriding. Polymorphism allows
objects of different classes to be treated as objects of a common
superclass. The most common use of polymorphism is when a
method or property can take on many forms depending on the
context. Dynamic Binding (also known as late binding) is the
process of determining which method implementation to call at
runtime rather than compile-time. It is closely associated with
polymorphism and allows for method calls to be resolved based on
the actual object type rather than the reference type.
Method Overriding: Method overriding occurs when a subclass
provides a specific implementation for a method already defined in
its parent class. The overridden method must have the same name,
return type, and parameters String Functions:These are methods
provided by programming languages to manipulate strings.
Common functions include:1) length(): Returns the length of the
string. 2)substring(): Returns a part of the string. 3)replace():
Replaces occurrences of a substring with another substring.

You might also like