




















































Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!





















































Fundamentals of Object-Oriented Programming: Object-Oriented Paradigm – Basic Concepts of Object-Oriented Programming – Benefits of Object-Oriented Programming – Application of Object- Oriented Programming. Java Evolution: History – Features – How Java differs from C and C++ – Java and Internet – Java and www – Web Browsers. Overview of Java: simple Java program – Structure – Java Tokens – Statements – Java Virtual Machine.
UNIT-II:
Constants, Variables, Data Types - Operators and Expressions – Decision Making and Branching: if, if ..else, nested if, switch,? : Operator - Decision Making and Looping: while, do, for – Jumps in Loops - Labeled Loops – Classes, Objects and Methods.
UNIT-III:
Arrays, Strings and Vectors – Interfaces: Multiple Inheritance – Packages: Putting Classes together – Multithreaded Programming.
UNIT-IV:
Managing Errors and Exceptions – Applet Programming – Graphics Programming.
UNIT-V:
Managing Input / Output Files in Java : Concepts of Streams- Stream Classes – Byte Stream classes – Character stream classes – Using streams – I/O Classes – File Class – I/O exceptions – Creation of files – Reading / Writing characters, Byte-Handling Primitive data Types – Random Access Files.
Objects are basic run-time entities in an object oriented system, objects are instances of a class these are defined user defined data types. They may represent a person, a place, a bank account, a table of data or any item that the program has to handle. They may also represent user-defined data such as vectors, time and lists. When a program is executed, the objects interact by sending messages to one another. For example, if “customer” and “account” are to object in a program, then the customer object may send a message to the count object requesting for the bank balance.
Each object contain data, and code to manipulate data. Objects can interact without having to know details of each other’s data or code. It is a sufficient to know the type of message accepted, and the type of response returned by the objects.
The entire set of data and code of an object can be made a user-defined data type with the help of class. Objects are variables of the type class. Once a class has been defined, we can create any number of objects belonging to that class. For examples, Mango, Apple and orange members of class fruit. Classes are user-defined that types and behave like the built-in types of a programming language.
If fruit has been defines as a class, then the statement Fruit Mango; Will create an object mango belonging to the class fruit.
The wrapping up of data and function into a single unit (called class) is known as encapsulation. Data and encapsulation is the most striking feature of a class. The data is not accessible to the outside world, and only those functions which are wrapped in the class can access it. This insulation of the data from direct access by the program is called data hiding or information hiding. Abstraction refers to the act of representing essential features without including the background details or explanation.
Inheritance is the process by which objects of one class acquire the properties of objects of another class. It supports the concept of hierarchical classification. Inheritance provides reusability. This means that we can add additional features to an existing class without modifying it. For example, the car, is a part of the class ‘Automobiles’ which is again a part of the class ‘Vehicles’.
Binding refers to the linking of a procedure call to the code to be executed in response to the call. Dynamic binding means that the code associated with a given procedure call is not known until the time of the call at run time. It is associated with polymorphism and inheritance. Consider the procedure “draw” in above figure by inheritance, every object will have this procedure. Its algorithm is, however, unique to each object and so the draw procedure will be redefined in each class that defines the object.
An object-oriented program consists of a set of objects that communicate with each other. The process of programming in an object-oriented language, involves the following basic steps: o Creating classes that define object and their behavior o Creating objects from class definitions o Establishing communication among objects.
way as people pass messages to one another. A Message for an object is a request for execution of a procedure, and therefore will invoke a function (procedure) in the receiving object that generates the desired results. Message passing involves specifying the name of object, the name of the function (message) and the information to be sent. Example:
It is easy to model a real system as real objects are represented by programming objects in OOP. The objects are processed by their member data and functions. It is easy to analyze the user requirements. With the help of inheritance, we can reuse the existing class to derive a new class such that the redundant code is eliminated and the use of existing class is extended. This saves time and cost of program. In OOP, data can be made private to a class such that only member functions of the class can access the data. This principle of data hiding helps the programmer to build a secure program that can not be invaded by code in other part of the program. With the help of polymorphism, the same function or same operator can be used for different purposes. This helps to manage software complexity easily. Large problems can be reduced to smaller and more manageable problems. It is easy to partition the work in a project based on objects. It is possible to have multiple instances of an object to co-exist without any interference i.e. each object has its own separate member data and function.
Desktop Applications such as acrobat reader, media player, antivirus etc. Web Applications such as irctc.co.in, javatpoint.com etc. Enterprise Applications such as banking applications. Mobile Embedded System Smart Card Robotics Games etc. User interface design such as windows, menu ,… Real Time Systems Simulation and Modeling
Java is an object-oriented programming language developed by James Gosling and colleagues at Sun Microsystems in the early 1990s. Java is intended to be compiled to a bytecode, which is then run (generally using JIT compilation) by a Java Virtual Machine. Java was started as a project called "Oak" by James Gosling in June 1991. James Gosling , Mike Sheridan , and Patrick Naughton initiated the Java language project in June 1991. The small team of sun engineers called Green Team. Originally designed for small, embedded systems in electronic appliances like set-top boxes. Firstly, it was called "Greentalk" by James Gosling and file extension was .gt. After that, it was called Oak and was developed as a part of the Green project. Why "Oak" name - Oak is a symbol of strength and chosen as a national tree of many countries like U.S.A., France, Germany, Romania etc. (Oak Tree) Why "Java" name - The team gathered to choose a new name. The suggested words were "dynamic", "revolutionary", "Silk", "jolt", "DNA" etc. They wanted something that reflected the essence of the technology: revolutionary, dynamic, lively, cool, unique, and easy to spell and fun to say. According to James Gosling "Java was one of the top choices along with Silk". Since java was so unique, most of the team members preferred java. Java is an island of Indonesia where first coffee was produced (called java coffee). Originally developed by James Gosling at Sun Microsystems (which is now a subsidiary of Oracle Corporation) and released in 1995. In 1995, Time magazine called Java one of the Ten Best Products of 1995. JDK 1.0 released in(January 23, 1996).
There are many java versions that has been released. Current stable release of Java is Java SE 8. JDK Alpha and Beta (1995)
JDK 1.0 (23rd Jan, 1996) JDK 1.1 (19th Feb, 1997) J2SE 1.2 (8th Dec, 1998) J2SE 1.3 (8th May, 2000) J2SE 1.4 (6th Feb, 2002) J2SE 5.0 (30th Sep, 2004) Java SE 6 (11th Dec, 2006) Java SE 7 (28th July, 2011) Java SE 8 (18th March, 2014)
According to Sun, Java language is simple because Syntax is based on C++ (so easier for programmers to learn it after C++). Removed many confusing and/or rarely-used features e.g., explicit pointers, operator overloading etc. No need to remove unreferenced objects because there is Automatic Garbage Collection in java
platform-independent code because it can be run on multiple platforms i.e. Write Once and Run anywhere (WORA)
Java is secured because: No explicit pointer Java Programs run inside virtual machine sandbox
Class loader : Adds security by separating the package for the classes of the local file system from those that are imported from network sources. Byte code Verifier : Checks the code fragments for illegal code that can violate access right to objects. Security Manager : Determines what resources a class can access such as reading and writing to the local disk.
Robust simply means strong. Java uses strong memory management. There are lack of pointers that avoids security problem. There is automatic garbage collection in java. There is exception handling and type checking mechanism in java. All these points makes java robust.
We may carry the java bytecode to any platform.
Java is faster than traditional interpretation since byte code is "close" to native code still somewhat slower than a compiled language (e.g., C++)
We can create distributed applications in java. RMI and EJB are used for creating distributed applications. We may access files by calling the methods from any machine on the internet.
A thread is like a separate program, executing concurrently. We can write Java programs that deal with many tasks at once by defining multiple threads. The main advantage of multi-threading is that it doesn't occupy memory for each thread. It shares a common memory area. Threads are important for multi-media, Web applications etc.
Java and Internet: Java is strongly associated with the Internet. Internet users can use Java to create applet programs and run them locally using a "Java-enabled browser" such as HotJava. They can also use a Java-enabled browser to download an applet located on a computer anywhere in the Internet and run it on his local computer. In fact, Java applets have made the Internet a true extension of the storage system of the local computer. Java and World Wide Web: World Wide Web (WWW) is an open- ended information retrieval system designed to be used in the Internet's distributed environment. This system contains Web pages that provide both information and controls. Web system is open-ended and we can navigate to a new document in any direction. This is made possible with the help of a 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. Since, both the Web and Java share the same philosophy, Java could be easily incorporated into the Web system. Before Java, the World Wide Web was limited to the display of still images and texts. However, the incorporation of Java into Web pages has made it capable of supporting animation, graphics, games, and a wide range of special effects. Web browsers Internet explorer HotJava Netscape navigator Firefox Google chrome
How do I enable Java in my web browser? Internet Explorer Click Tools and then Internet Options Select the Security tab, and select the Custom Level button Scroll down to Scripting of Java applets Make sure the Enable radio button is checked Click OK to save your preference
Firefox Open the Firefox browser or restart it, if it is already running From the Firefox menu, select Tools, then click the Add-ons option In the Add-ons Manager window, select Plugins Click Java (TM) Platform plugin (Windows) or Java Applet Plug-in (Mac OS X) to select it Check that the option selected is Ask to Activate or Always Activate or on older Firefox versions, click on the Enable button (if the button says Disable, Java is already enabled)
By changing sequence of the modifiers, method prototype is not changed.
Subscript notation in java array can be used after type, before variable or after variable.
You can provide var-args support to main method by passing 3 ellipses (dots)
Having semicolon at the end of class in java is optional.
Documentation Section Suggested Package Statement Optional Import Statements Optional Interface Statement Optional Class Definition Optional Main Method Class { Main Method Definition }
Essential
A Java program consists of different sections. Some of them are mandatory but some are optional. The optional section can be excluded from the program depending upon the requirements of the programmer. The file naming conversion in the java programming is that which-ever class is containing main() method, that class name must be given as a file name with an extension .java.
It includes the comments that improve the readability of the program. A comment is a non-executable statement that helps to read and understand a program especially when your programs get more complex. It is simply a message that exists only for the programmer and is ignored by the compiler. A good program should include comments that describe the purpose of the program, author name, date and time of program creation. This section is optional and comments may appear anywhere in the program.
Java programming language supports three types of comments.
Single line (or end-of line) comment : It starts with a double slash symbol (//) and terminates at the end of the current line. The compiler ignores everything from // to the end of the line. For example: