Unit I
Unit I
SEMESTER III
Data structures are designed such that they characterize the objects.
OBJECTS
ENCAPSULATION
POLYMORPHISM
INHERITANCE
ABSTRACTION
Class
A class is a data-type that has its own members i.e. data members and member
functions. It is the blueprint for an object in object oriented programming language.
It is the basic building block of object oriented programming in c++. The members of a
class are accessed in programming language by creating an instance of the class.
Object
Encapsulation
In our colleges, we have departments for each course like computer science,
information technology, Computer Application, etc. each of these departments have
their own students and subjects that are kept track of and being taught.
let's think of each department as a class that encapsulates the data about students of
that department and the subjects that are to be taught.
Also a department has some fixed rules and guidelines that are to be followed by the
students that course like timings, methods used while learning, etc. this is
encapsulation in real life, there are data and there are ways to manipulate data.
Polymorphism
The name defines polymorphism is multiple forms. which means polymorphism is the
ability of object oriented programming to do some work using multiple forms. The
behaviour of the method is dependent on the type or the situation in which the method
is called.
Let‟s take a real life example, A person can have more than one behaviour depending
upon the situation. like a woman a mother, manager and a daughter And this define
her behaviour. This is from where the concept of polymorphism came from.
In C++ programming language, polymorphism is achieved using two ways. They are
operator overloading and function overloading.
Operator overloading
Function overloading
Functions with the same name that can do multiple types based on some condition.
Inheritance
single inheritance
multiple inheritance
Hierarchical inheritance
hybrid inheritance
Abstraction
Data abstraction or Data Hiding is the concept of hiding data and showing only
relevant data to the final user. It is also an important part object oriented programing.
let's take real life example to understand concept better, when we ride a bike we only
know that pressing the brake will stop the bike and rotating the throttle will accelerate
but you don't know how it works and it is also not think we should know that's why this
is done from the same as a concept data abstraction.
In C++ programming language write two ways using which we can accomplish data
abstraction −
using class
There are several benefits of OOP to both program designer and the user. Object orientation
solves many problems which are associated with the development and quality of software
products. New technology gives greater programmer productivity, good quality of software
and low maintanance cost. The main advantages are:
We can eliminate redundant code and extend the use of existing classes.
The data hiding rules helps the programmer to make secure programs that
cannot be invaded by code in other parts of the program.
It has map objects in the problem domain to those objects in the program.
1. Image Processing
2. Pattern Recognition
3. Computer Assisted Concurrent Engineering
4. Computer Aided Design and Manufacturing
5. Computer Aided Teaching
6. Intelligent Systems
7. Database Management Systems
8. Web based Applications
9. Distributed Computing and Applications
10. Component based Applications
11. Business Process Reengineering
12. Enterprise resource planning
13. Data security and management
14. Mobile Computing
15. Data Warehouse and Data Mining
16. Parallel Computing
Java History:
Java is as of 2012 one of the most popular programming languages in use, particularly
for client-server web applications, with a reported 10 million users.
The original and reference implementation Java compilers, virtual machines, and class
libraries were developed by Sun from 1991 and first released in 1995.
As of May 2007, in compliance with the specifications of the Java Community
Process, Sun relicensed most of its Java technologies under the GNU General Public
License.
Milestones of Java
1.5 Java features:
The inventors of java wanted to design a language which could offer solutions to some
of the problems encountered in modern programming they wanted the language to be not
only reliable, portable and distributed but also simple, compact and interactive
Sun micro System officially describes java with the following attributes:
Compiled and interpreted
Platform _independent and portable
Object-oriented
Robust and secure
Distributed
Familiar, simple and interactive
High performance
Dynamic and Extensible
Ease of development
Scalability of performance
Monitoring and manageability
desktop client
Core XML support
Supplementary character support
JDBC Rowset
These features have made java the first application language of the World Wide Web java
will also become the premier language for general purpose standalone application
Simple and powerful
Object oriented to java
You can learn to program in java quickly once the basic concepts of object-oriented
programming are understood.
You once need to understand a few concepts in order to write productive and
satisfying program.
This style of simplicity has often produced inefficient and non-expressive “scripting
language”.
Java is not scripting language.
Safe
Java is protocol, it provide security and safe.
Even your word processor documents can carry viruses.
One of the key design principles of java is safety and security.
Object-oriented
Class and object are used in java.
Most other object-oriented systems have chosen to have rigid, hard-to –manage
object hierarchies.
It is not a direct derivative of any other programming language, nor is‟t in any way
upward compatible with one.
Robust
It is very strong it is a case sensitive language.
You might think that robustness is a luxury in these times of adventure on the internet.
Java is a very strict language when it comes to type and declarations, most common
errors can be caught time.
Interactive
Requirements real word event It is very interactive to use.
Java was designed to meet the real-word requirement of creating interactive network
program.
Most systems have a hard time dealing with either
One, let alone interactivity and networking at once.
Architecture neutral
Portable language.
Run anywhere at any time.
It‟s work on “macintosh, pc, unix” and whatever the platforms can offer.
Interpreted and high performance
Java is the byte code format it‟s carefully design.
All platforms are independent.
It‟s easy to translate directly into native machine code for very high performance.
Easy to learn
The language features feel like the natural way to do things and encourage good
programming style.
Java is more complicated then a scripting language.
It‟s an object-oriented program.
Java is Compiled and Interpreted
Java compiler
Java is not lot like C but the major difference between Java and C is that Java is an object-
oriented language and has a mechanism to define classes and objects. In an effort to build a
simple and safe language, the Java team did not include some of the C features in Java.
1. Java does not include the C unique statement keywords size of and typedef.
2. Java does not contain the data type struct and union.
3. Java does not define the type modifiers keywords auto, extern, register, signed, and
unsigned.
4. Java does not support an explicit pointer type.
5. Java does not have a preprocessor and therefore we cannot use # define, # include,
and # ifdef statements.
6. Java requires that the functions with no arguments must be declared with empty
parenthesis and not with the void keyword as done in C.
7. Java adds new operators such as instanceof and >>>.
8. Java adds labelled break and continue statements.
9. Java adds many features required for object-oriented programming.
It does include the unique statement It does not include the C unique statement
keywords sizeof, and typedef. keywords sizeof, and typedef.
It contain the data type struct and union. It does not contain the data type struct and union.
C Programming Java Programming
It define the type modifiers keywords It does not define the type modifiers keywords
auto, extern, register, signed, and auto, extern, register, signed, and unsigned.
unsigned.
It supports an explicit pointer type. It does not support an explicit pointer type.
It has a preprocessor and therefore we It does not have a preprocessor and therefore we
can use # define, # include, and # ifdef cannot use # define, # include, and # ifdef
statements. statements.
It requires that the functions with no It requires that the functions with no arguments
arguments, with the void keyword must be declared with empty parenthesis, not
with the void keyword
C has no operators such as instanceof Java adds new operators such as instanceof and
and >>>. >>>.
C adds have a break and continue Java adds labeled break and continue statements.
statements.
C has no object-oriented programming Java adds many features required for object-
features. oriented programming.
Listed below are some major C++ features that were intentionally omitted from Java or
significantly modified.
It support has template classes. It does not have template classes as in C++.
It supports global variables. It does not support global variables. Every variable and
method is declared within classes and forms part of that
class.
It does not support destructor It has replaced the destructor function with a finalize()
function with a finalize() function. function.
There are header files in Java. There are no header files in Java.
Web Browsers
The internet is a vast sea of information represented in many formats and stored on many
computers. a browser is a software application used to locate, retrieve and display
content on the World Wide Web, including Web pages, images, video and other files.
As a client/server model, the browser is the client run on a computer that contacts the
Web server and requests information. The Web server sends the information back to the
Web browser which displays the results.
The browser application retrieves or fetches code, usually written in HTML (Hypertext
Markup Language) and/or another language, from a web server, interprets this code, and
renders (displays) it as a Web page for you to view. on the computer or another Internet-
enabled device that supports a browser.
Hot Java
Netscape Navigator
Internet Explorer
Google Chrome
Web Browser
local computer should be connected to the internet
Web Server
A program that accepts a request from a user and gives output as per the requirement.
Apache TomCat server is one of the major web servers.
Web Browser
The web browser is a software that will allow you to view web pages on the internet. it is a
program that you use to access the Internet. It reads and knows how to display and
download files that are put on servers for people to read. A program that provides the access
of WWW and runs java applets. Chrome and Firefox are two major web browsers.
HTML
HTML is short for Hypertext Markup Language. HTML is used to create electronic documents
(called pages) that are displayed on the World Wide Web. Each page contains a series of
connections to other pages called hyperlinks. Every web page you see on the Internet is
written using one version of HTML code or another.
Execution of Applets
Interactive WWW
Flashy animation instead of static web pages
Applets react to users input and dynamically change
Display of dynamic data
WWW with Java - more than a document publishing medium
http://www.javasoft.com/applets/alpha/applets/StockDemo/standalone.html
Power of Java and the Web
Deliver applications, not just information
Eliminate porting
Eliminate end-user installation
Slash software distribution costs
Reach millions of customers - instantly
Java Development Kit
javac - The Java Compiler
java - The Java Interpreter
jdb- The Java Debugger
appletviewer -Tool to run the applets
javap - to print the Java bytecodes
javaprof - Java profiler
javadoc - documentation generator
javah - creates C header files
Java programming language was originally developed by Sun Microsystems which was
initiated by James Gosling and released in 1995 as core component of Sun
Microsystems' Java platform (Java 1.0 [J2SE]).
The latest release of the Java Standard Edition is Java SE 8. With the advancement of
Java and its widespread popularity, multiple configurations were built to suit various types
of platforms. For example: J2EE for Enterprise Applications, J2ME for Mobile
Applications.
The new J2 versions were renamed as Java SE, Java EE, and Java ME respectively.
Java is guaranteed to be Write Once, Run Anywhere.
When we consider a Java program, it can be defined as a collection of objects that
communicate via invoking each other's methods. Let us now briefly look into what do
class, object, methods, and instance variables mean.
Object − Objects have states and behaviors. Example: A dog has states - color, name,
breed as well as behavior such as wagging their tail, barking, eating. An object is an
instance of a class.
Class − A class can be defined as a template/blueprint that describes the behavior/state
that the object of its type supports.
Methods − A method is basically a behavior. A class can contain many methods. It is in
methods where the logics are written, data is manipulated and all the actions are
executed.
Instance Variables − Each object has its unique set of instance variables. An object's
state is created by the values assigned to these instance variables.
You can use any editor like notepad or any Java IDE for writing java programs.
/*
*/
class Welcome
After we have written our program we need to compile and run the program. For that we
need to use the compiler called javac which is provided by java.
Go to the command prompt and type the file name as shown here.
c;\>javac Welcome.java
The javac compiler will create a class file called Welcome.class that contains only bytecodes.
These bytecodes have to be interpreted by a Java Virtual Machine(JVM) that will convert the
bytecodes into machine codes. Once we successfully compiled the program, we need to run
the program in order to get the output. So this can be done by the java interpreter called java.
In the command line type as shown here.
c:\>java Welcome
Welcome to Java-Sample!!!
Java Tokens
Token: A unit of user input. Tokens are separated by whitespace (spaces, tabs, new
lines).
Example: If an input file contains the following:
23 3.14
"John Smith"
The tokens in the input are the following, and can be interpreted as the given
types:
Token Type(s)
3. "John String
4. Smith" String
JVM
JVMs are available for many hardware and software platforms. The use of the same
bytecode for all JVMs on all platforms allows Java to be described as a "compile once, run
anywhere" programming language, as opposed to "write once, compile anywhere", which
describes cross-platform compiled languages. Thus, the JVM is a crucial component of the
Java platform.
Java bytecode is an intermediate language which is typically compiled from Java, but it can
also be compiled from other programming languages. For example, Ada source code can be
compiled to Java bytecode and executed on a JVM.
Important University Question Bank
Section - B
Section-C (8 MARK)
1. Discuss basic concept of oops.(2017,2010)
2. Describe the structure of java program with an example(2012)
3. Discuss basic concept of oops.(2019)
4. Describe the structure of java program with an example.(2013)
5. Briefly describe about any four OOP concepts.( 20072014,2019)
6. Explain the basic concept of oops.(2015)
7. How java differs from c and c++.(2017,2019)
8. Describe the various feature of java.(2013,2019)
9. Discuss the application and benefit of OOP. (2013,2015,2019)
10. Explain the following concept with an example(2016,2018)
i. Web browser ii. Java tokens
11. Explain the basic concept of object oriented programming.(2011,2019)
12.Write a note on java tokens. (2011,2014)
Expected Questions