SYLLABUS JAVA PROGRAMMING
Paper Code: ETCS-307 L T/P C
Paper: Java Programming 3 1 4
INSTRUCTIONS TO PAPER SETTERS: MAXIMUM MARKS: 75
1. Question No. 1 should be compulsory and cover the entire syllabus. This question should have objective or short answer type
questions. It should be of 25 marks.
2. Apart from Question No. 1, rest of the paper shall consist of four units as per the syllabus. Every unit should have two questions.
However, student may be asked to attempt only 1 question from each unit. Each question should be of 12.5 marks
Objective: To learn object oriented concepts and enhancing programming skills.
UNIT I
Overview and characteristics of Java, Java program Compilation and Execution Process Organization of the Java Virtual Machine,
JVM as an interpreter and emulator, Instruction Set, class File Format, Verification, Class Area, Java Stack, Heap, Garbage Collection.
Security Promises of the JVM, Security Architecture and Security Policy. Class loaders and security aspects, sandbox model
[T1,R2][No. of Hrs.: 11]
UNIT II
Java Fundamentals, Data Types & Literals Variables, Wrapper Classes, Arrays, Arithmetic Operators, Logical Operators, Control of
Flow, Classes and Instances, Class Member Modifiers Anonymous Inner Class Interfaces and Abstract Classes, inheritance, throw and
throws clauses, user defined Exceptions, The String Buffer Class, tokenizer, applets, Life cycle of applet and Security concerns.
[T1,T2][No. of Hrs.: 12]
UNIT III
Threads: Creating Threads, Thread Priority, Blocked States, Extending Thread Class, Runnable Interface, Starting Threads, Thread
Synchronization, Synchronize Threads, Sync Code Block, Overriding Synced Methods, Thread Communication, wait, notify and notify
all.AWT Components, Component Class, Container Class, Layout Manager Interface Default Layouts, Insets and Dimensions, Border
Layout, Flow Layout, Grid Layout, Card Layout Grid Bag Layout AWT Events, Event Models, Listeners, Class Listener, Adapters,
Action Event Methods Focus Event Key Event, Mouse Events, Window Event
[T2][No. of Hrs.: 11]
UNIT IV
Input/Output Stream, Stream Filters, Buffered Streams, Data input and Output Stream, Print Stream Random Access File, JDBC
(Database connectivity with MS-Access, Oracle, MS-SQL Server), Object serialization, Sockets, development of client Server
applications, design of multithreaded server. Remote Method invocation, Java Native interfaces, Development of a JNI based
application. Collection API Interfaces, Vector, stack, Hashtable classes, enumerations, set, List, Map, Iterators. [T1][R1][No. of Hrs.:
10]
Text Books:
[T1] Patrick Naughton and Herbertz Schidt, “Java-2 the complete Reference”,TMH
[T2] Sierra & bates, “Head First Java”, O’Reilly
Reference Books:
[R1] E. Balaguruswamy, “Programming with Java”, TMH
[R2] Horstmann, “Computing Concepts with Java 2 Essentials”, John Wiley.
[R3] Decker & Hirshfield, “Programming.Java”, Vikas Publication.
Introduction to Java
Java is a programming language created in 1995 in Sun Microsystem by James Gosling.
Later, Sun Microsystem was acquired by Oracle in 2010. Since then, its a Oracle product.
Java is everywhere:
1. Java resides in mobile phones, client machines, server machines, embedded services,
smart phones, cloud etc
2. It shares the same basic language features and libraries.
3. Principle of JAVA: Write Once, Run Anywhere (WORA)
Library?
It is a collection of pre defined classes. You can use these library either by inheriting them or
instantiating them.
Java Editions
JAVA SE (STANDARD EDITION; CORE JAVA)
JAVA EE (ENTERPRISE EDITION: ADVANCE JAVA)
JAVA ME (MICRO EDITION FOR MOBILES)
Java Version
Why Use Java?
● Java works on different platforms (Windows, Mac, Linux, Raspberry Pi, etc.)
● It is one of the most popular programming language in the world
● It is easy to learn and simple to use
● It is open-source and free
● It is secure, fast and powerful
● It has a huge community support (tens of millions of developers)
● Java is an object oriented language which gives a clear structure to programs and
allows code to be reused, lowering development costs
● As Java is close to C++ and C#, it makes it easy for programmers to switch to Java or
vice versa
Features
● Simple
● Object Oriented
● Distributed
● Interpreted
● Robust
● Secure
● Portable
● Multi threaded
● Garbage Collector
Downloading & Installation of java
1. Jdk download
https://www.oracle.com/in/java/technologies/javase-downloads.html
2 https://www.oracle.com/java/technologies/javase-jdk14-downloads.html
After Download and installation:
Setting a path:
1. C:\Program Files\Java\jdk-14.0.2\bin
2. Go to System settings of environment variable
3. In the Path, add: C:\Program Files\Java\jdk-14.0.2\bin
4. Add New:
5. Variable name: JAVA_HOME
6. Variable value : C:\Program Files\Java\jdk-14.0.2
How to Compile and Run?
The language a computer can understand is called machine language or machine code.
When you run a program written in high-language, which is human-readable source code like
mycode.java, you first need to compile it before you can run it. The compiler translates codes
written in high-language into byte code (mycode.class)
There's a special interpreter that translates your byte code into machine language, this
interpreter is called Java Virtual Machine a.k.a JVM. It is the JVM that runs your java
code.
How to Run?
Difference between C and java?
C JAVA
Java is Object-Oriented
C is a Procedural Programming Language.
language.
Java is an Interpreted language
C is a compiled language that is it converts that is in Java, the code is first
the code into machine language so that it transformed into bytecode and
could be understood by the machine or that bytecode is then executed
system. by the JVM (Java Virtual
Machine).
C does not contain the property called
Inheritance because it does not support
Java contains the property of
OOPS, which is very useful for code
Inheritance which is very useful
reusability. Thus C is not suited when one
in code reuseability.
has to relate the things according to the
real world.
Memory allocation can be done by malloc Memory allocation can be done
in C by a new keyword in Java.
Declaration of variables is at the beginning
of the block but in the latest version of C We can declare variables
that is C99 we can also declare variables anywhere.
anywhere.
A compiler will free up the
free is used for freeing the memory in C. memory internally by calling the
garbage collector.
Java supports the concept of
C does not supports Threading.
threading.
Java does not supports
C supports pointers.
pointers.
It is not portable. It is portable.
Call by value and call by reference is
It only supports a call by value.
supported in C.
C is platform dependent. Java is a platform independent.
It supports user-based memory It internally manages the
management. memory.
C is not robust that is strict type checking
does not takes place while compile and Java is robust.
run time.
Exception handling cannot be directly
achieved in C and thus it lacks the Exception Handling is supported
maintenance of normal flow of the in Java.
program.
Java follows a bottom-up
It follows a top-down approach.
approach.
Java supports method
Overloading functionality is not supported
overloading which helps in code
by C.
readability.
Java does not support
C supports Preprocessors.
Preprocessors.
C does not supports OOPS concept. Java supports OOPS concept.
Union and structure datatypes are Java does not supports union
supported by C. and structures.
Whereas Java does not suport
C supports the storage classes.
the storage classes.
Go-to statements are supported in C Java does not supports go-to
language. statements.
Virtual keywords are not
Virtual keywords are supported by C.
supported by Java.
Java supports method
Overloading functionality is not supported
overloading which helps in code
by C.
readability.
Default members of Java are
Default members of C are public.
private.
Data hiding is done by using
Data hiding is done by using static in C.
private in Java.
Difference between C++ and JAVA
Differences between Java and C++
PARAMETERS JAVA C++
Platform independent,
Platform dependent,
Java bytecode works
Platform Dependency should be compiled for
on any operating
different platform.
System.
C++ is platform
It can run in any OS
Portability dependent hence it is
hence it is portable.
not portable.
Java is both Compiled
C++ is only Compiled
Compilation and Interpreted
Language.
Language.
Memory Management Memory Management
Memory Management
is System Controlled. in C++ is Manual.
It doesn’t have Virtual It have Virtual
Virtual Keyword
Keyword. Keyword.
It supports only single
inheritance. Multiple It supports both single
Multiple Inheritance inheritance achieved and multiple
partially using Inheritance.
interfaces.
It supports only
It supports both
method overloading
Overloading methods and operators
and doesn’t allow
overloading.
operator overloading.
It supports limited It strongly supports
Pointers
support for pointers. Pointer.
C++ libraries are
Libraries libraries have a wide comparatively with low
range of classes for level functionalities.
various high-level
services
It supports It doesn’t support
Documentation documentation documentation
Comment comment (e.g, /**.. */) comment for source
for source code. code.
Java is only C++ is both a
object-oriented procedural and
Type
programming object-oriented
language. programing language.
Java uses the (System
C++ uses uses cin for
Input-Output class) System.in for
input and cout for an
mechanism input and System.out
Output operation.
for output.
Java doesn’t support C++ supports goto
goto Keyword
goto Keyword keyword.
Java doesn’t support C++ supports
Structures and Unions
Structures and Unions. Structures and Unions.
Java supports only C++ supports both
Parameter Passing Pass by Value Pass by Value and
technique. pass by reference.
It supports both global
It supports no global
Global Scope scope and namespace
scope.
scope.
Automatic object It supports manual
Object Management management with object management
garbage collection. using new and delete.
JVM Architecture
JVM is the heart of entire JAVA program execution process.
It is an abstract machine. It is specification that provides runtime environment in which JAVA bytecodes
can be executed
Platform Dependent
Responsible for taking .class file and converting each byte code instructions into the machine language
instructions that can be executed by the microprocessor.
Architecture
1. Class Loader : It is a sub system used for loading class files, it performs 3 main functions:
Loading, linking and initialization
How JVM Works – JVM Architecture?
Last Updated: 21-05-2019
JVM(Java Virtual Machine) acts as a run-time engine to run Java applications. JVM is the one that
actually calls the main method present in a java code. JVM is a part of JRE(Java Runtime
Environment).
Java applications are called WORA (Write Once Run Anywhere). This means a programmer can
develop Java code on one system and can expect it to run on any other Java enabled system without
any adjustment. This is all possible because of JVM.
When we compile a . java file, .class files(contains byte-code) with the same class names present in
.java file are generated by the Java compiler. This . class file goes into various steps when we run it.
These steps together describe the whole JVM.
Class Loader Subsystem
It is mainly responsible for three activities.
● Loading
● Linking
● Initialization
Loading : The Class loader reads the .class file, generate the corresponding binary data and save it in
method area. For each . class file, JVM stores following information in method area.
● Fully qualified name of the loaded class and its immediate parent class.
● Whether . class file is related to Class or Interface or Enum
● Modifier, Variables and Method information etc.
After loading .class file, JVM creates an object of type Class to represent this file in the heap memory.
Please note that this object is of type Class predefined in j ava.lang package. This Class object can be
used by the programmer for getting class level information like name of class, parent name, methods
and variable information etc. To get this object reference we can use g
etClass() method of Object
class.
Note : For every loaded .class file, only o
ne object of Class is created.
Student s2 = new Student();
// c2 will point to same object where
// c1 is pointing
Class c2 = s2.getClass();
System.out.println(c1==c2); // true
Linking : Performs verification, preparation, and (optionally) resolution.
● Verification : It ensures the correctness of . class file i.e. it check whether this file is
properly formatted and generated by valid compiler or not. If verification fails, we get
run-time exception java.lang.VerifyError.
● Preparation : JVM allocates memory for class variables and initializing the memory to
default values.
● Resolution : It is the process of replacing symbolic references from the type with direct
references. It is done by searching into method area to locate the referenced entity.
Initialization : In this phase, all static variables are assigned with their values defined in the code and
static block(if any). This is executed from top to bottom in a class and from parent to child in class
hierarchy.
In general, there are three class loaders :
● Bootstrap class loader : Every JVM implementation must have a bootstrap class loader,
capable of loading trusted classes. It loads core java API classes present in
JAVA_HOME/jre/lib directory. This path is popularly known as bootstrap path. It is
implemented in native languages like C, C++.
● Extension class loader : It is child of bootstrap class loader. It loads the classes present in
the extensions directories J
AVA_HOME/jre/lib/ext(Extension path) or any other directory
specified by the java.ext.dirs system property. It is implemented in java by the
sun.misc.Launcher$ExtClassLoader class.
● System/Application class loader : It is child of extension class loader. It is responsible to
load classes from application class path. It internally uses Environment Variable which
mapped to java.class.path. It is also implemented in Java by the
sun.misc.Launcher$AppClassLoader class.
Note : JVM follow Delegation-Hierarchy principle to load classes. System class loader delegate load
request to extension class loader and extension class loader delegate request to boot-strap class
loader. If class found in boot-strap path, class is loaded otherwise request again transfers to extension
class loader and then to system class loader. At last if system class loader fails to load class, then we
get run-time exception j ava.lang.ClassNotFoundException.
JVM Memory
Method area :In method area, all class level information like class name, immediate parent class
name, methods and variables information etc. are stored, including static variables. There is only one
method area per JVM, and it is a shared resource.
Heap area :Information of all objects is stored in heap area. There is also one Heap Area per JVM. It is
also a shared resource.
Stack area :For every thread, JVM create one run-time stack which is stored here. Every block of this
stack is called activation record/stack frame which store methods calls. All local variables of that
method are stored in their corresponding frame. After a thread terminate, it’s run-time stack will be
destroyed by JVM. It is not a shared resource.
PC Registers :Store address of current execution instruction of a thread. Obviously each thread has
separate PC Registers.
Native method stacks :For every thread, separate native stack is created. It stores native method
information.
Execution Engine
Execution engine execute the .class (bytecode). It reads the byte-code line by line, use data and
information present in various memory area and execute instructions. It can be classified in three
parts :-
● Interpreter : It interprets the bytecode line by line and then executes. The disadvantage
here is that when one method is called multiple times, every time interpretation is required.
● Just-In-Time Compiler(JIT) : It is used to increase efficiency of interpreter.It compiles the
entire bytecode and changes it to native code so whenever interpreter see repeated
method calls,JIT provide direct native code for that part so re-interpretation is not
required,thus efficiency is improved.
● Garbage Collector : It destroy un-referenced objects.For more on Garbage Collector,refer
Garbage Collector.
Java Native Interface (JNI) :
It is an interface which interacts with the Native Method Libraries and provides the native libraries(C,
C++) required for the execution. It enables JVM to call C/C++ libraries and to be called by C/C++
libraries which may be specific to hardware.
Native Method Libraries :
It is a collection of the Native Libraries(C, C++) which are required by the Execution Engine.