0 ratings 0% found this document useful (0 votes) 13 views 290 pages Core Java
The document outlines the new syllabus for Core Java under the CBCS pattern for B.B.A.(C.A) Semester V, effective from June 2021. It includes topics such as Java fundamentals, classes, inheritance, file handling, and GUI programming with AWT and Swing. The book aims to present the subject matter in a concise and accessible manner to enhance understanding and vocabulary in technical terms.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content,
claim it here .
Available Formats
Download as PDF or read online on Scribd
Go to previous items Go to next items
NEW SYLLABUS
CBCS PATTERN
Core Java
Dr. Ms. Manisha Bharambe
Mrs. Manisha Suryawanshi
Kamil Ajmal Khan
pee
Ceeyllaus
gppu Hews A Book OF
Core Java
For B.B.A.(C.A) : Semester - V
[Course Code CA-503 : Credits-03]
Cie
As Per New Syllabus, Effective from June 2021
Dr. Ms. Manisha Bharambe
[Link]. (Comp. Sci), [Link], Ph.D (Comp. Sci.)
Vice Principal and BCA Coordinator
MES Abasaheb Garware College, Pune 4
Mrs. Manisha Suryawanshi
[Link]., MPhil. (CS), M'B.A, (HR)
Asst. Prof., Placement Co-ordinator
Modern College of arts, Science and Commerce
(Autonomous), Pune 5
Mr. Kamil Ajmal Khan
se, computer scence
ss, Prof, Computer Scene Department
‘Abedainemder Serior College, Pune
Price = 290.00
NIRALI
PRAKASHAN
PUERTO
N4959]CORE JAVA ISBN 978-93-5451-305-3
Edition: September 2021
© ‘Authors
The text ofthis publication, oF any part thertot should not be reproduced or transmitted in any form or stored in any
‘computer storage system or device for distibution incuding photocopy, recording, taping or infxmation retrieval system or
reproduced on any dis tpe pefereted media or ether Ifermation stomnge device ete without tre written permicion of
‘Authors wth whom the rights ae reserved Breach ofthis eanlton i able fe legal action
Every efor has been mae to avoid errors or omissions in tis publication. In spite ofthis eros may have crept in. Any
mistake, erororcscrepancy so nated and shall be brought to our noice shal be taken care af in the nxt edition. tis notified
that neither the publisher nar the authors or sll shall be respansibe for any damage or loss of action'o any one, of any kind in
‘any manner, therefiom. The reader must cross check all the facts and contents with original Goverment notification or
publietions
Published By : Polyplate Printed By :
NIRALI PRAKASHAN YOGIRAJ PRINTERS AND BINDERS
‘Abhyudaya Pragati, 1312 Shivaji Nagar, ‘Survey No, 10/1A, Ghule Industrial Estate
(Off JM, Road, Pune ~ 421005 Nanded Gaon Road
Tel - (020) 25512336/37/39 Nanded, Pune - 411041
Email nialipune@ pragntionlinecom
OS kena
PUNE
Nirali Prakashan Nirali Prakashan
(For erders outside Pune) (For orders within Pune)
[Link], 28/27, Dhayiri Narhe Road, Near Asian College 119, Budhwar Peth Jogeshwai Mandir Lane
Pune $11041, Maharashtra Pune 411002, Maharashtra
Tel: (020) 24690204; Motil 9657703143 Tel: (020) 2448 2044; Mabie 9657702145
Email: bockorder@ [Link] Email: iralilocal@[Link]
MUMBAI
Nirali Prakashan
Rasdhara Co-op. Heg Seciety Lid, 0’ Wing Ground Floor, 385 SMP. Roas
GGirgaum, Mumbai 400004, Maharashtra
Mobile 7045821020, Tel (022) 2385 6339 / 2386 9976
Email: iralimumbaidpragetionine com
Seem enn ss
DELHI BENGALURU
Nirali Prakashan Nirali Prakashan Nirali Prakashan
Room No. 2 Ground Floor Maiti Ground Floor, Jaya Aparments, | Above Maratha Mandi, Shop No.3,
4575/15 Omar Tower, Agarwal Road No. 93, 6 Cross, 6” Main, First Floor, Ran hanshi Square,
Darya Gary, New Delhi 110002 Mateswaram, Bengaluru 560003 | Sitabuldi Nagpur 440012 (MAH)
Mobile :9555778814/9818561840 Karmataka; Mob : 9686821074 Tel: (712) 254 7129
Emall-delhi@niraibookscom | mai: bengaluru@niraibookscom | Email: nagpur@niralibookscom
KOLHAPUR JALGAON ‘SOLAPUR
Nirali Prakeshan Nirali Prakashan Nirali Prakashan
"New Mahadvar Roaé, Kedar Plaza, | 34,[Link] Matket, NaviPeth, | R-158/2, Avanti Nagar, Near Golden
1" Flor Opp. It Bank Jalgaon 425001, Maharashira ‘Gate, Pune Naka Chowk
Kolhapur 416 012 Maharashtra Tel: (0257) 222 0395 Solapur 413001, Maharashtra
Mob : 985006155 Mob : 94234 91860 ‘Mobile 9890918587
Email: kolhapur@nilibookscom | Email-jalgaon@niralibookscom | Email: solapur@niralibooks com
SP
e
inecom_|_ www [Link]]
yePreface...
We take an opportunity to present this book entitled as “Core Java” to the students of
Fifth Semester - 8B.A.(CA). The object of this book is to present the subject matter in a most
concise and simple manner. The book is written strictly according to the New Syllabus
(CBCS Pattern)
The book covers theory of Java Fundamentals, Classes, Objects and Methods, Inheritance,
Package and Collection, File and Exception Handling, Applet, AWT, Event and Swing
Programming,
The book has its own unique features. It brings out the subject in a very simple and lucid
manner for easy and comprehensive understanding of the basic concepts, its intricacies,
procedures and practices. This book will help the readers to have a broader view on Core
Java. The language used in this book is easy and will help students to improve their
vocabulary of Technical terms and understand the matter in a better and happier way.
A special words of thank to Shri, Dineshbhai Ful
, Mr. Jignesh Furia for showing full faith
in us to write this text book. We also thank to Mr. Akbar Shaikh of M/s Nirali Prakashan for
their excellent co-operation,
We also thank Mr. Akbar Shaikh, Ms, Chaitali Takale, Mr. Ravindra Welodare, Mr. Sachin
Shinde, Mr. Ashok Bodke, Mr. Moshin Sayyed and Mr. Nitin Thorat.
Although every care has been taken to check mistakes and misprints, any errors,
‘omission and suggestions from teachers and students for the improvement of this text book
shall be most welcome,
AuthorsSyllabus ...
1.
3.
Java Fundamentals [Lectures 8]
1
12
13
14
1s
16
wy
18
Introduction to Java
Basics of Java: Data Types, Variable, Expression, Operators, Constant
Structure of Java Program
Execution Process of Java Program
JDK Tools
Command Line Arguments
Array and String
17.1 Single Array and Multidimensional Array
17.2 String, String Buffer
Built In Packages and Classes
1.8.1 javautit Scanner, Date, Math etc.
182 javalang
Classes, Objects and Methods [Lectures 8]
21
22
23
24
25
26
Class and Object
Object Reference
Constructor: Constructor Overloading
Method: Method Overloading, Recursion, Passing and Returning Object Form
Method
New Operator, this and static keyword, finalize) Method
Nested Class, Inner Class and Anonymous Inner Class
Inheritance, Package and Collection [Lectures 10]
BL
32
33
34
35
36
37
38
39
3.10
Bal
312
3.13
Overview of Inheritance
Inheritance in Constructor
Inheriting Data Members end Methods
Multilevel Inheritance - Method Overriding Handle Multilevel Constructors
Use of Super and Final Keyword
Interface
Creation and Implementation of an Interface, Interface Reference
Interface Inheritance
Dynamic Method Dispatch
Abstract Class
Comparison between Abstract Class and Interface
Access Control
Packages
3.13.1 Packages Concept
3.13.2 Creating User Defined Packages
3.13.3 Java Built Inpackages
3.134 Import Statement, Static Import3.14 Collection
3.14.1 Collection Framework.
3.142 Interfaces: Collection, List, Set
3.143 Navigation: Enumeration, Iterator, Listiterator
3.144 Classes: Linkedlist, ArrayList, Vector, HashSet
File and Exception Handling [Lectures 8]
Exception
41 Exception and Error
42. Use of try, catch, throw, throws and finally
43 Built in Exception
44 Custom exception
45 Throwable Class.
File Handling
46 Overview of Different Stream (Byte Stream, Character stream)
47 Readers and Writers class
48 File Class
49 File Input Stream, File Output Stream
4.10 Input Stream Reader and Output Stream Writer
Class
4.11 FileReader and FileWriter Class
4.12 Buffered Reader Class
Applet, AWT, Event and Swing Programming [Lectures 14]
Applet
5.1 Introduction
5.2. Types Applet
53. Applet Lifecycle
5.3.1 Creating Applet
53.2 Applet Tag
54 Applet Classes
541 Color
5.42 Graphics
543. Font
AWT
5.5 Components and container used in AWT
5.6 Layout Managers
5.7 Listeners and Adapter Classes
5.8 Event Delegation Model
Swing
5.9 Introduction to Swing Component and Container Classes
5.10 Exploring Swing Controls - JLabel and Image Icon, JText Field, The Swing Buttons
JButton, JToggle Button, Check Box, JRadio Button, JTabbed Pane, JScroll Pane,
Jlist, JTable, ComboBox, Swing Menus, Dialogs, JFileOpen, JColorChooser
a.Contents ...
4. Java Fundamentals
2. Classes, Objects and Methods
3. Inheritance, Package and Collection
4. File and Exception Handling
5. Applet, AWT, Event and Swing Programming
Bibliography
44 - 1.50
2A = 2.32
3.4 - 3.72
44 - 4.40
54 - 5.88
BA-B.4Java Fundamentals
Learning Objectives...
To understand Basic Concepts of Java
To learn Structure of Java
=) To study JDK Tools.
To study Command Line Arguments.
To learn about Array and String.
To study Built In Packages and Classes,
Pi wopucine java
Java is a class-based, object-oriented, simple programming language. Java makes
writing, compiling, and debugging programming easy. It helps to create reusable
code and modular programs.
Java is used for Mobile applications, Desktop applications, Web applications, Web
servers and Application servers, Games, Database connection, etc.
Java works on different platforms like Windows, Mac, Linux, Raspberry Pi, ete.
Java is related to C++, which is a direct descendant of C. Much of the character of Java
is inherited from these two languages. From C, Java derives its syntax. Many of Java's
object-oriented features were influenced by C++.
Itis a general-purpose programming language, intended to let application developers
write once, run anywhere. Meaning that compiled Java code can run on all platforms
that support Java without the need for recompilation. Java applications are typically
compiled to bytecode that can run on any Java virtual machine (JVM)
Java enables computer programmers to write computer instructions using English
based commands, instead of having to write in numeric codes,
Like English language, Java has a set of rules (syntax) that determine how the
instructions are written. Once, a program has been written, the high-level
instructions are translated into numeric codes that computers can understand and
execute,
(ay«
Java [BBA(CA): Ser. V] 42 Java Fundamentals
History of Java
Java was developed at Sun Microsystems (which has since been acquired by Oracle) in
1991, by a team of James Gosling, Patrick Naughton, Chris Wrath, Ed Frank and Mike
Sheridan as its members. The language was initially called Oak. It was later termed as
Java.
+ Between the initial implementation of Oak in the fall of 1992 and the public
announcement of Java in the spring of 1995, many more people contributed to the
design and evolution of the language. Bill Joy, Arthur van Hoff, Jonathan Payne,
Frank Yellin, and Tim Lind holm were key contributors to the maturing of the original
prototype.
+ Java is a general-purpose, Object-Oriented Programming (OOP) language. James
Gosling is called the father of Java Programming.
‘+ Java is an Object-Oriented Programming language means Java enables us not only to
organize our program code into logical unit called objects but also to take advantage
of encapsulation, inheritance, polymorphism and so on.
‘+ As of March 2021, the latest version is Java 16, with Java 11, a currently supported
long-term support (LTS) version, released on September 25, 2018. Oracle released the
last zero-cost public update for the legacy version Java 8 LTS in January 2019 for
commercial use, although it will otherwise still support Java 8 with public updates for
personal use indefinitely. Other vendors have begun to offer zero-cost builds of
OpenjDK 8 and 11 that are still receiving security and other upgrades.
‘+ Oracle (and others) highly recommend uninstalling outdated versions of Java because
of serious risks due to unresolved security issues. Since Java 9, 10, 12, 13, 14, and 15
are no longer supported, Oracle advises its users to immediately transition to the
latest version (currently Java 16) or an LTS release.
‘+ An application is a type of software that allows user to perform specific task. Sun
Microsystems Inc, has divided Java into following parts:
1. Java SE (Java Standard Edition): It contains basic core Java classes and used to
develop standard applets and applications.
2. J2EE (Java Enterprise Edition): It contains classes that are beyond Java SE and used
to providing business solutions on a network.
3. J2ME (Java Micro Edition): Java ME is for developers who develop code for portable
devices like a PDA, a cellular phone and so on.
FRE] Features of Java
‘+ Following are list of buzzwords:
1. Simple: Java is a simple language. There are various concepts that makes the Java
as a simple language. Java is designed to be easy to learn. Programs in Java are
easy to write and debug because Java does not use the pointers, preprocessor
header files, operator overloading etc.
2. Secure: Java is aimed to be used in networked or distributed environments. Java
does not allocate direct pointer to memory, this makes it impossible to
accidentally reference memory that belongs to other program.Core Java [BBA(CA): Sem. V) 43 Java Fundamentals
3.
4.
6.
10.
1.
Portable: Being architectural-neutral and having no implementation dependent
aspects of the specification makes Java portable. Java code is portable. It was an
important design goal of Java that it be portable so that as new architectures (due
to hardware, operating system, or both) are developed, the Java environment
could be ported to them.
Object-oriented: Java is a truly object oriented language. Almost everything in
java is an object. Java has a wide variety of classes. These classes are organized in
various packages. We can use them in our programs while implementing
inheritance. The object model in java is simpleand easy to extend,
Robust: Java is a robust language because it provides many safeguards to ensure
reliable code. Java does not allow pointer which avoids security problem. There is
no concept of reference variable. This eliminates the possibility of overwriting
memory and corrupting data, Automatic garbage collection eliminates memory
leaks.
Multithreaded: Java was designed to meet the real-world requirement of creating.
interactive, networked programs. To accomplish this, Java supports
multithreaded programming, which allows you to write programs that do many
things simultaneously. The Java run-time system comes with an elegant yet
sophisticated solution for multi-process synchronization that enables you to
construct smoothly running interactive systems.
Architecture-neutral: A central issue for the Java designers was that of code
longevity and portability. One of the main problems facing programmers is that
no guarantee exists that if you write a program today, it will run tomorrow even.
on the same machine. Operating system upgrades, processor upgrades, and
changes in core system resources can all combine to make a program
malfunction. Their goal was “write once; run anywhere, anytime, forever.” To a
great extent, this goal was accomplished.
Interpreted: As described earlier, Java enables the creation of cross-platform
programs by compiling into an intermediate representation called Java bytecode.
Most previous attempts at cross-platform solutions have done so at the expense of
performance.
High Performance: The Java bytecode was carefully designed so that it would be
easy to translate directly into native machine code for very high performance by
using a just-in-time compiler.
Distributed: Java facilitates the building of distributed application by a collection
of classes for use in networked applications. Java is designed for the distributed
environment of the Internet
Dynamic: Java language is capable of dynamically linking in new class librarie
methods and objects. Because Java is interpreted, Java is an extremely dynamic
language, at runtime, the Java environment can extends itself by linking in
classes that may be located on remote servers on a network, for example, the
Internet.sA(CA): Sem. VI. a dave Fundamentals
OPERATORS, CONSTANT
Bass OF JAVA - DATA TYPES, VARIABLE, EXPRESSION,
FEB vaca ps
‘A computer has to process various types of data. Data type is a term that refers to the
kind of data used in a program. Every programming language comes with a set of
data types ready to use.
‘+ Java is a strongly typed language and this means that every variable and every
expression has a data type known at compile time.
1, The Primitive Types:
* Various primitive data types are listed below:
(i) byte:
Byte data type is an 8-bit signed two's complement integer.
Rangeis -128 to 127.
Default value is 0.
Byte data type is used to save space in large arrays, mainly in place of integers,
since a byte is four times smaller than an int.
Example: byte a = 100, byte b = 50
(ii) short:
Short data type is a 16-bit signed two's complement integer.
Minimum value is -32,768 and maximum value is 32,767.
Short data type can also be used to save memory as byte data type. A short is 2
times smaller than an int.
Default value is 0,
Example: short s = 10000, short r= - 20000
(iii) int:
int data type is a 32-bit signed two's complement integer.
Rangeis - 2,147,483,648.. to 2,147,483,647.
int is generally used as the default data type for integral values unless there is
aconcern about memory.
The default value is 0.
Example: int a = 100000, int b = -200000
(iv) long:
long data type is a 64-bit signed two's complement integer.
Rangeis -9,223,372,036,854,775,808... to 9,223,372,036 854,775,807.
This type is used when a wider range than int is needed.
Default value is OL.
Example: long a = 1000001, int b = -200000L.