0% found this document useful (0 votes)
4 views35 pages

Module 1 Introduction

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views35 pages

Module 1 Introduction

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 35

1

Syllabus
Module – 1
Basics of Java: Features of Java, Byte Code and Java Virtual Machine, JDK, Data types, Operator, Control
Statements – If , else, nested if, if-else ladders, Switch, while, do- while, for, for-each, break, continue.
Array : Single and Multidimensional Array,
Classes, Objects and Methods: Class, Object, Object reference, Constructor, Constructor Overloading,
Method Overloading, Recursion, Passing and Returning object form Method, new operator, this and
static keyword, finalize() method , Access control, modifiers, Nested class, Inner class, Anonymous inner
class, Abstract class.
Programs:
1.Write a program to convert rupees to dollar. 60 rupees=1 dollar.
2.Write a program that calculate the percentage marks of the student if marks of 6 subjects are given.
3.Write a program to enter two numbers and perform mathematical operations on them.
4.Write an interactive program to print a diamond shape.
5.Program to define class Box and constructors. Demonstrate constructors.
6.Program to define class Addition, methods and objects. Demonstrate method overloading to add 2
integers, 3 floating numbers and 2 strings.

2
Module – 2

String: String class, StringBuffer class, Operations on string, Command line


argument, Use of Wrapper Class.
Inheritance: Use of Inheritance, Inheriting Data members and Methods, constructor
in inheritance, Multilevel Inheritance – method overriding Handle multilevel
constructors – super keyword, Stop Inheritance - Final keywords, Dynamic method
dispatch, Understanding of Java Object Class.
Package: Use of Package, CLASSPATH, Import statement, Static import, Access
control.

Programs:
1.Write a program to find length of string and print second half of the string.
2.Write a program to accept a line and check how many consonants and vowels are there in line.
3.Write a program to count the number of words that start with capital letters.
4.Write a program to find that given number or string is palindrome or not.
5.Create a class which asks the user to enter a sentence, and it should display count of each vowel type in the sentence.
The program should continue till user enters a word “quit”. Display the total count of each vowel for all sentences.
6.Write an interactive program to print a string entered in a pyramid form.
7.Program to define inheritance and show method overriding - Program to define base class Shapes, with methods and
create derived classes Square, Triangle, Rectangle and Circle. Create objects and show method overriding for calculating
area of Square,
Triangle, Rectangle and Circle.

3
Module – 3
Interfaces : Creation and Implementation of an interface, Interface reference, Interface inheritance,
Nesting Interfaces, variables in Interfaces, Comparison between Abstract Class and Interface.
Exception Handling: Exception and Error, Use of try, catch, throw, throws and finally, Built in
Exception, Custom exception, Throwable Class.
Programs:
1.Create an Interface Stack with methods push(), pop() and show(). Create class IntStack which
implements Stack. Demonstrate the working of this class.
2.Create an Interface Queue with methods insert(), delete() and display(). Create class StringQueue
which implements Queue. Demonstrate the working of this class.
3.Analyze how a programmer must handle an error when an invalid mobile number is entered (lesser
than 10 digits or greater than 10 digits; with alphabets; starting with 0) is entered while taking the
details of a student. The Student class must contain the following: Name; USN; Branch and Mobile
Number. Write a program using a custom exception type.
4.Create an exception called Non Int Result Exception, which is generated when the result of dividing
two integer values produces a result with a fractional component. Non Int Result Exception has two
fields that hold integer values; a constructor; and an override of the to String() method, allowing a
friendlier description of the exception to be displayed using println().
5.Create a Counter class with a private count instance variable and two methods.
The first method: synchronized void increment() – tries to increment count by If count is already at its
maximum of 3, then it waits until count is less than 3 before incrementing it. The other method is
synchronized void decrement() – attempts to decrement count by
1. If count already at a minimum of 0, then it waits until count is greater than 0 before decrementing
it. Every time either method has to wait, it displays a statement as to why it is waiting. Also every
time an increment or decrement occurs, the Counter displays a statement that says what occurred
and shows count’s new value.
1.Create a Bank class with withdrawal and deposit methods. Demonstrate the use of notify() and
wait().

4
Module – 4

Multithreaded Programming: Use of Multithread programming, Thread class and Runnable interface ,
Thread priority, Thread synchronization, Thread communication, Deadlock.
Swings: Swings: The origins of Swing; Two key Swing features; Components and Containers; The Swing
Packages; A simple Swing Application; Create a Swing J Applet; J label and Image Icon; J Text Field; The
Swing Buttons; J Tabbed pane; J Scroll Pane; JList; J Combo Box; JTable.
Programs:
1.Write a JAVA program which creates two threads, one thread displays “JAVA” 10 times, and another thread
displays “PROGRAMMING LANGUAGE” 15 times continuously?
2.Write a Java program that implements a multi-thread application that has three threads. First thread
generates a random integer for every 1 second; second thread computes the square of the number and
prints; third thread will print the value of cube of the number.
3.Write a program that prints the Multiplication Table for numbers 2- 10. At a time the tables must print
completely for one number before printing for the next number.
4.Create a GUI for a business of your choice using swings. Demonstrate the use of Button,
Radio Button, Combo box, List, Textfield etc.

