0% found this document useful (0 votes)
1 views10 pages

Java Unit 1

The document provides an overview of Object-Oriented Programming (OOP) principles, including key concepts such as classes, objects, inheritance, and polymorphism, emphasizing their benefits in software development. It also discusses the evolution of Java, its features, and how it differs from C and C++, highlighting its applications in various domains. Additionally, the document includes a simple Java program example and outlines the structure of a Java program.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
1 views10 pages

Java Unit 1

The document provides an overview of Object-Oriented Programming (OOP) principles, including key concepts such as classes, objects, inheritance, and polymorphism, emphasizing their benefits in software development. It also discusses the evolution of Java, its features, and how it differs from C and C++, highlighting its applications in various domains. Additionally, the document includes a simple Java program example and outlines the structure of a Java program.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

ONJECT ORIENTED PROGRAMMING WITH JAVA

UNIT - 1

FUNDAMENTALS OF OBJECT-ORIENTED PROGRAMMING

Implement real-world entities in programming


The main aim of OOP is to bind together the data and the functions
creating objects that combine data and behavior, enabling developers to write more modular,
flexible, and maintainable code.

BASICS CONCETPS OF OOP PROGRAMMING


 Class
 Objects
 Data Abstraction
 Encapsulation
 Inheritance
 Polymorphism
 Dynamic Binding
 Message Passing

1. Class:
 Collection of object of similar data type.
 It is a user-defined data type.
 Consists of data members and member functions,
 A class is like a blueprint for an object.
 Example: Fruits mango
2. Objects
 Basic Runtime entities in oop.
 An object has an identity, state, and behavior.
 object contains data and code to manipulate the data.
3. Data Abstraction
 Providing only essential information about the data to the outside world
 allows to focus on what an object does rather than how it does it.
 Hiding the background details or implementation.
 Example - a man driving a car.
4. Encapsulation
 Wrapping up of data AND METHOD INTO SINGLE UNIT (CALLED CLASS) is
Encapsulation.
 the mechanism that binds together the code and the data.
 the variables or data of a class are hidden from any other class and can be accessed
only through any member function of their class.
5. Inheritance
 Inheritance is an important pillar of OOP(Object-Oriented Programming).
 It is the mechanism in Java by which one class is allowed to inherit the features (fields
and methods) of another class.
 It use extends keyword.
 The capability of a class to derive properties and characteristics from another class is
called Inheritance.

6. Polymorphism:
 The word polymorphism means having many forms.
 poly (many) and morph (forms)
 one entity can take many forms.
 we can define polymorphism as the ability of a message to be displayed in more than one
form.

Dynamic Binding:
 In dynamic binding, the code to be executed in response to the function call is decided at
runtime.
 Dynamic binding means that the code associated with a given procedure call is not
known until the time of the call at run time
Message Passing:
 It is a form of communication used in object-oriented programming as well as parallel
programming.
 Objects communicate
 with one another by sending and receiving information to each other.

***********************************************************************
BENEFITS OF OOP
 OOP offers several benefits to both the program designer and the user.
1. Provides greater programmer productivity,
2. better quality of software
3. and lesser maintenance cost.
The principal advantages are:
 inheritance eliminate redundant code.
 build programs from the standard working modules that communicate with one
another.
 This leads to saving of development time and higher productivity.
 The principle of data hiding helps the programmer to build secure programs cant
viewed by other parts of the program.
 It is possible to have multiple objects to coexist without any interference.
 It is possible to map objects in the problem domain
 It is easy to partition the work in a project based on objects.
 The data-centered design approach enables us to capture more details of a model
 Object-oriented systems can be easily upgraded from small to large systems.
 Message passing techniques for communication between objects make the interface
descriptions with
 Software complexity can be easily managed.

***********************************************************************
APPLICATION OF OBJECT-ORIENTED PROGRAMMING
 OOP is one of the programming buzzwords today.
 It gain importance in many areas.
 The most popular application is area of user interface design such as windows.
 There are hundreds of windowing systems developed using OOP techniques.
 Real-business systems are often much more complex and contain many more objects
with complicated attributes and methods.
 OOP is useful in this type of applications since it is simplify a complex problem.
 The promising areas for application of OOP includes:

 Real-time systems
 Simulation and modelling
 Object-oriented databases
 Hypertext, hypermedia and expertext
 Al and expert systems
 Neural networks and parallel programming
 Decision support and office automation systems
 CIM/CAD/CAD system
 Object-oriented technology is certainly changing the way software engineers think,
analyze, design and implement systems today.

********************************************************************
JAVA EVOLUTION
HISTORY
 Developed by James Gosling and his team at Sun Microsystems in the early
