SlideShare a Scribd company logo
Java Programming (JP)
Lecture Notes
Unit 1
 Introduction:
◦ Over view of java, Java Buzzwords
◦ Data types, Variables and arrays, Operators
 Control statements,
 Classes and objects.
 I/O: I/O Basics, Reading Console input,
 writing Console output, Reading and
Writing Files.
 Inheritance: Basic concepts, uses super,
method overriding, dynamic method
dispatch,
 Abstract class, using final, the object class.
Unit 2
 String Handling:
◦ String Constructors, Special String
Operations-String Literals, String
Concatenation, Character Extraction, String
Comparisons. Searching Strings,
Modifying a string.
 String Buffer:
◦ String Buffer Constructors, length(),
capacity(), set Length(),Character
Extraction methods,
append(),insert(),reverse(),delete(),replace(
Unit 3
 Packages and Interfaces:
 Packages, Access protection,
Importing packages, Interfaces.
 Exception Handling:
◦ Fundamentals, Types of Exception,
◦ Usage of try, catch, throw throws
◦ finally, built in Exceptions.
Unit 4
 Multithreading:
◦ Concepts of multithreading, Main thread,
creating thread and multiple threads,
 Using isAlive() and join( ),
 Thread Priorities, synchronization,
 Interthread communication.
Unit 5
 Applets:
◦ Applet basics and Applet class.
 Event Handling:
◦ Basic concepts, Event classes, Sources
of events, Event listener Interfaces,
 Handling mouse and keyboard events,
 Adapter classes.
 Abstract Window Toolkit (AWT)
◦ AWT classes, AWT Controls.
Unit 6
 Java Swings & JDBC:
◦ Introduction to Swing: JApplet,
TextFields, Buttons, Combo Boxes,
Tabbed Panes.
 JDBC: Introduction to JDBC
Books
 TEXT BOOKS:
◦ Herbert Schildt [2008], [5th Edition], The
Complete Reference Java2, TATA
McGraw-Hill.(1,2,3,4,5,6 Units).
 REFERENCE BOOKS:
◦ Bruce Eckel [2008], [2nd Edition],
Thinking in Java, Pearson Education.
◦ H.M Dietel and P.J Dietel [2008], [6th
Edition], Java How to Program, Pearson
Ed.
◦ E. Balagurusamy, Programming with
Java: A primer, III Edition, Tata McGraw-
Hill, 2007.
List of Lab Experiments
1. Implementing classes and Constructors concepts.
2. Program to implement Inheritance.
3. Program for Operations on Strings.
4. Program to design Packages.
5. Program to implement Interfaces.
6. Program to handle various types of exceptions.
7. Program to create Multithreading by extending
Thread class.
8. Program to create Multithreading by implementing
Runnable interface.
9. Program for Applets.
10. Program for Mouse Event Handling.
11. Program to implement Key Event Handling
12. Program to implement AWT Controls.
Java Programming Examples
 Program to print some text onto output
screen.
 Program to accept values from user
Java Program: Example 1
public class firstex
{
public static void main(String []args)
{
System.out.println(“Java welcomes CSE
4A");
}
}
Dissection of Java Program
 public : It is an Access Modifier, which
defines who can access this method.
Public means that this method will be
accessible to any class(If other class
can access this class.).
 Access Modifier :
◦ default
◦ private
◦ public
◦ protected
public class firstex
{
public static void main(String []args)
{
System.out.println(“Java welcomes CSE
4A");
}
}
 class - A class can be defined as a
template/blue print that describes the
behaviors/states that object of its type
support.
 static : Keyword which identifies the
class related this. It means that the
main() can be accessed without
creating the instance of Class.
public class firstex
{
public static void main(String []args)
{
System.out.println(“Java welcomes CSE
4A");
}
}
 void: is a return type, here it does not
return any value.
 main: Name of the method. This
method name is searched by JVM as
starting point for an application.
 string args[ ]: The parameter is a
String array by name args. The string
array is used to access command-line
arguments. public class firstex
{
public static void main(String []args)
{
System.out.println(“Java welcomes CSE 4A");
}
}
 System:
◦ system class provides facilities such as
standard input, output and error streams.
 out:
◦ out is an object of PrintStream class defined
in System class
 println(“ “);
◦ println() is a method of PrintStream class
public class firstex
{
public static void main (String [ ] args)
{
System.out.println(“Java welcomes CSE 4A");
}
}
Possible
Errors
public class firstex
 class  Class
public class firstex
 firstex 
myex
{
public static void main (String [ ]
args)
 public 
private
{
public static void main (String [ ]
args)
 static 
{
public static void main (String [ ]
args)
{
system.out.println(“Java welcomes CSE
4A");
}
}
 system 
System
 out  Out
 println 
Println
Program to take input from
user
 Ways to accept input from user:
◦ Using InputStreamReader class
◦ Using Scanner class
◦ Using BufferedReader class
◦ Using Console class
Accept two numbers and display
sumimport java.io.*;
public class ex3
{
public static void main(String ar[ ])throws IOException {
InputStreamReader isr=new
InputStreamReader(System.in);
BufferedReader br=new BufferedReader(isr);
System.out.println("Enter first value");
String s1=br.readLine();
System.out.println("Enter Second value");
String s2=br.readLine();
int a=Integer.parseInt(s1);
int b=Integer.parseInt(s2);
System.out.println("Addition = "+(a+b));
}
}
The Java.io.InputStreamReader class is a bridge from byte
streams to character streams.It reads bytes and decodes
them into characters using a specified charset.
The Java.io.BufferedReader class reads text from a
character-input stream, buffering characters so as to provide
for the efficient reading of characters, arrays, and lines.
Using Scanner Class
import java.util.*;
public class ex4 {
public static void main(String ar[]) {
Scanner scan=new
Scanner(System.in);
System.out.println("Enter first value");
int a=scan.nextInt();
System.out.println("Enter Second
value");
int b=scan.nextInt();
System.out.println("Addition =
"+(a+b));
}
}
The java.util.Scanner class is a simple text scanner which
can parse primitive types and strings using regular
expressions.
Using Console
import java.io.*;
class consoleex
{
public static void main(String args[])
{
Console c=System.console();
System.out.println("Enter your name: ");
String n=c.readLine();
System.out.println("Enter password: ");
char[ ] ch=c.readPassword();
String pass=String.valueOf(ch);//converting char array into string
System.out.println(“Hai Mr. "+n);
System.out.println(“Ur Password is: "+pass);
}
}
Using BufferedReader class
import java.io.*;
class ex2 {
public static void main(String[ ] args) {
BufferedReader in =
new BufferedReader(new InputStreamReader(System.in));
String name = “ “;
System.out.print(“Enter your name: ");
try {
name = in.readLine();
}
catch(Exception e) {
System.out.println("Caught an exception!");
}
System.out.println("Hello " + name + "!");
}
}
Unit 1
Overview of Java
Programming Languages:
 Machine Language
 Assembly Language
 High level Language
Machine language:
• It is the lowest-level programming language.
• Machine languages are the only languages understood by computers.
For example, to add two numbers, you might write an instruction in
binary like this:
1101101010011010
Assembly Language
 It implements a symbolic representation of
the numeric machine codes and other
constants needed to program a particular
CPU architecture.
 Assembly Program to add two numbers:
name "add"
mov al, 5 ; bin=00000101b
mov bl, 10 ; hex=0ah or bin=00001010b
add bl, al ; 5 + 10 = 15 (decimal) or
hex=0fh or
bin=00001111b
 MASM
 TASM
…
ADDF3 R1, R2, R3
…
Assembly Source File
Assembler …
1101101010011010
…
Machine Code File
Translation
 Interpreter
 Compiler
Compiler
 A compiler translates the entire source
code into a machine-code file
…
area = 5 * 5 * 3.1415;
...
High-level Source File
Compiler Executor
Output…
0101100011011100
1111100011000100
…
...
Machine-code File
Interpreter
 An interpreter reads one statement
from the source code, translates it to
the machine code or virtual machine
code, and then executes it.
…
area = 5 * 5 * 3.1415;
...
High-level Source File
Interpreter
Output
What is Java
 Java is a computer programming language that
is concurrent, object-oriented.
 It is intended to let application developers "write
once, run anywhere" (WORA), meaning that
code that runs on one platform does not need to
be recompiled to run on another.
 Java applications are typically compiled to
bytecode (class file) that can run on any Java
virtual machine (JVM) regardless of computer
architecture.
 Java is a general purpose programming
language.
 Java is the Internet programming language.
Where is Java used?
Usage of Java in Applets :
Example
Usage of Java in Mobile Phones
and PDA
Usage of Java in Self Test
Websites
Prerequisites to be known for
Java
 How to check whether java is present in
the system or not.
 How to install java in your machine.
 How to set path for java
 Check whether java is installed correctly
or not.
 What is JVM
Introduction to Java
 “B” led to “C”, “C” evolved into “C++” and
“C++ set the stage for Java.
 Java is a high level language like C, C++
and Visual Basic.
 Java is a programming language originally
developed by James Gosling at Sun
Microsystems (which has since merged into
Oracle Corporation) and released in 1995
as a core component of Sun Microsystems'
Java platform.
20 December 2015
C Sreedhar Java Programming Lecture Notes
2015 – 2016 IV Semester 37
 Java was conceived by
◦ James Gosling,
◦ Patrick Naughton,
◦ Chris Warth,
◦ Ed Frank and
◦ Mike Sheridan at Sun Microsystems, Inc in
1991.
 It took 18 months to develop the first
working version.
 Initially called “Oak”,a tree; “Green”;
renamed as “Java”, cofee in 1995.
 The language derives much of its syntax
from C and C++.
20 December 2015 38
 Motivation and Objective of Java: “Need
for a platform-independent (architecture-
neutral) language.
 Java applications are typically compiled
to bytecode (class file) that can run on
any Java virtual machine (JVM)
regardless of computer architecture.
 Java was originally designed for
interactive television, but it was too
advanced for the digital cable television
industry at the time.
 To create a software which can be
embedded in various consumer electronic
20 December 2015 39
Bytecode
 The output of Java compiler is NOT
executable code, rather it is called as
bytecode.
 Bytecode is a highly optimized set of
instructions designed to be executed
by the Java run-time system, called as
Java Virtual Machine (JVM).
 JVM is an interpreter for bytecode.
20 December 2015 40
20 December 2015 42
Characteristics of Java /
Buzzwords Java Is Simple
 Java Is Object-Oriented
 Java Is Distributed
 Java Is Interpreted
 Java Is Robust
 Java Is Secure
 Java Is Architecture-Neutral
 Java Is Portable
 Java's Performance
 Java Is Multithreaded
 Java Is Dynamic
20 December 2015 43
Characteristics of Java
 Java Is Simple
 Java Is Object-Oriented
 Java Is Distributed
 Java Is Interpreted
 Java Is Robust
 Java Is Secure
 Java Is Architecture-
Neutral
 Java Is Portable
 Java's Performance
 Java Is Multithreaded
 Java Is Dynamic
20 December 2015 44
Java is partially modeled
on C++, but greatly
simplified and improved.
Some people refer to
Java as "C++--" because
it is like C++ but with
more functionality and
fewer negative aspects.
Characteristics of Java
 Java Is Simple
 Java Is Object-Oriented
 Java Is Distributed
 Java Is Interpreted
 Java Is Robust
 Java Is Secure
 Java Is Architecture-
Neutral
 Java Is Portable
 Java's Performance
 Java Is Multithreaded
 Java Is Dynamic
20 December 2015 45
Java is inherently object-oriented.
Although many object-oriented
languages began strictly as
procedural languages, Java was
designed from the start to be
object-oriented. Object-oriented
programming (OOP) is a popular
programming approach that is
replacing traditional procedural
programming techniques.
One of the central issues in
software development is how to
reuse code. Object-oriented
programming provides great
flexibility, modularity, clarity, and
reusability through encapsulation,
inheritance, and polymorphism.
Characteristics of Java
 Java Is Simple
 Java Is Object-Oriented
 Java Is Distributed
 Java Is Interpreted
 Java Is Robust
 Java Is Secure
 Java Is Architecture-
Neutral
 Java Is Portable
 Java's Performance
 Java Is Multithreaded
 Java Is Dynamic
20 December 2015 46
Distributed computing involves
several computers working
together on a network. Java is
designed to make distributed
computing easy. Since
networking capability is
inherently integrated into Java,
writing network programs is like
sending and receiving data to
and from a file.
Characteristics of Java
 Java Is Simple
 Java Is Object-Oriented
 Java Is Distributed
 Java Is Interpreted
 Java Is Robust
 Java Is Secure
 Java Is Architecture-
Neutral
 Java Is Portable
 Java's Performance
 Java Is Multithreaded
 Java Is Dynamic
20 December 2015 47
You need an interpreter to run
Java programs. The programs
are compiled into the Java
Virtual Machine code called
bytecode. The bytecode is
machine-independent and can
run on any machine that has a
Java interpreter, which is part of
the Java Virtual Machine (JVM).
Characteristics of Java
 Java Is Simple
 Java Is Object-Oriented
 Java Is Distributed
 Java Is Interpreted
 Java Is Robust
 Java Is Secure
 Java Is Architecture-
Neutral
 Java Is Portable
 Java's Performance
 Java Is Multithreaded
 Java Is Dynamic
20 December 2015 48
Java compilers can detect many
problems that would first show up
at execution time in other
languages.
Java has eliminated certain types
of error-prone programming
constructs found in other
languages.
Java has a runtime exception-
handling feature to provide
programming support for
robustness.
Characteristics of Java
 Java Is Simple
 Java Is Object-Oriented
 Java Is Distributed
 Java Is Interpreted
 Java Is Robust
 Java Is Secure
 Java Is Architecture-
Neutral
 Java Is Portable
 Java's Performance
 Java Is Multithreaded
 Java Is Dynamic
20 December 2015 49
Java implements several security
mechanisms to protect your system
against harm caused by stray
programs.
Characteristics of Java
 Java Is Simple
 Java Is Object-Oriented
 Java Is Distributed
 Java Is Interpreted
 Java Is Robust
 Java Is Secure
 Java Is Architecture-
Neutral
 Java Is Portable
 Java's Performance
 Java Is Multithreaded
 Java Is Dynamic
20 December 2015 50
Write once, run anywhere
With a Java Virtual Machine
(JVM), you can write one
program that will run on any
platform.
Characteristics of Java
 Java Is Simple
 Java Is Object-Oriented
 Java Is Distributed
 Java Is Interpreted
 Java Is Robust
 Java Is Secure
 Java Is Architecture-
Neutral
 Java Is Portable
 Java's Performance
 Java Is Multithreaded
 Java Is Dynamic
20 December 2015 51
Because Java is architecture
neutral, Java programs are
portable. They can be run on any
platform without being
recompiled.
Characteristics of Java
 Java Is Simple
 Java Is Object-Oriented
 Java Is Distributed
 Java Is Interpreted
 Java Is Robust
 Java Is Secure
 Java Is Architecture-
Neutral
 Java Is Portable
 Java's Performance
 Java Is Multithreaded
 Java Is Dynamic
20 December 2015 52
Java’s performance Because
Java is architecture neutral,
Java programs are portable.
They can be run on any
platform without being
recompiled.
Characteristics of Java
 Java Is Simple
 Java Is Object-Oriented
 Java Is Distributed
 Java Is Interpreted
 Java Is Robust
 Java Is Secure
 Java Is Architecture-
Neutral
 Java Is Portable
 Java's Performance
 Java Is Multithreaded
 Java Is Dynamic
20 December 2015 53
Multithread programming is
smoothly integrated in Java,
whereas in other languages you
have to call procedures specific to
the operating system to enable
multithreading.
Characteristics of Java
 Java Is Simple
 Java Is Object-Oriented
 Java Is Distributed
 Java Is Interpreted
 Java Is Robust
 Java Is Secure
 Java Is Architecture-
Neutral
 Java Is Portable
 Java's Performance
 Java Is Multithreaded
 Java Is Dynamic
20 December 2015 54
Java was designed to adapt to an
evolving environment. New code
can be loaded on the fly without
recompilation. There is no need for
developers to create, and for users
to install, major new software
versions. New features can be
incorporated transparently as
needed.
Lab Program
 write a java program to display total
marks of 5 students using student
class. Given the following attributes:
Regno(int), Name(string), Marks in
subjects(Integer Array), Total (int).
Expected Output
Enter the no. of students: 2
Enter the Reg.No: 1234
Enter the Name: name
Enter the Mark1: 88
Enter the Mark2: 99
Enter the Mark3: 89
Enter the Reg.No: 432
Enter the Name: name
Enter the Mark1: 67
Enter the Mark2: 68
Enter the Mark3: 98
Mark List
*********
RegNo Name Mark1 Mark2 Mark3 Total
1234 name 88 99 89 276
432 name 67 68 98 233
Outline of the Program
class Student
{
// Variable declarations
void readinput() throws IOException
{
// Use BufferedReader class to accept input from keyboard
}
void display()
{
}
}
class Mark
{
public static void main(String args[]) throws IOException
{
// body of main method
}
}
import java.io.*;
class Student
{
int regno,total;
String name;
int mark[ ]=new int[3];
void readinput() throws IOException
{
BufferedReader din=new BufferedReader(new InputStreamReader(System.in));
System.out.print("nEnter the Reg.No: ");
regno=Integer.parseInt(din.readLine());
System.out.print("Enter the Name: ");
name=din.readLine();
System.out.print("Enter the Mark1: ");
mark[0]=Integer.parseInt(din.readLine());
System.out.print("Enter the Mark2: ");
mark[1]=Integer.parseInt(din.readLine());
System.out.print("Enter the Mark3: ");
mark[2]=Integer.parseInt(din.readLine());
total=mark[0]+mark[1]+mark[2];
}
void display()
{
System.out.println(regno+"t"+name+"tt"+mark[0]+"t"+mark[1]+"t"+mark[2]+"t"+total);
}
}
class Mark
{
public static void main(String args[]) throws IOException
{
int size;
BufferedReader din=new BufferedReader(new InputStreamReader(System.in));
System.out.print("Enter the no. of students: ");
size=Integer.parseInt(din.readLine());
Student s[]=new Student[size];
for(int i=0;i<size;i++)
{
s[i]=new Student();
s[i].readinput();
}
System.out.println("tttMark List");
System.out.println("ttt*********");
System.out.println("RegNotNamettMark1tMark2tMark3tTotal");
for(int i=0;i<size;i++)
s[i].display();
}
}
Lab Program: Complex number
Arithmetic
public class ComplexNumber
{
// declare variables
Default Constructor definition
{ }
Parameterized constructor definition
{
}
Use method getComplexValue() to display in
complex number form
{
}
public static String addition(ComplexNumber num1, ComplexNumber num2)
{
// Code for complex number addition
}
public static String subtraction(ComplexNumber num1, ComplexNumber num2)
{
// Code for complex number subtraction
}
public static String multiplication(ComplexNumber num1, ComplexNumber num2)
{
// Code for complex number multiplication
}
public static String multiplication(ComplexNumber num1, ComplexNumber num2)
{
// create objects and call to parameterized constructors
// call to respective methods
}
Lab Program: Complex number
Arithmeticimport java.io.*;
public class ComplexNumber
{
private int a;
private int b;
public ComplexNumber()
{ }
public ComplexNumber(int a, int b)
{
this.a =a;
this.b=b;
}
public String getComplexValue()
{
if(this.b < 0)
{
return a+""+b+"i";
}
else
{
return a+"+"+b+"i";
}
}
public static String addition(ComplexNumber
num1, ComplexNumber num2)
{
int a1= num1.a+num2.a;
int b1= num1.b+num2.b;
if(b1<0)
{
return a1+""+b1+"i";
}
else
{
return a1+"+"+b1+"i";
}
}
public static String substraction(ComplexNumber
num1, ComplexNumber num2)
{
int a1= num1.a-num2.a;
int b1= num1.b-num2.b;
if(b1<0){
return a1+""+b1+"i";
}
else
{
return a1+"+"+b1+"i";
}
}
public static String multiplication(ComplexNumber num1,
ComplexNumber num2)
{
int a1= num1.a*num2.a;
int b1= num1.b*num2.b;
int vi1 = num1.a * num2.b;
int vi2 = num2.a * num1.b;
int vi;
vi=vi1+vi2;
if(vi<0)
{
return a1-b1+""+vi+"i";
}
else
{
return a1-b1+"+"+vi+"i";
}
}
public static void main(String args[])
{
ComplexNumber com1 = new
ComplexNumber(2,4);
ComplexNumber com2 = new
ComplexNumber(6,8);
System.out.println(com1.getComplexValue());
System.out.println(com2.getComplexValue());
System.out.println("Addition of both Complex
Numbers are
:"+ComplexNumber.addition(com1,com2));
System.out.println("Substraction of both Complex
Numbers are
:"+ComplexNumber.substraction(com1,com2));
System.out.println("Multiplication of both Complex
Numbers are
:"+ComplexNumber.multiplication(com1,com2));
}
}

More Related Content

What's hot

input/ output in java
input/ output  in javainput/ output  in java
input/ output in java
sharma230399
 
Java program structure
Java program structureJava program structure
Java program structure
shalinikarunakaran1
 
Arrays in Java
Arrays in JavaArrays in Java
Arrays in Java
Naz Abdalla
 
Java package
Java packageJava package
Java package
CS_GDRCST
 
Command line-arguments-in-java-tutorial
Command line-arguments-in-java-tutorialCommand line-arguments-in-java-tutorial
Command line-arguments-in-java-tutorial
Kuntal Bhowmick
 
MULTI THREADING IN JAVA
MULTI THREADING IN JAVAMULTI THREADING IN JAVA
MULTI THREADING IN JAVA
VINOTH R
 
Files in java
Files in javaFiles in java
Lexical analysis - Compiler Design
Lexical analysis - Compiler DesignLexical analysis - Compiler Design
Lexical analysis - Compiler Design
Muhammed Afsal Villan
 
Wrapper class
Wrapper classWrapper class
Wrapper class
kamal kotecha
 
Command line arguments
Command line argumentsCommand line arguments
Command line arguments
Ashok Raj
 
Constructor overloading & method overloading
Constructor overloading & method overloadingConstructor overloading & method overloading
Constructor overloading & method overloading
garishma bhatia
 
System calls
System callsSystem calls
System calls
Bernard Senam
 
Interface in java
Interface in javaInterface in java
Interface in java
PhD Research Scholar
 
Java interfaces
Java interfacesJava interfaces
Java interfaces
Raja Sekhar
 
Packages in java
Packages in javaPackages in java
Packages in java
Elizabeth alexander
 
Inheritance in java
Inheritance in javaInheritance in java
Inheritance in java
RahulAnanda1
 
Java abstract class & abstract methods
Java abstract class & abstract methodsJava abstract class & abstract methods
Java abstract class & abstract methods
Shubham Dwivedi
 
9. Input Output in java
9. Input Output in java9. Input Output in java
9. Input Output in java
Nilesh Dalvi
 
Java Tokens
Java  TokensJava  Tokens
Java Exception handling
Java Exception handlingJava Exception handling
Java Exception handling
kamal kotecha
 

What's hot (20)

input/ output in java
input/ output  in javainput/ output  in java
input/ output in java
 
Java program structure
Java program structureJava program structure
Java program structure
 
Arrays in Java
Arrays in JavaArrays in Java
Arrays in Java
 
Java package
Java packageJava package
Java package
 
Command line-arguments-in-java-tutorial
Command line-arguments-in-java-tutorialCommand line-arguments-in-java-tutorial
Command line-arguments-in-java-tutorial
 
MULTI THREADING IN JAVA
MULTI THREADING IN JAVAMULTI THREADING IN JAVA
MULTI THREADING IN JAVA
 
Files in java
Files in javaFiles in java
Files in java
 
Lexical analysis - Compiler Design
Lexical analysis - Compiler DesignLexical analysis - Compiler Design
Lexical analysis - Compiler Design
 
Wrapper class
Wrapper classWrapper class
Wrapper class
 
Command line arguments
Command line argumentsCommand line arguments
Command line arguments
 
Constructor overloading & method overloading
Constructor overloading & method overloadingConstructor overloading & method overloading
Constructor overloading & method overloading
 
System calls
System callsSystem calls
System calls
 
Interface in java
Interface in javaInterface in java
Interface in java
 
Java interfaces
Java interfacesJava interfaces
Java interfaces
 
Packages in java
Packages in javaPackages in java
Packages in java
 
Inheritance in java
Inheritance in javaInheritance in java
Inheritance in java
 
Java abstract class & abstract methods
Java abstract class & abstract methodsJava abstract class & abstract methods
Java abstract class & abstract methods
 
9. Input Output in java
9. Input Output in java9. Input Output in java
9. Input Output in java
 
Java Tokens
Java  TokensJava  Tokens
Java Tokens
 
Java Exception handling
Java Exception handlingJava Exception handling
Java Exception handling
 

Viewers also liked

Great cup of java
Great  cup of javaGreat  cup of java
Great cup of javaCIB Egypt
 
The Java memory model made easy
The Java memory model made easyThe Java memory model made easy
The Java memory model made easy
Rafael Winterhalter
 
Play Framework on Google App Engine - Productivity Stack
Play Framework on Google App Engine - Productivity StackPlay Framework on Google App Engine - Productivity Stack
Play Framework on Google App Engine - Productivity Stack
Marcin Stepien
 
Computer Programming- Lecture 9
Computer Programming- Lecture 9Computer Programming- Lecture 9
Computer Programming- Lecture 9
Dr. Md. Shohel Sayeed
 
Chapter 1. java programming language overview
Chapter 1. java programming language overviewChapter 1. java programming language overview
Chapter 1. java programming language overviewJong Soon Bok
 
SOLID Java Code
SOLID Java CodeSOLID Java Code
SOLID Java Code
Omar Bashir
 
Functional Programming in Java - Code for Maintainability
Functional Programming in Java - Code for MaintainabilityFunctional Programming in Java - Code for Maintainability
Functional Programming in Java - Code for Maintainability
Marcin Stepien
 

Viewers also liked (9)

Great cup of java
Great  cup of javaGreat  cup of java
Great cup of java
 
The Java memory model made easy
The Java memory model made easyThe Java memory model made easy
The Java memory model made easy
 
Play Framework on Google App Engine - Productivity Stack
Play Framework on Google App Engine - Productivity StackPlay Framework on Google App Engine - Productivity Stack
Play Framework on Google App Engine - Productivity Stack
 
Unit 1 Java
Unit 1 JavaUnit 1 Java
Unit 1 Java
 
Computer Programming- Lecture 9
Computer Programming- Lecture 9Computer Programming- Lecture 9
Computer Programming- Lecture 9
 
Chapter 1. java programming language overview
Chapter 1. java programming language overviewChapter 1. java programming language overview
Chapter 1. java programming language overview
 
Computer Programming - Lecture 1
Computer Programming - Lecture 1Computer Programming - Lecture 1
Computer Programming - Lecture 1
 
SOLID Java Code
SOLID Java CodeSOLID Java Code
SOLID Java Code
 
Functional Programming in Java - Code for Maintainability
Functional Programming in Java - Code for MaintainabilityFunctional Programming in Java - Code for Maintainability
Functional Programming in Java - Code for Maintainability
 

Similar to Java Notes by C. Sreedhar, GPREC

Introduction to java programming part 1
Introduction to java programming   part 1Introduction to java programming   part 1
Introduction to java programming part 1
university of education,Lahore
 
Chapter 2.1
Chapter 2.1Chapter 2.1
Chapter 2.1sotlsoc
 
OOP-Chap2.docx
OOP-Chap2.docxOOP-Chap2.docx
OOP-Chap2.docx
NaorinHalim
 
Java programming basics
Java programming basicsJava programming basics
Java programming basics
Hamid Ghorbani
 
4CS4-25-Java-Lab-Manual.pdf
4CS4-25-Java-Lab-Manual.pdf4CS4-25-Java-Lab-Manual.pdf
4CS4-25-Java-Lab-Manual.pdf
amitbhachne
 
Introduction java programming
Introduction java programmingIntroduction java programming
Introduction java programming
Nanthini Kempaiyan
 
basic_java.ppt
basic_java.pptbasic_java.ppt
basic_java.ppt
sujatha629799
 
Java programing language unit 1 introduction
Java programing language unit 1 introductionJava programing language unit 1 introduction
Java programing language unit 1 introduction
chnrketan
 
01-ch01-1-println.ppt java introduction one
01-ch01-1-println.ppt java introduction one01-ch01-1-println.ppt java introduction one
01-ch01-1-println.ppt java introduction one
ssuser656672
 
Java/Servlet/JSP/JDBC
Java/Servlet/JSP/JDBCJava/Servlet/JSP/JDBC
Java/Servlet/JSP/JDBC
FAKHRUN NISHA
 
CORE JAVA
CORE JAVACORE JAVA
Java platform
Java platformJava platform
Java platform
BG Java EE Course
 
Unit 1 of java part 2 basic introduction
Unit 1 of java part 2 basic introduction Unit 1 of java part 2 basic introduction
Unit 1 of java part 2 basic introduction
AKR Education
 
Java For beginners and CSIT and IT students
Java  For beginners and CSIT and IT studentsJava  For beginners and CSIT and IT students
Java For beginners and CSIT and IT students
Partnered Health
 
Java Programming
Java ProgrammingJava Programming
Java Programming
Anjan Mahanta
 
Introduction to Software Development
Introduction to Software DevelopmentIntroduction to Software Development
Introduction to Software Development
Zeeshan MIrza
 

Similar to Java Notes by C. Sreedhar, GPREC (20)

Introduction to java programming part 1
Introduction to java programming   part 1Introduction to java programming   part 1
Introduction to java programming part 1
 
Chapter 2.1
Chapter 2.1Chapter 2.1
Chapter 2.1
 
OOP-Chap2.docx
OOP-Chap2.docxOOP-Chap2.docx
OOP-Chap2.docx
 
Java programming basics
Java programming basicsJava programming basics
Java programming basics
 
4CS4-25-Java-Lab-Manual.pdf
4CS4-25-Java-Lab-Manual.pdf4CS4-25-Java-Lab-Manual.pdf
4CS4-25-Java-Lab-Manual.pdf
 
Introduction java programming
Introduction java programmingIntroduction java programming
Introduction java programming
 
basic_java.ppt
basic_java.pptbasic_java.ppt
basic_java.ppt
 
Core java
Core javaCore java
Core java
 
Java programing language unit 1 introduction
Java programing language unit 1 introductionJava programing language unit 1 introduction
Java programing language unit 1 introduction
 
Javalecture 1
Javalecture 1Javalecture 1
Javalecture 1
 
01-ch01-1-println.ppt java introduction one
01-ch01-1-println.ppt java introduction one01-ch01-1-println.ppt java introduction one
01-ch01-1-println.ppt java introduction one
 
Java/Servlet/JSP/JDBC
Java/Servlet/JSP/JDBCJava/Servlet/JSP/JDBC
Java/Servlet/JSP/JDBC
 
CORE JAVA
CORE JAVACORE JAVA
CORE JAVA
 
UNIT 1.pptx
UNIT 1.pptxUNIT 1.pptx
UNIT 1.pptx
 
Java platform
Java platformJava platform
Java platform
 
Unit 1 of java part 2 basic introduction
Unit 1 of java part 2 basic introduction Unit 1 of java part 2 basic introduction
Unit 1 of java part 2 basic introduction
 
Java For beginners and CSIT and IT students
Java  For beginners and CSIT and IT studentsJava  For beginners and CSIT and IT students
Java For beginners and CSIT and IT students
 
Java Programming
Java ProgrammingJava Programming
Java Programming
 
Java
JavaJava
Java
 
Introduction to Software Development
Introduction to Software DevelopmentIntroduction to Software Development
Introduction to Software Development
 

More from Sreedhar Chowdam

Design and Analysis of Algorithms-DP,Backtracking,Graphs,B&B
Design and Analysis of Algorithms-DP,Backtracking,Graphs,B&BDesign and Analysis of Algorithms-DP,Backtracking,Graphs,B&B
Design and Analysis of Algorithms-DP,Backtracking,Graphs,B&B
Sreedhar Chowdam
 
Design and Analysis of Algorithms Lecture Notes
Design and Analysis of Algorithms Lecture NotesDesign and Analysis of Algorithms Lecture Notes
Design and Analysis of Algorithms Lecture Notes
Sreedhar Chowdam
 
Design and Analysis of Algorithms (Knapsack Problem)
Design and Analysis of Algorithms (Knapsack Problem)Design and Analysis of Algorithms (Knapsack Problem)
Design and Analysis of Algorithms (Knapsack Problem)
Sreedhar Chowdam
 
DCCN Network Layer congestion control TCP
DCCN Network Layer congestion control TCPDCCN Network Layer congestion control TCP
DCCN Network Layer congestion control TCP
Sreedhar Chowdam
 
Data Communication and Computer Networks
Data Communication and Computer NetworksData Communication and Computer Networks
Data Communication and Computer Networks
Sreedhar Chowdam
 
DCCN Unit 1.pdf
DCCN Unit 1.pdfDCCN Unit 1.pdf
DCCN Unit 1.pdf
Sreedhar Chowdam
 
Data Communication & Computer Networks
Data Communication & Computer NetworksData Communication & Computer Networks
Data Communication & Computer Networks
Sreedhar Chowdam
 
PPS Notes Unit 5.pdf
PPS Notes Unit 5.pdfPPS Notes Unit 5.pdf
PPS Notes Unit 5.pdf
Sreedhar Chowdam
 
PPS Arrays Matrix operations
PPS Arrays Matrix operationsPPS Arrays Matrix operations
PPS Arrays Matrix operations
Sreedhar Chowdam
 
Programming for Problem Solving
Programming for Problem SolvingProgramming for Problem Solving
Programming for Problem Solving
Sreedhar Chowdam
 
Big Data Analytics Part2
Big Data Analytics Part2Big Data Analytics Part2
Big Data Analytics Part2
Sreedhar Chowdam
 
Python Programming: Lists, Modules, Exceptions
Python Programming: Lists, Modules, ExceptionsPython Programming: Lists, Modules, Exceptions
Python Programming: Lists, Modules, Exceptions
Sreedhar Chowdam
 
Python Programming by Dr. C. Sreedhar.pdf
Python Programming by Dr. C. Sreedhar.pdfPython Programming by Dr. C. Sreedhar.pdf
Python Programming by Dr. C. Sreedhar.pdf
Sreedhar Chowdam
 
Python Programming Strings
Python Programming StringsPython Programming Strings
Python Programming Strings
Sreedhar Chowdam
 
Python Programming
Python Programming Python Programming
Python Programming
Sreedhar Chowdam
 
Python Programming
Python ProgrammingPython Programming
Python Programming
Sreedhar Chowdam
 
C Recursion, Pointers, Dynamic memory management
C Recursion, Pointers, Dynamic memory managementC Recursion, Pointers, Dynamic memory management
C Recursion, Pointers, Dynamic memory management
Sreedhar Chowdam
 
C Programming Storage classes, Recursion
C Programming Storage classes, RecursionC Programming Storage classes, Recursion
C Programming Storage classes, Recursion
Sreedhar Chowdam
 
Programming For Problem Solving Lecture Notes
Programming For Problem Solving Lecture NotesProgramming For Problem Solving Lecture Notes
Programming For Problem Solving Lecture Notes
Sreedhar Chowdam
 
Big Data Analytics
Big Data AnalyticsBig Data Analytics
Big Data Analytics
Sreedhar Chowdam
 

More from Sreedhar Chowdam (20)

Design and Analysis of Algorithms-DP,Backtracking,Graphs,B&B
Design and Analysis of Algorithms-DP,Backtracking,Graphs,B&BDesign and Analysis of Algorithms-DP,Backtracking,Graphs,B&B
Design and Analysis of Algorithms-DP,Backtracking,Graphs,B&B
 
Design and Analysis of Algorithms Lecture Notes
Design and Analysis of Algorithms Lecture NotesDesign and Analysis of Algorithms Lecture Notes
Design and Analysis of Algorithms Lecture Notes
 
Design and Analysis of Algorithms (Knapsack Problem)
Design and Analysis of Algorithms (Knapsack Problem)Design and Analysis of Algorithms (Knapsack Problem)
Design and Analysis of Algorithms (Knapsack Problem)
 
DCCN Network Layer congestion control TCP
DCCN Network Layer congestion control TCPDCCN Network Layer congestion control TCP
DCCN Network Layer congestion control TCP
 
Data Communication and Computer Networks
Data Communication and Computer NetworksData Communication and Computer Networks
Data Communication and Computer Networks
 
DCCN Unit 1.pdf
DCCN Unit 1.pdfDCCN Unit 1.pdf
DCCN Unit 1.pdf
 
Data Communication & Computer Networks
Data Communication & Computer NetworksData Communication & Computer Networks
Data Communication & Computer Networks
 
PPS Notes Unit 5.pdf
PPS Notes Unit 5.pdfPPS Notes Unit 5.pdf
PPS Notes Unit 5.pdf
 
PPS Arrays Matrix operations
PPS Arrays Matrix operationsPPS Arrays Matrix operations
PPS Arrays Matrix operations
 
Programming for Problem Solving
Programming for Problem SolvingProgramming for Problem Solving
Programming for Problem Solving
 
Big Data Analytics Part2
Big Data Analytics Part2Big Data Analytics Part2
Big Data Analytics Part2
 
Python Programming: Lists, Modules, Exceptions
Python Programming: Lists, Modules, ExceptionsPython Programming: Lists, Modules, Exceptions
Python Programming: Lists, Modules, Exceptions
 
Python Programming by Dr. C. Sreedhar.pdf
Python Programming by Dr. C. Sreedhar.pdfPython Programming by Dr. C. Sreedhar.pdf
Python Programming by Dr. C. Sreedhar.pdf
 
Python Programming Strings
Python Programming StringsPython Programming Strings
Python Programming Strings
 
Python Programming
Python Programming Python Programming
Python Programming
 
Python Programming
Python ProgrammingPython Programming
Python Programming
 
C Recursion, Pointers, Dynamic memory management
C Recursion, Pointers, Dynamic memory managementC Recursion, Pointers, Dynamic memory management
C Recursion, Pointers, Dynamic memory management
 
C Programming Storage classes, Recursion
C Programming Storage classes, RecursionC Programming Storage classes, Recursion
C Programming Storage classes, Recursion
 
Programming For Problem Solving Lecture Notes
Programming For Problem Solving Lecture NotesProgramming For Problem Solving Lecture Notes
Programming For Problem Solving Lecture Notes
 
Big Data Analytics
Big Data AnalyticsBig Data Analytics
Big Data Analytics
 

Recently uploaded

Railway Signalling Principles Edition 3.pdf
Railway Signalling Principles Edition 3.pdfRailway Signalling Principles Edition 3.pdf
Railway Signalling Principles Edition 3.pdf
TeeVichai
 
Halogenation process of chemical process industries
Halogenation process of chemical process industriesHalogenation process of chemical process industries
Halogenation process of chemical process industries
MuhammadTufail242431
 
Gen AI Study Jams _ For the GDSC Leads in India.pdf
Gen AI Study Jams _ For the GDSC Leads in India.pdfGen AI Study Jams _ For the GDSC Leads in India.pdf
Gen AI Study Jams _ For the GDSC Leads in India.pdf
gdsczhcet
 
H.Seo, ICLR 2024, MLILAB, KAIST AI.pdf
H.Seo,  ICLR 2024, MLILAB,  KAIST AI.pdfH.Seo,  ICLR 2024, MLILAB,  KAIST AI.pdf
H.Seo, ICLR 2024, MLILAB, KAIST AI.pdf
MLILAB
 
ethical hacking-mobile hacking methods.ppt
ethical hacking-mobile hacking methods.pptethical hacking-mobile hacking methods.ppt
ethical hacking-mobile hacking methods.ppt
Jayaprasanna4
 
Pile Foundation by Venkatesh Taduvai (Sub Geotechnical Engineering II)-conver...
Pile Foundation by Venkatesh Taduvai (Sub Geotechnical Engineering II)-conver...Pile Foundation by Venkatesh Taduvai (Sub Geotechnical Engineering II)-conver...
Pile Foundation by Venkatesh Taduvai (Sub Geotechnical Engineering II)-conver...
AJAYKUMARPUND1
 
Forklift Classes Overview by Intella Parts
Forklift Classes Overview by Intella PartsForklift Classes Overview by Intella Parts
Forklift Classes Overview by Intella Parts
Intella Parts
 
CME397 Surface Engineering- Professional Elective
CME397 Surface Engineering- Professional ElectiveCME397 Surface Engineering- Professional Elective
CME397 Surface Engineering- Professional Elective
karthi keyan
 
DESIGN A COTTON SEED SEPARATION MACHINE.docx
DESIGN A COTTON SEED SEPARATION MACHINE.docxDESIGN A COTTON SEED SEPARATION MACHINE.docx
DESIGN A COTTON SEED SEPARATION MACHINE.docx
FluxPrime1
 
一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理
一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理
一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理
bakpo1
 
TECHNICAL TRAINING MANUAL GENERAL FAMILIARIZATION COURSE
TECHNICAL TRAINING MANUAL   GENERAL FAMILIARIZATION COURSETECHNICAL TRAINING MANUAL   GENERAL FAMILIARIZATION COURSE
TECHNICAL TRAINING MANUAL GENERAL FAMILIARIZATION COURSE
DuvanRamosGarzon1
 
Hybrid optimization of pumped hydro system and solar- Engr. Abdul-Azeez.pdf
Hybrid optimization of pumped hydro system and solar- Engr. Abdul-Azeez.pdfHybrid optimization of pumped hydro system and solar- Engr. Abdul-Azeez.pdf
Hybrid optimization of pumped hydro system and solar- Engr. Abdul-Azeez.pdf
fxintegritypublishin
 
Quality defects in TMT Bars, Possible causes and Potential Solutions.
Quality defects in TMT Bars, Possible causes and Potential Solutions.Quality defects in TMT Bars, Possible causes and Potential Solutions.
Quality defects in TMT Bars, Possible causes and Potential Solutions.
PrashantGoswami42
 
block diagram and signal flow graph representation
block diagram and signal flow graph representationblock diagram and signal flow graph representation
block diagram and signal flow graph representation
Divya Somashekar
 
weather web application report.pdf
weather web application report.pdfweather web application report.pdf
weather web application report.pdf
Pratik Pawar
 
WATER CRISIS and its solutions-pptx 1234
WATER CRISIS and its solutions-pptx 1234WATER CRISIS and its solutions-pptx 1234
WATER CRISIS and its solutions-pptx 1234
AafreenAbuthahir2
 
ethical hacking in wireless-hacking1.ppt
ethical hacking in wireless-hacking1.pptethical hacking in wireless-hacking1.ppt
ethical hacking in wireless-hacking1.ppt
Jayaprasanna4
 
Cosmetic shop management system project report.pdf
Cosmetic shop management system project report.pdfCosmetic shop management system project report.pdf
Cosmetic shop management system project report.pdf
Kamal Acharya
 
road safety engineering r s e unit 3.pdf
road safety engineering  r s e unit 3.pdfroad safety engineering  r s e unit 3.pdf
road safety engineering r s e unit 3.pdf
VENKATESHvenky89705
 
Final project report on grocery store management system..pdf
Final project report on grocery store management system..pdfFinal project report on grocery store management system..pdf
Final project report on grocery store management system..pdf
Kamal Acharya
 

Recently uploaded (20)

Railway Signalling Principles Edition 3.pdf
Railway Signalling Principles Edition 3.pdfRailway Signalling Principles Edition 3.pdf
Railway Signalling Principles Edition 3.pdf
 
Halogenation process of chemical process industries
Halogenation process of chemical process industriesHalogenation process of chemical process industries
Halogenation process of chemical process industries
 
Gen AI Study Jams _ For the GDSC Leads in India.pdf
Gen AI Study Jams _ For the GDSC Leads in India.pdfGen AI Study Jams _ For the GDSC Leads in India.pdf
Gen AI Study Jams _ For the GDSC Leads in India.pdf
 
H.Seo, ICLR 2024, MLILAB, KAIST AI.pdf
H.Seo,  ICLR 2024, MLILAB,  KAIST AI.pdfH.Seo,  ICLR 2024, MLILAB,  KAIST AI.pdf
H.Seo, ICLR 2024, MLILAB, KAIST AI.pdf
 
ethical hacking-mobile hacking methods.ppt
ethical hacking-mobile hacking methods.pptethical hacking-mobile hacking methods.ppt
ethical hacking-mobile hacking methods.ppt
 
Pile Foundation by Venkatesh Taduvai (Sub Geotechnical Engineering II)-conver...
Pile Foundation by Venkatesh Taduvai (Sub Geotechnical Engineering II)-conver...Pile Foundation by Venkatesh Taduvai (Sub Geotechnical Engineering II)-conver...
Pile Foundation by Venkatesh Taduvai (Sub Geotechnical Engineering II)-conver...
 
Forklift Classes Overview by Intella Parts
Forklift Classes Overview by Intella PartsForklift Classes Overview by Intella Parts
Forklift Classes Overview by Intella Parts
 
CME397 Surface Engineering- Professional Elective
CME397 Surface Engineering- Professional ElectiveCME397 Surface Engineering- Professional Elective
CME397 Surface Engineering- Professional Elective
 
DESIGN A COTTON SEED SEPARATION MACHINE.docx
DESIGN A COTTON SEED SEPARATION MACHINE.docxDESIGN A COTTON SEED SEPARATION MACHINE.docx
DESIGN A COTTON SEED SEPARATION MACHINE.docx
 
一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理
一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理
一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理
 
TECHNICAL TRAINING MANUAL GENERAL FAMILIARIZATION COURSE
TECHNICAL TRAINING MANUAL   GENERAL FAMILIARIZATION COURSETECHNICAL TRAINING MANUAL   GENERAL FAMILIARIZATION COURSE
TECHNICAL TRAINING MANUAL GENERAL FAMILIARIZATION COURSE
 
Hybrid optimization of pumped hydro system and solar- Engr. Abdul-Azeez.pdf
Hybrid optimization of pumped hydro system and solar- Engr. Abdul-Azeez.pdfHybrid optimization of pumped hydro system and solar- Engr. Abdul-Azeez.pdf
Hybrid optimization of pumped hydro system and solar- Engr. Abdul-Azeez.pdf
 
Quality defects in TMT Bars, Possible causes and Potential Solutions.
Quality defects in TMT Bars, Possible causes and Potential Solutions.Quality defects in TMT Bars, Possible causes and Potential Solutions.
Quality defects in TMT Bars, Possible causes and Potential Solutions.
 
block diagram and signal flow graph representation
block diagram and signal flow graph representationblock diagram and signal flow graph representation
block diagram and signal flow graph representation
 
weather web application report.pdf
weather web application report.pdfweather web application report.pdf
weather web application report.pdf
 
WATER CRISIS and its solutions-pptx 1234
WATER CRISIS and its solutions-pptx 1234WATER CRISIS and its solutions-pptx 1234
WATER CRISIS and its solutions-pptx 1234
 
ethical hacking in wireless-hacking1.ppt
ethical hacking in wireless-hacking1.pptethical hacking in wireless-hacking1.ppt
ethical hacking in wireless-hacking1.ppt
 
Cosmetic shop management system project report.pdf
Cosmetic shop management system project report.pdfCosmetic shop management system project report.pdf
Cosmetic shop management system project report.pdf
 
road safety engineering r s e unit 3.pdf
road safety engineering  r s e unit 3.pdfroad safety engineering  r s e unit 3.pdf
road safety engineering r s e unit 3.pdf
 
Final project report on grocery store management system..pdf
Final project report on grocery store management system..pdfFinal project report on grocery store management system..pdf
Final project report on grocery store management system..pdf
 

Java Notes by C. Sreedhar, GPREC

  • 2. Unit 1  Introduction: ◦ Over view of java, Java Buzzwords ◦ Data types, Variables and arrays, Operators  Control statements,  Classes and objects.  I/O: I/O Basics, Reading Console input,  writing Console output, Reading and Writing Files.  Inheritance: Basic concepts, uses super, method overriding, dynamic method dispatch,  Abstract class, using final, the object class.
  • 3. Unit 2  String Handling: ◦ String Constructors, Special String Operations-String Literals, String Concatenation, Character Extraction, String Comparisons. Searching Strings, Modifying a string.  String Buffer: ◦ String Buffer Constructors, length(), capacity(), set Length(),Character Extraction methods, append(),insert(),reverse(),delete(),replace(
  • 4. Unit 3  Packages and Interfaces:  Packages, Access protection, Importing packages, Interfaces.  Exception Handling: ◦ Fundamentals, Types of Exception, ◦ Usage of try, catch, throw throws ◦ finally, built in Exceptions.
  • 5. Unit 4  Multithreading: ◦ Concepts of multithreading, Main thread, creating thread and multiple threads,  Using isAlive() and join( ),  Thread Priorities, synchronization,  Interthread communication.
  • 6. Unit 5  Applets: ◦ Applet basics and Applet class.  Event Handling: ◦ Basic concepts, Event classes, Sources of events, Event listener Interfaces,  Handling mouse and keyboard events,  Adapter classes.  Abstract Window Toolkit (AWT) ◦ AWT classes, AWT Controls.
  • 7. Unit 6  Java Swings & JDBC: ◦ Introduction to Swing: JApplet, TextFields, Buttons, Combo Boxes, Tabbed Panes.  JDBC: Introduction to JDBC
  • 8. Books  TEXT BOOKS: ◦ Herbert Schildt [2008], [5th Edition], The Complete Reference Java2, TATA McGraw-Hill.(1,2,3,4,5,6 Units).  REFERENCE BOOKS: ◦ Bruce Eckel [2008], [2nd Edition], Thinking in Java, Pearson Education. ◦ H.M Dietel and P.J Dietel [2008], [6th Edition], Java How to Program, Pearson Ed. ◦ E. Balagurusamy, Programming with Java: A primer, III Edition, Tata McGraw- Hill, 2007.
  • 9. List of Lab Experiments 1. Implementing classes and Constructors concepts. 2. Program to implement Inheritance. 3. Program for Operations on Strings. 4. Program to design Packages. 5. Program to implement Interfaces. 6. Program to handle various types of exceptions. 7. Program to create Multithreading by extending Thread class. 8. Program to create Multithreading by implementing Runnable interface. 9. Program for Applets. 10. Program for Mouse Event Handling. 11. Program to implement Key Event Handling 12. Program to implement AWT Controls.
  • 10. Java Programming Examples  Program to print some text onto output screen.  Program to accept values from user
  • 11. Java Program: Example 1 public class firstex { public static void main(String []args) { System.out.println(“Java welcomes CSE 4A"); } }
  • 12. Dissection of Java Program  public : It is an Access Modifier, which defines who can access this method. Public means that this method will be accessible to any class(If other class can access this class.).  Access Modifier : ◦ default ◦ private ◦ public ◦ protected public class firstex { public static void main(String []args) { System.out.println(“Java welcomes CSE 4A"); } }
  • 13.  class - A class can be defined as a template/blue print that describes the behaviors/states that object of its type support.  static : Keyword which identifies the class related this. It means that the main() can be accessed without creating the instance of Class. public class firstex { public static void main(String []args) { System.out.println(“Java welcomes CSE 4A"); } }
  • 14.  void: is a return type, here it does not return any value.  main: Name of the method. This method name is searched by JVM as starting point for an application.  string args[ ]: The parameter is a String array by name args. The string array is used to access command-line arguments. public class firstex { public static void main(String []args) { System.out.println(“Java welcomes CSE 4A"); } }
  • 15.  System: ◦ system class provides facilities such as standard input, output and error streams.  out: ◦ out is an object of PrintStream class defined in System class  println(“ “); ◦ println() is a method of PrintStream class public class firstex { public static void main (String [ ] args) { System.out.println(“Java welcomes CSE 4A"); } }
  • 16. Possible Errors public class firstex  class  Class public class firstex  firstex  myex { public static void main (String [ ] args)  public  private { public static void main (String [ ] args)  static  { public static void main (String [ ] args) { system.out.println(“Java welcomes CSE 4A"); } }  system  System  out  Out  println  Println
  • 17. Program to take input from user  Ways to accept input from user: ◦ Using InputStreamReader class ◦ Using Scanner class ◦ Using BufferedReader class ◦ Using Console class
  • 18. Accept two numbers and display sumimport java.io.*; public class ex3 { public static void main(String ar[ ])throws IOException { InputStreamReader isr=new InputStreamReader(System.in); BufferedReader br=new BufferedReader(isr); System.out.println("Enter first value"); String s1=br.readLine(); System.out.println("Enter Second value"); String s2=br.readLine(); int a=Integer.parseInt(s1); int b=Integer.parseInt(s2); System.out.println("Addition = "+(a+b)); } } The Java.io.InputStreamReader class is a bridge from byte streams to character streams.It reads bytes and decodes them into characters using a specified charset. The Java.io.BufferedReader class reads text from a character-input stream, buffering characters so as to provide for the efficient reading of characters, arrays, and lines.
  • 19. Using Scanner Class import java.util.*; public class ex4 { public static void main(String ar[]) { Scanner scan=new Scanner(System.in); System.out.println("Enter first value"); int a=scan.nextInt(); System.out.println("Enter Second value"); int b=scan.nextInt(); System.out.println("Addition = "+(a+b)); } } The java.util.Scanner class is a simple text scanner which can parse primitive types and strings using regular expressions.
  • 20. Using Console import java.io.*; class consoleex { public static void main(String args[]) { Console c=System.console(); System.out.println("Enter your name: "); String n=c.readLine(); System.out.println("Enter password: "); char[ ] ch=c.readPassword(); String pass=String.valueOf(ch);//converting char array into string System.out.println(“Hai Mr. "+n); System.out.println(“Ur Password is: "+pass); } }
  • 21. Using BufferedReader class import java.io.*; class ex2 { public static void main(String[ ] args) { BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); String name = “ “; System.out.print(“Enter your name: "); try { name = in.readLine(); } catch(Exception e) { System.out.println("Caught an exception!"); } System.out.println("Hello " + name + "!"); } }
  • 23. Programming Languages:  Machine Language  Assembly Language  High level Language
  • 24. Machine language: • It is the lowest-level programming language. • Machine languages are the only languages understood by computers. For example, to add two numbers, you might write an instruction in binary like this: 1101101010011010
  • 25. Assembly Language  It implements a symbolic representation of the numeric machine codes and other constants needed to program a particular CPU architecture.  Assembly Program to add two numbers: name "add" mov al, 5 ; bin=00000101b mov bl, 10 ; hex=0ah or bin=00001010b add bl, al ; 5 + 10 = 15 (decimal) or hex=0fh or bin=00001111b  MASM  TASM
  • 26. … ADDF3 R1, R2, R3 … Assembly Source File Assembler … 1101101010011010 … Machine Code File
  • 28. Compiler  A compiler translates the entire source code into a machine-code file … area = 5 * 5 * 3.1415; ... High-level Source File Compiler Executor Output… 0101100011011100 1111100011000100 … ... Machine-code File
  • 29. Interpreter  An interpreter reads one statement from the source code, translates it to the machine code or virtual machine code, and then executes it. … area = 5 * 5 * 3.1415; ... High-level Source File Interpreter Output
  • 30. What is Java  Java is a computer programming language that is concurrent, object-oriented.  It is intended to let application developers "write once, run anywhere" (WORA), meaning that code that runs on one platform does not need to be recompiled to run on another.  Java applications are typically compiled to bytecode (class file) that can run on any Java virtual machine (JVM) regardless of computer architecture.  Java is a general purpose programming language.  Java is the Internet programming language.
  • 31. Where is Java used?
  • 32. Usage of Java in Applets : Example
  • 33. Usage of Java in Mobile Phones and PDA
  • 34. Usage of Java in Self Test Websites
  • 35.
  • 36. Prerequisites to be known for Java  How to check whether java is present in the system or not.  How to install java in your machine.  How to set path for java  Check whether java is installed correctly or not.  What is JVM
  • 37. Introduction to Java  “B” led to “C”, “C” evolved into “C++” and “C++ set the stage for Java.  Java is a high level language like C, C++ and Visual Basic.  Java is a programming language originally developed by James Gosling at Sun Microsystems (which has since merged into Oracle Corporation) and released in 1995 as a core component of Sun Microsystems' Java platform. 20 December 2015 C Sreedhar Java Programming Lecture Notes 2015 – 2016 IV Semester 37
  • 38.  Java was conceived by ◦ James Gosling, ◦ Patrick Naughton, ◦ Chris Warth, ◦ Ed Frank and ◦ Mike Sheridan at Sun Microsystems, Inc in 1991.  It took 18 months to develop the first working version.  Initially called “Oak”,a tree; “Green”; renamed as “Java”, cofee in 1995.  The language derives much of its syntax from C and C++. 20 December 2015 38
  • 39.  Motivation and Objective of Java: “Need for a platform-independent (architecture- neutral) language.  Java applications are typically compiled to bytecode (class file) that can run on any Java virtual machine (JVM) regardless of computer architecture.  Java was originally designed for interactive television, but it was too advanced for the digital cable television industry at the time.  To create a software which can be embedded in various consumer electronic 20 December 2015 39
  • 40. Bytecode  The output of Java compiler is NOT executable code, rather it is called as bytecode.  Bytecode is a highly optimized set of instructions designed to be executed by the Java run-time system, called as Java Virtual Machine (JVM).  JVM is an interpreter for bytecode. 20 December 2015 40
  • 41.
  • 43. Characteristics of Java / Buzzwords Java Is Simple  Java Is Object-Oriented  Java Is Distributed  Java Is Interpreted  Java Is Robust  Java Is Secure  Java Is Architecture-Neutral  Java Is Portable  Java's Performance  Java Is Multithreaded  Java Is Dynamic 20 December 2015 43
  • 44. Characteristics of Java  Java Is Simple  Java Is Object-Oriented  Java Is Distributed  Java Is Interpreted  Java Is Robust  Java Is Secure  Java Is Architecture- Neutral  Java Is Portable  Java's Performance  Java Is Multithreaded  Java Is Dynamic 20 December 2015 44 Java is partially modeled on C++, but greatly simplified and improved. Some people refer to Java as "C++--" because it is like C++ but with more functionality and fewer negative aspects.
  • 45. Characteristics of Java  Java Is Simple  Java Is Object-Oriented  Java Is Distributed  Java Is Interpreted  Java Is Robust  Java Is Secure  Java Is Architecture- Neutral  Java Is Portable  Java's Performance  Java Is Multithreaded  Java Is Dynamic 20 December 2015 45 Java is inherently object-oriented. Although many object-oriented languages began strictly as procedural languages, Java was designed from the start to be object-oriented. Object-oriented programming (OOP) is a popular programming approach that is replacing traditional procedural programming techniques. One of the central issues in software development is how to reuse code. Object-oriented programming provides great flexibility, modularity, clarity, and reusability through encapsulation, inheritance, and polymorphism.
  • 46. Characteristics of Java  Java Is Simple  Java Is Object-Oriented  Java Is Distributed  Java Is Interpreted  Java Is Robust  Java Is Secure  Java Is Architecture- Neutral  Java Is Portable  Java's Performance  Java Is Multithreaded  Java Is Dynamic 20 December 2015 46 Distributed computing involves several computers working together on a network. Java is designed to make distributed computing easy. Since networking capability is inherently integrated into Java, writing network programs is like sending and receiving data to and from a file.
  • 47. Characteristics of Java  Java Is Simple  Java Is Object-Oriented  Java Is Distributed  Java Is Interpreted  Java Is Robust  Java Is Secure  Java Is Architecture- Neutral  Java Is Portable  Java's Performance  Java Is Multithreaded  Java Is Dynamic 20 December 2015 47 You need an interpreter to run Java programs. The programs are compiled into the Java Virtual Machine code called bytecode. The bytecode is machine-independent and can run on any machine that has a Java interpreter, which is part of the Java Virtual Machine (JVM).
  • 48. Characteristics of Java  Java Is Simple  Java Is Object-Oriented  Java Is Distributed  Java Is Interpreted  Java Is Robust  Java Is Secure  Java Is Architecture- Neutral  Java Is Portable  Java's Performance  Java Is Multithreaded  Java Is Dynamic 20 December 2015 48 Java compilers can detect many problems that would first show up at execution time in other languages. Java has eliminated certain types of error-prone programming constructs found in other languages. Java has a runtime exception- handling feature to provide programming support for robustness.
  • 49. Characteristics of Java  Java Is Simple  Java Is Object-Oriented  Java Is Distributed  Java Is Interpreted  Java Is Robust  Java Is Secure  Java Is Architecture- Neutral  Java Is Portable  Java's Performance  Java Is Multithreaded  Java Is Dynamic 20 December 2015 49 Java implements several security mechanisms to protect your system against harm caused by stray programs.
  • 50. Characteristics of Java  Java Is Simple  Java Is Object-Oriented  Java Is Distributed  Java Is Interpreted  Java Is Robust  Java Is Secure  Java Is Architecture- Neutral  Java Is Portable  Java's Performance  Java Is Multithreaded  Java Is Dynamic 20 December 2015 50 Write once, run anywhere With a Java Virtual Machine (JVM), you can write one program that will run on any platform.
  • 51. Characteristics of Java  Java Is Simple  Java Is Object-Oriented  Java Is Distributed  Java Is Interpreted  Java Is Robust  Java Is Secure  Java Is Architecture- Neutral  Java Is Portable  Java's Performance  Java Is Multithreaded  Java Is Dynamic 20 December 2015 51 Because Java is architecture neutral, Java programs are portable. They can be run on any platform without being recompiled.
  • 52. Characteristics of Java  Java Is Simple  Java Is Object-Oriented  Java Is Distributed  Java Is Interpreted  Java Is Robust  Java Is Secure  Java Is Architecture- Neutral  Java Is Portable  Java's Performance  Java Is Multithreaded  Java Is Dynamic 20 December 2015 52 Java’s performance Because Java is architecture neutral, Java programs are portable. They can be run on any platform without being recompiled.
  • 53. Characteristics of Java  Java Is Simple  Java Is Object-Oriented  Java Is Distributed  Java Is Interpreted  Java Is Robust  Java Is Secure  Java Is Architecture- Neutral  Java Is Portable  Java's Performance  Java Is Multithreaded  Java Is Dynamic 20 December 2015 53 Multithread programming is smoothly integrated in Java, whereas in other languages you have to call procedures specific to the operating system to enable multithreading.
  • 54. Characteristics of Java  Java Is Simple  Java Is Object-Oriented  Java Is Distributed  Java Is Interpreted  Java Is Robust  Java Is Secure  Java Is Architecture- Neutral  Java Is Portable  Java's Performance  Java Is Multithreaded  Java Is Dynamic 20 December 2015 54 Java was designed to adapt to an evolving environment. New code can be loaded on the fly without recompilation. There is no need for developers to create, and for users to install, major new software versions. New features can be incorporated transparently as needed.
  • 55. Lab Program  write a java program to display total marks of 5 students using student class. Given the following attributes: Regno(int), Name(string), Marks in subjects(Integer Array), Total (int).
  • 56. Expected Output Enter the no. of students: 2 Enter the Reg.No: 1234 Enter the Name: name Enter the Mark1: 88 Enter the Mark2: 99 Enter the Mark3: 89 Enter the Reg.No: 432 Enter the Name: name Enter the Mark1: 67 Enter the Mark2: 68 Enter the Mark3: 98 Mark List ********* RegNo Name Mark1 Mark2 Mark3 Total 1234 name 88 99 89 276 432 name 67 68 98 233
  • 57. Outline of the Program class Student { // Variable declarations void readinput() throws IOException { // Use BufferedReader class to accept input from keyboard } void display() { } } class Mark { public static void main(String args[]) throws IOException { // body of main method } }
  • 58. import java.io.*; class Student { int regno,total; String name; int mark[ ]=new int[3]; void readinput() throws IOException { BufferedReader din=new BufferedReader(new InputStreamReader(System.in)); System.out.print("nEnter the Reg.No: "); regno=Integer.parseInt(din.readLine()); System.out.print("Enter the Name: "); name=din.readLine(); System.out.print("Enter the Mark1: "); mark[0]=Integer.parseInt(din.readLine()); System.out.print("Enter the Mark2: "); mark[1]=Integer.parseInt(din.readLine()); System.out.print("Enter the Mark3: "); mark[2]=Integer.parseInt(din.readLine()); total=mark[0]+mark[1]+mark[2]; }
  • 59. void display() { System.out.println(regno+"t"+name+"tt"+mark[0]+"t"+mark[1]+"t"+mark[2]+"t"+total); } } class Mark { public static void main(String args[]) throws IOException { int size; BufferedReader din=new BufferedReader(new InputStreamReader(System.in)); System.out.print("Enter the no. of students: "); size=Integer.parseInt(din.readLine()); Student s[]=new Student[size]; for(int i=0;i<size;i++) { s[i]=new Student(); s[i].readinput(); } System.out.println("tttMark List"); System.out.println("ttt*********"); System.out.println("RegNotNamettMark1tMark2tMark3tTotal"); for(int i=0;i<size;i++) s[i].display(); } }
  • 60. Lab Program: Complex number Arithmetic public class ComplexNumber { // declare variables Default Constructor definition { } Parameterized constructor definition { } Use method getComplexValue() to display in complex number form { }
  • 61. public static String addition(ComplexNumber num1, ComplexNumber num2) { // Code for complex number addition } public static String subtraction(ComplexNumber num1, ComplexNumber num2) { // Code for complex number subtraction } public static String multiplication(ComplexNumber num1, ComplexNumber num2) { // Code for complex number multiplication } public static String multiplication(ComplexNumber num1, ComplexNumber num2) { // create objects and call to parameterized constructors // call to respective methods }
  • 62. Lab Program: Complex number Arithmeticimport java.io.*; public class ComplexNumber { private int a; private int b; public ComplexNumber() { } public ComplexNumber(int a, int b) { this.a =a; this.b=b; } public String getComplexValue() { if(this.b < 0) { return a+""+b+"i"; } else { return a+"+"+b+"i"; } }
  • 63. public static String addition(ComplexNumber num1, ComplexNumber num2) { int a1= num1.a+num2.a; int b1= num1.b+num2.b; if(b1<0) { return a1+""+b1+"i"; } else { return a1+"+"+b1+"i"; } }
  • 64. public static String substraction(ComplexNumber num1, ComplexNumber num2) { int a1= num1.a-num2.a; int b1= num1.b-num2.b; if(b1<0){ return a1+""+b1+"i"; } else { return a1+"+"+b1+"i"; } }
  • 65. public static String multiplication(ComplexNumber num1, ComplexNumber num2) { int a1= num1.a*num2.a; int b1= num1.b*num2.b; int vi1 = num1.a * num2.b; int vi2 = num2.a * num1.b; int vi; vi=vi1+vi2; if(vi<0) { return a1-b1+""+vi+"i"; } else { return a1-b1+"+"+vi+"i"; } }
  • 66. public static void main(String args[]) { ComplexNumber com1 = new ComplexNumber(2,4); ComplexNumber com2 = new ComplexNumber(6,8); System.out.println(com1.getComplexValue()); System.out.println(com2.getComplexValue()); System.out.println("Addition of both Complex Numbers are :"+ComplexNumber.addition(com1,com2)); System.out.println("Substraction of both Complex Numbers are :"+ComplexNumber.substraction(com1,com2)); System.out.println("Multiplication of both Complex Numbers are :"+ComplexNumber.multiplication(com1,com2)); } }