5
Module – 5

Servlet : The Life Cycle of a Servlet; Using Tomcat for Servlet Development; A
simple Servlet; The Servlet API; The Javax. servlet Package; Reading Servlet
Parameter; The Javax. servlet.http package; Handling HTTP Requests and
Responses; Using Cookies; Session Tracking. Java Server Pages (JSP): JSP, JSP
Tags, Tomcat, Request String, User Sessions, Cookies, Session Objects.
Programs:
1.Write Servlet application to print current date &time.
2.Write Servlet application to demonstrate session tracking.
3.Implement Program 1 using JSP.
4.Implement Program 2 using JSP.

6
Module 1

Lecture Hour Topics Covered

1 Introduction to Java: Java and Java applications; Java Development Kit (JDK)

Java is interpreted, Byte Code, JVM; Object-oriented programming; Simple Java


2
programs.

3 Data types and other tokens: Boolean variables, int, long, char, operators, arrays,

White spaces, literals, assigning values; Creating and destroying objects; Access
4
specifiers.

Operators and Expressions: Arithmetic Operators, Bitwise operators, Relational


5 operators, The Assignment Operator, The? Operator; Operator Precedence; Logical
expression; Type casting; Strings

6 Control Statements: Selection statements, iteration statements, Jump Statements.

7
What Is Java?

• History
• Characteristics of Java

8
History
• James Gosling and Sun Microsystems
• Oak
• Java, May 20, 1995, Sun World
• HotJava
– The first Java-enabled Web browser

9
Overlap of C, C++, and Java

C++

C Java

10
How Java Changed the Internet
Java innovated a new type of networked program called the applet
Java also addressed portability and security.

Java Applets
•An applet is a special kind of Java program that is designed to be transmitted
over the Internet and automatically executed by a Java-compatible web
browser.

•An applet is downloaded on demand, without further interaction with the user.
• small programs.
•used to display data provided by the server, handle user input, or provide
simple functions that execute locally, rather than on the server.
•In essence, the applet allows some functionality to be moved from the server
to the client.
•In general, there are two very broad categories of objects that are transmitted
between the server and the client:
• passive information and dynamic, active programs.
• the applet is a dynamic, self-executing program. Such a program is an active
agent on the client computer, yet it is initiated by the server. 11
• Security
• Java achieved this protection by confining an applet to the
Java execution environment and not allowing it access to
other parts of the computer.
• The ability to download applets with confidence that no harm
will be done and that no security will be breached is
considered by many to be the single most innovative aspect
of Java.

• Portability
• Portability is a major aspect of the Internet because there are
many different types of computers and operating systems
connected to it.
• The same code must work on all computers. Therefore, some
means of generating portable executable code was needed
12
Java Bytecode
• Bytecode is a highly optimized set of instructions
• executed by the Java run-time system, which is called the Java
Virtual Machine (JVM).
• JVM was designed as an interpreter for bytecode.
• only the JVM needs to be implemented for each platform.
• Once the run-time package exists for a given system, any Java
program can run on it.
• Although the details of the JVM will differ from platform to
platform, all understand the same Java bytecode.
• Thus, the execution of bytecode by the JVM is the easiest way
to create truly portable programs.

13
• Because the JVM is in control, it can contain the program and
prevent it from generating side effects outside of the system
• Just-In-Time (JIT) compiler for bytecode.
• When a JIT compiler is part of the JVM, selected portions of
bytecode are compiled into executable code in real time, on a
piece-by-piece, demand basis.
• not practical to compile an entire Java program into
executable code all at once
• a JIT compiler compiles code as it is needed, during
execution.
• not all sequences of bytecode are compiled—only those that
will benefit from compilation. The remaining code is simply
interpreted.
• Even when dynamic compilation is applied to bytecode, the
portability and safety features still apply, because the JVM is
still in charge of the execution environment 14
Compiled Programs With Different
Operating Systems

Windows
compiler

Executable (Windows)

Mac OS
Computer compiler
program
Executable (Mac)

UNIX
compiler

Executable (UNIX)
15
Compiled Languages

Programmer

Source Code Object Code Executable


Code
Text Editor Compiler linker
.c file .o file a.out file
Notepad, gcc
emacs,vi