1990s.
 The goal was to build a platform independent language for embedded devices
such as set-top boxes and televisions.
 The team embarked on an new project codenamed the “Green Project”.
 The project first used the name “Green” (internally “Greentalk” with
extension .gt),
 Then was renamed “Oak”
 The name “Java” (after the Indonesian coffee bean) emerged as the one that
cleared legal review.
 Gosling’s preferred name was “Lyric” and the team initially favoured “Silk,”
 Java” became the official name.
JAVA MILESTONE
1990 Sun Microsystems decided to develop a software electronic devices.
1991 The team announced a new language named "Oak",
The team, Green Project team by Sun, demonstrated the application of the
1992
new language to control a list of home appliances
. The World Wide Web (WWW) appeared on the Internet and transformed
1993
the text-based Internet into a graphical-rich environment.
1994 The team developed a Web browser called "HotJava" to locate and run applet
1995 Oak was renamed "Java", due to some legal snags.
Java established itself not only as a leader for Internet programming but also
1996
as a general-purpose, object-oriented programming language.
1997 Sun releases Java Development Kit 1.1 (JDK 1.1).
Sun relases the Java 2 with version 1.2 of the Software Development Kit
1998
(SDK 1.2).
Sun releases Java 2 Platform, Standard Edition (J2SE) and Enterprise Edition
1999
(J2EE).
2000 J2SE with SDK 1.3 was released.
2002 J2SE with SDK 1.4 was released.
J2SE with JDK 5.0 (instead of JDK 1.5) was released. This is known as J2SE
2004
5.0

***************************************************************************
JAVA FEATURES
Java2 Features
 Compiled and Interpreted
Java compiler translatye sou
 Platform-Independent and Portable
 Object-Oriented
 Robust and Secure
 Distributed
 Familiar, Simple and Small
 Multithreaded and Interactive
 High Performance
 Dynamic and Extensible

Additional Features of J2SE 5.0


 Ease of Development
 Scalability and Performance
 Monitoring and Manageability
 Desktop Client
 Core XML Support
 Supplementary character support
 JDBCRowSet

HOW JAVA DIFFERS FROM C AND C++


 Java was modelled after C and C++ languages, has differs from C and C++
 Java does not incorporate a number of features available in C and C++.
JAVA AND C
 Java is a lot like C but the major difference between Java and C
 Java is an object-oriented language and has mechanism to define classes
and objects.
 It build a simple and safe language, the Java team did not include some of
the C features in Java.
Does Not
 Java does not have unique statement keywords sizeof, and typedef.
 Java does not contain the data types struct and union.
 Java does not define the type modifiers keywords auto, extern, register,
signed, and unsigned.
 Java does not support an explicit pointer type.
 Java does not have a preprocessor and therefore we cannot use # define, #
include, and # ifdef statements.
 Java requires that the functions with no arguments must be declared with
empty parenthesis and not with the void keyword as done in C

Does
 Java adds new operators such as instanceof and >>>.
 Java adds labelled break and continue statements.
 Java adds many features required for object-oriented programming.

JAVA AND C++


 Java is a true object-oriented language while C++ is basically C with object-
oriented extension.
 That is what exactly the increment operator ++ indicates. C++ has maintained
backward compatibility with C.
 It is therefore possible to write an old style C program and run it successfully
under C++, Java appears to be similar to C++ when we consider only the
"extension" part of C++.
 However, some object-oriented features of C++ make the C++ code extremely
difficult to follow and maintain.

Listed below are some major C++ features that were intentionally
 Java does not support operator overloading.
 Java does not have template classes as in C++.
 Java does not support multiple inheritance of using a new classes.
 Java does not support global variables. Java does not use pointers.
 Java has replaced the destructor function with a finalize() function.
 There are no header files in Java.
JAVA AND INTERNET
 Java and Internet Java is strongly associated with the Internet because the first
application program written in Java was HotJava,a browser to run the applet on
Internet .
 So the Internet users use the Java to create the applet programs and run them locally
using a 'Java-enabled browsers' like HotJava..
 Java is a platform-independent, object-oriented programming language (OOP).
 It is not to be confused with JavaScript, a scripting language used to create dynamic
web pages.
 Due to its reliability

JAVA AND WWW


 World Wide Web is an open-ended information retrieval system designed to be used in
the Internet’s distributed environment.
 It contains Web Pages that provides both information and controls.
 we are guided through a particular direction using a decision tree structure.
 It use language called Hypertext Markup Language (HTML).
 Web pages contain HTML tags that enable us to find, retrieve, manipulate, and display
documents worldwide.
 Java was meant to be used in distributed environments such as Internet.
 could be easily incorporated into the Web system. Before Java, the World Wide Web was