16
A High Level View Of
Translating/Executing Java Programs
Stage 1: Compilation

Filename.java Java compiler Filename.class


(javac)

Java program Java bytecode


(generic binary)

17
A High Level View Of
Translating/Executing Java Programs
Stage 2: Interpreting and executing the byte code
Machine language
instruction (UNIX)

Filename.class Java interpreter Machine language


(java) instruction (Windows)
Java bytecode
(generic binary)
Machine language
instruction (Apple)

18
Java is Compiled and Interpreted
Hardware and
Programmer
Operating System

Source Code Byte Code


Text Editor Compiler Interpreter
.java file .class file
Notepad, javac java
emacs,vi appletviewer
netscape

19
Total Platform Independence

JAVA COMPILER
(translator)

JAVA BYTE CODE


(same for all platforms)

JAVA INTERPRETER
(one for each different system)

Windows 95 Macintosh Solaris Windows NT20


Java: Write Once, Run Anywhere
• Java has been used by large
and reputable companies to
create serious stand-alone
applications.
• Example:
– Eclipse1: started as a
programming environment
created by IBM for developing
Java programs. The program
Eclipse was itself written in Java.

21
Servlets: Java on the Server Side
• A servlet is a small program that executes on the server.
• applets dynamically extend the functionality of a web
browser,
• servlets dynamically extend the functionality of a web server.
• Servlets are used to create dynamically generated content
that is then served to the client.
• the servlet offers several advantages, including increased
performance.
• Because servlets (like all Java programs) are compiled into
bytecode and executed by the JVM, they are highly portable.
Thus, the same servlet can be used in a variety of different
server environments. The only requirements are that the
server support the JVM and a servlet container.
22
Characteristics of Java
The Java Buzzwords
• Java is simple
• Java is object-oriented
• Java is distributed – TCP/IP, RMI
• Java is interpreted and provides high performance
• Java is robust – multi platform, strictly typed language, memory
management & Exception handling
• Java is secure
• Java is architecture-neutral – write once, run anywhere, anytime
forever
• Java is portable
• Java is multithreaded
• Java is dynamic - Java programs carry with them substantial amounts
of run-time type information that is used to verify and resolve
accesses to objects at run time. This makes it possible to dynamically
link code in a safe and expedient manner
23
Java Environment
• Development tools : JDK
• Classes and methods : Java Standard
Library/API
• J2SE – Java 2 : Platform Standard Edition

24
JDK Versions
• JDK 1.02 (1995)
• JDK 1.1 (1996)
• Java 2 SDK v 1.2 (a.k.a JDK 1.2, 1998)Playground
• Java 2 SDK v 1.3 (a.k.a JDK 1.3, 2000)
• Java 2 SDK v 1.4 (a.k.a JDK 1.4, 2002)
• J2SE 5.0 (September 30, 2004)
• Java SE 6 (December 11, 2006)
• Java SE 7 (July 28, 2011)
• Java SE 8 (March 18, 2014)
• Java SE 9
• Java SE 10
25
JDK Versions
• Java SE 11 (LTS) September 2018
• Java SE 12 March 2019
• Java SE 13 September 2019
• Java SE 14 March 2020
• Java SE 15 September 2020
• Java SE 16 March 2021
• Java SE 17 September 2021

26
J2SE Version 1.3
Code named Kestrel and released on May 8, 2000.
J2SE Version 1.4
Code named Merlin and released on February 6, 2002 (first release
under JCP).

J2SE Version 5.0


Code named Tiger and released on September 30, 2004.
Java Version SE 6
Code named Mustang and released on December 11, 2006.

Java Version SE 7
Code named Dolphin and released on July 28, 2011.
JDK Editions
• Java Standard Edition (J2SE)
– J2SE can be used to develop client-side standalone
applications or applets.

• Java Enterprise Edition (J2EE)


– J2EE can be used to develop server-side applications such as
Java servlets and Java ServerPages.

• Java Micro Edition (J2ME).


– J2ME can be used to develop applications for mobile
devices such as cell phones.

30
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
• javadoc - documentation generator
• javah - creates C header files

31
Process of Building and Running Java
Programs
Text Editor

Java Source
javadoc HTML Files
Code

javac

Java Class File javah Header Files

java jdb

Output
32
Application Programming Interface
• Language Support Package
• Utilities Package
• Input/output package
• Network package
• AWT package
• Applet Package

33
Java Run Time Environment
• JVM
• Runtime class libraries
• User interface toolkits
• Deployment technologies:
– Java plugin
– Java Webstart

34
Java IDE Tools
• Forte by Sun MicroSystems
• Borland JBuilder
• Microsoft Visual J++
• WebGain Café
• IBM Visual Age for Java
• NetBeans

35

You might also like