limited to the display of still images .
 it capable of supporting animation, graphics, games, and a wide range of special effects.
 we can run Java program on someone else’s computer access from the Internet.
 Java communicates with a Web page through a special tag called <APPLET>.

The figure shows the following communication steps:


 The user sends a request for an HTML document to the remote computer's Web
server.
 The server is a program that accepts a request, processes the request, and sends
the required document
 The H'TML document is returned to the user's [Link] document contains
the APPLET tag, which identifies the applet.
 The corresponding applet bytecode is transferred to the user's computer.
 This bytecode had been previously created by the Java compiler using the Java
source code file for that applet.
 The Java-enabled browser on the user's computer interprets the bytecodes and
provides output.
 The user may have further interaction with the applet but with no further
downloading from the provider's Web server.
 This is because the bytecode contains all the information necessary to interpret
the applet.
WEB BROWSERS
 The Internet is a vast sea of data represented in many formats and stored on many
hosts.
 A large portion of the Internet is organized as the World Wide Web (WWW) which
uses hypertext to make navigation easier than the traditional ways
1. Hotlava
2. Netscape Navigator
3. Internet Explorer

1. HotJava
Hotlava is the Web browser from Sun Microsystems that enables the display of
interactive content on the Web, using the Java language,. When the Java language was first
developed and ported to the Internet, no browsers were available that could run Java applets..
Hotlava is currently available for the SPARC/Solaris platform as well as Windows 95, Windows
NT and Windows XP. Its biggest draw is that it was the first Web browser to provide support for
the Java language, thus making the Web more dynamic and interactive.
[Link] Navigator
Netscape Navigator, from Netscape Communications Corporation, is a general-purpose
browser, that can run Java applets)
Netscape Navigator has many useful features such as visual display about downloading
process and indication of the number bytes downloaded. It also supports JavaScript, a scripting
language used in HTML documents
[Link] Explorer
Internet Explorer is another popular browser developed by Microsoft for
Windows 95, NT and XP Workstations. Both the Navigator and Explorer use tool bars, icons,
menus and dialog boxes for easy navigation. Explorer uses a just-in-time (JIT) compiler which
greatly increases the speed of execution.

****************************************************************************

OVERVIEW OF JAVA
Two types of java programs are available
[Link] alone applications
[Link] applets
To execute
[Link] source code into byte code using javac compiler
[Link] the byte code program using java interpreter.
SIMPLE JAVA PROGRAM

class HelloWorld
{
public static void main(String[] args)
{
[Link]("Hello, World!");
}
}

class Declaration
class SampleOne Declares a class, which is an object-oriented construct. As stated
earlier, Java is a true object-oriented language and therefore, everything must be placed inside a
class.
Opening Brace
Every class definition in Java begins with an opening brace "[" and ends with a matching
closing brace"}", appearing in the last line in the example.
The Main Line
public static void main(String argal 1)
defines a method named main. Conceptually, this is similar to the main() function in
C/C++, Every Java application program must include the main() method. This is the starting
point for the interpreter to begin the execution of the program
This line contains a number of keywords, public, static and void.

Public: public is an access specifier that declares the main method as unprotected and
therefore making it accessible to all other classes. This is similar to the C++ public modifier.

Static: Next appears the keyword static, which declares this method as one that belongs
to the entire class and not a part of any objects of the class. The main must always be declared an
static
Void: The type modifier void states that the main method does not return any value (but
simply prints some text to the screen.)

The Output Line


The only executable statement in the program is System, [Link] ("Java is better than
C++.");
Since Java is a true object riented language, every method must be part of an object.
The print in method is a member of the out object, which is a static data member of
System class. This line prints the string Java is better than C++.
STRUCTURE OF JAVA PROGRAM

 Documentation Section (Optional): This section includes comments that provide


information about the program, such as the author, date, purpose, and any relevant
details. Comments are ignored by the compiler.
 Package Declaration (Optional): This statement defines the package to which
the current class belongs. It helps organize classes and prevent naming
conflicts. There can be only one package declaration per file, and it must be the
first non-comment line.
 Import Statements (Optional): These statements are used to import classes
or entire packages from other libraries or parts of your project, making them
accessible in the current file.
 Interface Section (Optional): This section defines interfaces, which are
blueprints of classes. An interface can contain abstract methods and constants
 .Class Definition: This is the core of a Java program. Every Java program
must contain at least one class. Classes encapsulate data (fields) and behavior
(methods) into a single unit.
 Main Method: For a standalone Java application, the main method serves as
the entry point for program execution. The Java Virtual Machine (JVM) starts
executing code from this method.
**********************************************************************************************
JAVA TOKENS

You might also like