[go: up one dir, main page]

0% found this document useful (0 votes)
10 views53 pages

Java Unit 4

The document discusses Java threads and exception handling. It covers topics like thread life cycle and methods, multithreading concepts like thread synchronization, and exception handling using try-catch blocks. Code examples are provided to demonstrate thread creation and synchronization.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views53 pages

Java Unit 4

The document discusses Java threads and exception handling. It covers topics like thread life cycle and methods, multithreading concepts like thread synchronization, and exception handling using try-catch blocks. Code examples are provided to demonstrate thread creation and synchronization.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 53

UNIT- 4

JAVA THREADS AND EXCEPTION


HANDLING

04/16/2024
SYLLABUS

Thread - Thread life cycle and methods, Runnable interface, Multi-


threading - Thread synchronization, Exception handling with try-catch-
finally – Nested try-catch – User defined Exception – Files – IO streams

04/16/2024
THREADS IN JAVA

04/16/2024
MULTITHREADING IN JAVA

• Multithreading in Java is a process of executing multiple threads


simultaneously.
• A thread is a lightweight sub-process, the smallest unit of processing.
Multiprocessing and multithreading, both are used to achieve
multitasking.
• we use multithreading than multiprocessing because threads use a
shared memory area.
• They don't allocate separate memory area so saves memory, and
context-switching between the threads takes less time than process.
• Java Multithreading is mostly used in games, animation, etc.
04/16/2024
ADVANTAGES OF JAVA MULTITHREADING

• It doesn't block the user because threads are independent and you can perform
multiple operations at the same time.
• You can perform many operations together, so it saves time.
• Threads are independent, so it doesn't affect other threads if an exception
occurs in a single thread.
MULTITASKING
• Multitasking is a process of executing multiple tasks simultaneously. We use
multitasking to utilize the CPU. Multitasking can be achieved in two ways:
• Process-based Multitasking (Multiprocessing)
• Thread-based Multitasking (Multithreading)
04/16/2024
Process-based Multitasking (Multiprocessing)
Each process has an address in memory. In other words, each process allocates a separate
memory area.

A process is heavyweight.

Cost of communication between the process is high.

Switching from one process to another requires some time for saving and loading
registers, memory maps, updating lists, etc.

04/16/2024
Thread-based Multitasking (Multithreading)
Threads share the same address space.

A thread is lightweight.

Cost of communication between the thread is low.


Note: At least one process is required for each thread.

What is Thread in java


A thread is a lightweight subprocess, the smallest unit of processing. It is a separate path of execution.

Threads are independent. If there occurs exception in one thread, it doesn't affect other threads. It uses
a shared memory area.
04/16/2024
Java Thread class
• Java provides Thread class to achieve thread programming.
• Thread class provides constructors and methods to create and perform operations
on a thread.
• Thread class extends Object class and implements Runnable interface.
Life cycle of a Thread (Thread States)
• A thread can be in one of the five states.
• According to sun, there is only 4 states in thread life cycle in java new, runnable,
non-runnable and terminated.
• There is no running state.
• The life cycle of the thread in java is controlled by JVM.

04/16/2024
• The java thread states are as follows:

• New

• Runnable

• Running

• Non-Runnable (Blocked)

• Terminated

04/16/2024
New
• The thread is in new state if you create an instance of Thread class but before the
invocation of start() method.
Runnable
• The thread is in runnable state after invocation of start() method, but the thread
scheduler has not selected it to be the running thread.
Running
• The thread is in running state if the thread scheduler has selected it.
Non-Runnable (Blocked)
• This is the state when the thread is still alive, but is currently not eligible to run.
Terminated
• A thread is in terminated or dead state when its run() method exits.

04/16/2024
How to create thread
• There are two ways to create a thread:
• By extending Thread class
• By implementing Runnable interface.
Thread class:
• Thread class provide constructors and methods to create and perform operations
on a thread.Thread class extends Object class and implements Runnable
interface.
Commonly used Constructors of Thread class:
• Thread()
• Thread(String name)
• Thread(Runnable r)
• Thread(Runnable r,String name)
04/16/2024
Commonly used methods of Thread class:

04/16/2024
Runnable interface:
• The Runnable interface should be implemented by any class whose instances are
intended to be executed by a thread. Runnable interface have only one method
named run().
public void run(): is used to perform action for a thread.

Starting a thread:
• start() method of Thread class is used to start a newly created thread. It performs
following tasks:
• A new thread starts(with new callstack).
• The thread moves from New state to the Runnable state.
• When the thread gets a chance to execute, its target run() method will run.

04/16/2024
Java Thread Example by extending Thread class
class Multi extends Thread{
public void run(){
System.out.println("thread is running...");
}
public static void main(String args[]){
Multi t1=new Multi();
t1.start();
} }

Java Thread Example by implementing Runnable interface


class Multi3 implements Runnable{
public void run(){
System.out.println("thread is running...");
}

public static void main(String args[]){


Multi3 m1=new Multi3();
Thread t1 =new Thread(m1);
t1.start();
} }
04/16/2024
Synchronization in Java
• Synchronization in java is the capability to control the access of multiple threads to
any shared resource.
• Java Synchronization is better option where we want to allow only one thread to
access the shared resource.
Why use Synchronization
• The synchronization is mainly used to
• To prevent thread interference.
• To prevent consistency problem.
Types of Synchronization
• There are two types of synchronization
• Process Synchronization
• Thread Synchronization
Here, we will discuss only thread synchronization.
04/16/2024
Thread Synchronization
• There are two types of thread synchronization mutual exclusive and inter-thread
communication.
• Mutual Exclusive
• Synchronized method.
• Synchronized block.
• static synchronization.
• Cooperation (Inter-thread communication in java)
Concept of Lock in Java
• Synchronization is built around an internal entity known as the lock or monitor.
• Every object has an lock associated with it.
• By convention, a thread that needs consistent access to an object's fields has to acquire
the object's lock before accessing them, and then release the lock when it's done with
them.
04/16/2024
Java synchronized method
• If you declare any method as synchronized, it is known as synchronized method.
class Table{ class MyThread2 extends Thread{
synchronized void printTable(int Table t;
n){//synchronized method MyThread2(Table t){
for(int i=1;i<=5;i++){ this.t=t;
System.out.println(n*i); }
try{ public void run(){
Thread.sleep(400); t.printTable(100);
}catch(Exception e){System.out.println(e);} }
} } } }
class MyThread1 extends Thread{ public class TestSynchronization2{
Table t; public static void main(String args[]){
MyThread1(Table t){ Table obj = new Table();//only one object
this.t=t; MyThread1 t1=new MyThread1(obj);
} MyThread2 t2=new MyThread2(obj);
public void run(){ t1.start();
t.printTable(5); t2.start();
} } }
}
04/16/2024
Example of synchronized method by using annonymous class
class Table{
synchronized void printTable(int Thread t1=new Thread(){
n){//synchronized method public void run(){
for(int i=1;i<=5;i++){ obj.printTable(5);
System.out.println(n*i); }
try{ };
Thread.sleep(400); Thread t2=new Thread(){
}catch(Exception e){System.out.println(e);} public void run(){
} obj.printTable(100);
}
} };
}
public class TestSynchronization3{ t1.start();
public static void main(String args[]){ t2.start();
final Table obj = new Table();//only one object }
}

04/16/2024
Synchronized Block in Java
• Synchronized block can be used to perform synchronization on any specific
resource of the method.
• Syntax:
synchronized (object reference expression) {
//code block
}

04/16/2024
class Table{ class MyThread2 extends Thread{
void printTable(int n){ Table t;
synchronized(this){//synchronized block MyThread2(Table t){
for(int i=1;i<=5;i++){ this.t=t;
System.out.println(n*i); }
try{
public void run(){
Thread.sleep(400);
t.printTable(100);
}catch(Exceptione){System.out.println(e);}
} }
} }
public class TestSynchronizedBlock1{
}}
public static void main(String args[]){
class MyThread1 extends Thread{
Table obj = new Table();//only one object
Table t;
MyThread1 t1=new MyThread1(obj);
MyThread1(Table t){
this.t=t; MyThread2 t2=new MyThread2(obj);
} t1.start();
public void run(){ t2.start();
t.printTable(5); }
} } }
04/16/2024
Static Synchronization
class Table{ class MyThread4 extends Thread{
synchronized static void printTable(int n){ public void run(){
for(int i=1;i<=10;i++){ Table.printTable(1000);
System.out.println(n*i); }
try{ }
Thread.sleep(400); public class TestSynchronization4{
}catch(Exception e){} public static void main(String t[]){
} } } MyThread1 t1=new MyThread1();
class Table{ MyThread2 t2=new MyThread2();
synchronized static void printTable(int n){ MyThread3 t3=new MyThread3();
for(int i=1;i<=10;i++){ MyThread4 t4=new MyThread4();
System.out.println(n*i); t1.start();
try{ t2.start();
Thread.sleep(400); t3.start();
}catch(Exception e){} t4.start();
}04/16/2024
} } } }
Exception Handling in Java
• The Exception Handling in Java is one of the powerful mechanism to handle the
runtime errors so that normal flow of the application can be maintained.
Advantage of Exception Handling
• Maintain the normal flow of the application.
statement 1;
statement 2;
statement 3;
statement 4;
statement 5;//exception occurs

statement 6;
statement 7;
statement 8;
statement 9;
statement 10;

04/16/2024
Hierarchy of Java Exception classes

04/16/2024
Types of Java Exceptions
• Checked Exception
• Unchecked Exception
• Error
1) Checked Exception
The classes which directly inherit Throwable class except RuntimeException and Error are known as
checked exceptions e.g. IOException, SQLException etc. Checked exceptions are checked at
compile-time.
2) Unchecked Exception
The classes which inherit RuntimeException are known as unchecked exceptions e.g.
ArithmeticException, NullPointerException, ArrayIndexOutOfBoundsException etc. Unchecked
exceptions are not checked at compile-time, but they are checked at runtime.
3) Error
Error is irrecoverable e.g. OutOfMemoryError, VirtualMachineError, AssertionError etc.

04/16/2024
Java Exception Keywords
• There are 5 keywords which are used in handling exceptions in Java.
Keyword Description
try The "try" keyword is used to specify a block where we should place exception
code. The try block must be followed by either catch or finally. It means, we
can't use try block alone.
catch The "catch" block is used to handle the exception. It must be preceded by try
block which means we can't use catch block alone. It can be followed by
finally block later.
finally The "finally" block is used to execute the important code of the program. It is
executed whether an exception is handled or not.
throw The "throw" keyword is used to throw an exception.
throws The "throws" keyword is used to declare exceptions. It doesn't throw an
exception. It specifies that there may occur an exception in the method. It is
always used with method signature.

04/16/2024
Java Exception Handling Example

public class JavaExceptionExample{


public static void main(String args[]){
try{
//code that may raise exception
int data=100/0;
}catch(ArithmeticExceptione)
{System.out.println(e);}
//rest code of the program
System.out.println("rest of the code...");
}
}

04/16/2024
Java try-catch block
• Java try block is used to enclose the code that might throw an exception. It must
be used within the method.
• Java catch block is used to handle the Exception by declaring the type of
exception within the parameter.
• The declared exception must be the parent class exception ( i.e., Exception) or the
generated exception type.
public class TryCatchExample2 {
public static void main(String[] args) {
try
{
int data=50/0; //may throw exception }
//handling the exception
catch(ArithmeticException e)
{
System.out.println(e);
}
System.out.println("rest of the code");
04/16/2024
} }
Java Nested try block
• The try block within a try block is known as nested try block in java.
class Excep6{
public static void main(String args[]){
try{
try{
System.out.println("going to divide");
int b =39/0;
}catch(ArithmeticException e){System.out.println(e);}

try{
int a[]=new int[5];
a[5]=4;
}catch(ArrayIndexOutOfBoundsException e)
{System.out.println(e);}

System.out.println("other statement);
}catch(Exception e){System.out.println("handeled");}

System.out.println("normal flow..");
04/16/2024
} }
Java finally block
• Java finally block is a block that is used to execute important code such as closing
connection, stream etc.
• Java finally block is always executed whether exception is handled or not.
• Java finally block follows try or catch block.
//exception not occured //not handled
class TestFinallyBlock{ class TestFinallyBlock1{
public static void main(String args[]){ public static void main(String args[]){
try{ try{
int data=25/5; int data=25/0;
System.out.println(data); System.out.println(data);
} }
catch(NullPointerException e) catch(NullPointerException e)
{System.out.println(e);} {System.out.println(e);}
finally{System.out.println("finally block finally{System.out.println("finally block is
is always executed");} always executed");}
System.out.println("rest of the code..."); System.out.println("rest of the code...");
} }
04/16/2024 } }
//Exception occured and handled
public class TestFinallyBlock2{
public static void main(String args[]){
try{
int data=25/0;
System.out.println(data);
}
catch(ArithmeticException e)
{System.out.println(e);}
finally{System.out.println("finally block
is always executed");}
System.out.println("rest of the code...");
}
}

04/16/2024
Java throw keyword
• The Java throw keyword is used to explicitly throw an exception.
• We can throw either checked or uncheked exception in java by throw keyword.
• The throw keyword is mainly used to throw custom exception.
public class TestThrow1{
static void validate(int age){
if(age<18)
throw new ArithmeticException("not
valid");
else
System.out.println("welcome to vote");
}
public static void main(String args[]){
validate(13);
System.out.println("rest of the code...");
}
}
04/16/2024
Java Custom Exception
• If you are creating your own Exception that is known as custom
exception or user-defined exception.
• Java custom exceptions are used to customize the exception
according to user need. class TestCustomException1{
class InvalidAgeException extends Exception{ static void validate(int age)throws
InvalidAgeException(String s){ InvalidAgeException{
super(s); if(age<18)
} throw new InvalidAgeException("not valid");
} else
System.out.println("welcome to vote");
}
public static void main(String args[]){
try{
validate(13);
}catch(Exceptionm){System.out.println("Exception
occured: "+m);}
System.out.println("rest of the code...");
04/16/2024
} }
Java File Class
• The File class is an abstract representation of file and directory pathname.
• A pathname can be either absolute or relative.
• The File class have several methods for working with directories and files such as
creating new directories or files, deleting and renaming directories or files, listing
the contents of a directory etc.
Fields
Modifier Type Field Description
static String pathSeparator It is system-dependent path-separator character,
represented as a string for convenience.
static char pathSeparatorChar It is system-dependent path-separator character.
static String separator It is system-dependent default name-separator character,
represented as a string for convenience.
static char separatorChar It is system-dependent default name-separator character.

04/16/2024
Constructors

Modifier Type Field Description


static String pathSeparator It is system-dependent path-separator character, represented as
a string for convenience.
static char pathSeparatorChar It is system-dependent path-separator character.
static String separator It is system-dependent default name-separator character,
represented as a string for convenience.
static char separatorChar It is system-dependent default name-separator character.

04/16/2024
Useful Methods
Modifier and Type Method Description

static File createTempFile(String prefix, It creates an empty file in the default temporary-file directory, using the given prefix and suffix to generate its name.
String suffix)

boolean createNewFile() It atomically creates a new, empty file named by this abstract pathname if and only if a file with this name does not yet exist.

boolean canWrite() It tests whether the application can modify the file denoted by this abstract pathname.String[]

boolean canExecute() It tests whether the application can execute the file denoted by this abstract pathname.

boolean canRead() It tests whether the application can read the file denoted by this abstract pathname.

boolean isAbsolute() It tests whether this abstract pathname is absolute.

boolean isDirectory() It tests whether the file denoted by this abstract pathname is a directory.

boolean isFile() It tests whether the file denoted by this abstract pathname is a normal file.

String getName() It returns the name of the file or directory denoted by this abstract pathname.

String getParent() It returns the pathname string of this abstract pathname's parent, or null if this pathname does not name a parent directory.

Path toPath() It returns a java.nio.file.Path object constructed from the this abstract path.

URI toURI() It constructs a file: URI that represents this abstract pathname.

File[] listFiles() It returns an array of abstract pathnames denoting the files in the directory denoted by this abstract pathname

long getFreeSpace() It returns the number of unallocated bytes in the partition named by this abstract path name.

String[] list(FilenameFilter filter) It returns an array of strings naming the files and directories in the directory denoted by this abstract pathname that satisfy the specified filter.

boolean mkdir() It creates the directory named by this abstract pathname.

04/16/2024
import java.io.*;
public class FileDemo {
public static void main(String[] args) {

try {
File file = new File("javaFile123.txt");
if (file.createNewFile()) {
System.out.println("New File is
created!");
} else {
System.out.println("File already exists.");
}
} catch (IOException e) {
e.printStackTrace();
}

}
}

04/16/2024
Java I/O Streams
• In Java, streams are the sequence of data that are read from the source
and written to the destination.
• An input stream is used to read data from the source. And, an output
stream is used to write data to the destination.
class HelloWorld {
public static void main(String[] args) {
System.out.println("Hello, World!");
}
}

Types of Streams
• Byte Stream
• Character Stream
04/16/2024
Byte Stream
• Byte stream is used to read and write a single byte (8 bits) of data.
• All byte stream classes are derived from base abstract classes called
InputStream and OutputStream.
// Read byte from the input stream
import java.io.FileInputStream;
input.read(array);
import java.io.InputStream;
System.out.println("Data read from
the file: ");
public class Main {
public static void main(String args[]) {
// Convert byte array into string
String data = new String(array);
byte[] array = new byte[100];
System.out.println(data);
try {
// Close the input stream
InputStream input = new FileInputStream("input.txt");
input.close();
}
System.out.println("Available bytes in the file: " +
catch (Exception e) {
input.available());
e.getStackTrace();
}}}
04/16/2024
import java.io.FileOutputStream;
import java.io.OutputStream;

public class Main {


public static void main(String args[]) {
String data = "This is a line of text inside the file.";
try {
OutputStream out = new FileOutputStream("output.txt");
// Converts the string into bytes
byte[] dataBytes = data.getBytes();
// Writes data to the output stream
out.write(dataBytes);
System.out.println("Data is written to the file.");
// Closes the output stream
out.close();
}
catch (Exception e) {
e.getStackTrace();
}
}
04/16/2024
}
CharacterStream Classes in Java
• The java.io package provides CharacterStream classes to overcome the limitations
of ByteStream classes, which can only handle the 8-bit bytes and is not compatible
to work directly with the Unicode characters.
• CharacterStream classes are used to work with 16-bit Unicode characters.
• They can perform operations on characters, char arrays and Strings.
• The CharacterStream classes are mainly used to read characters from the source and
write them to the destination.
• The CharacterStream classes are divided into two types of classes, I.e., Reader class
and Writer class.
Reader Class
• Reader class is used to read the 16-bit characters from the input stream.
• It is an abstract class and can't be instantiated, but there are various subclasses that
inherit the Reader class and override the methods of the Reader class.
04/16/2024
SN Class Description
1. BufferedReader This class provides methods to read characters from the buffer.
2. CharArrayReader This class provides methods to read characters from the char array.
3. FileReader This class provides methods to read characters from the file.
4. FilterReader This class provides methods to read characters from the underlying character
input stream.
5 InputStreamReader This class provides methods to convert bytes to characters.
6 PipedReader This class provides methods to read characters from the connected piped output
stream.
7 StringReader This class provides methods to read characters from a string.

04/16/2024
SN Method Description
1 int read() This method returns the integral representation of the next
character present in the input. It returns -1 if the end of the input
is encountered.
2 int read(char buffer[]) This method is used to read from the specified buffer. It returns
the total number of characters successfully read. It returns -1 if the
end of the input is encountered.
3 int read(char buffer[], int loc, int nChars) This method is used to read the specified nChars from the buffer at
the specified location. It returns the total number of characters
successfully read.
4 void mark(int nchars) This method is used to mark the current position in the input
stream until nChars characters are read.
5 void reset() This method is used to reset the input pointer to the previous set
mark.
6 long skip(long nChars) This method is used to skip the specified nChars characters from
the input stream and returns the number of characters skipped.
7 boolean ready() This method returns a boolean value true if the next request of
input is ready. Otherwise, it returns false.
8 void close() This method is used to close the input stream. However, if the
program attempts to access the input, it generates IOException.

04/16/2024
Writer Class
• Writer class is used to write 16-bit Unicode characters to the output stream.
• The methods of the Writer class generate IOException.
• Like Reader class, Writer class is also an abstract class that cannot be instantiated;
therefore, the subclasses of the Writer class are used to write the characters onto
the output stream.
SN Class Description
1 BufferedWriter This class provides methods to write characters to the buffer.
2 FileWriter This class provides methods to write characters to the file.
3 CharArrayWriter This class provides methods to write the characters to the character
array.
4 OutpuStreamWrite This class provides methods to convert from bytes to characters.
r
5 PipedWriter This class provides methods to write the characters to the piped output
stream.
6 StringWriter This class provides methods to write the characters to the string.
04/16/2024
SN Method Description
1 void write() This method is used to write the data to the output stream.
2 void write(int i) This method is used to write a single character to the
output stream.
3 Void write(char buffer[]) This method is used to write the array of characters to the
output stream.
4 void write(char buffer [],int loc, int nChars) This method is used to write the nChars characters to the
character array from the specified location.
5 void close () This method is used to close the output stream. However,
this generates the IOException if an attempt is made to
write to the output stream after closing the stream.
6 void flush () This method is used to flush the output stream and writes
the waiting buffered characters.

04/16/2024
04/16/2024
Java.io.BufferedReader Class in Java
• Reads text from a character-input stream, buffering characters so as to provide for
the efficient reading of characters, arrays, and lines.

• The buffer size may be specified, or the default size may be used. The default
is large enough for most purposes.
• In general, each read request made of a Reader causes a corresponding read
request to be made of the underlying character or byte stream.
• It is therefore advisable to wrap a BufferedReader around any Reader whose
read() operations may be costly, such as FileReaders and InputStreamReaders.
• Programs that use DataInputStreams for textual input can be localized by
replacing each DataInputStream with an appropriate BufferedReader.

04/16/2024
Constructors:
• BufferedReader(Reader in) : Creates a buffering character-input stream that uses a
default-sized input buffer.
• BufferedReader(Reader in, int sz) : Creates a buffering character-input stream that
uses an input buffer of the specified size.
Methods:
• void close() : Closes the stream and releases any system resources associated with
it.Once the stream has been closed, further read(), ready(), mark(), reset(), or skip()
invocations will throw an IOException. Closing a previously closed stream has no
effect.
• void mark(int readAheadLimit) : Marks the present position in the
stream.Subsequent calls to reset() will attempt to reposition the stream to this point.
• boolean markSupported() : Tells whether this stream supports the mark() operation,
which it does.
04/16/2024
• int read() : Reads a single character.
• int read(char[] cbuf, int off, int len) : Reads characters into a portion of an array.
• This method implements the general contract of the corresponding read method of the
Reader class. As an additional convenience, it attempts to read as many characters as
possible by repeatedly invoking the read method of the underlying stream. This
iterated read continues until one of the following conditions becomes true:
• The specified number of characters have been read,
• The read method of the underlying stream returns -1, indicating end-of-file, or
• The ready method of the underlying stream returns false, indicating that further input
requests would block.
• If the first read on the underlying stream returns -1 to indicate end-of-file then this
method returns -1. Otherwise this method returns the number of characters actually
read.
• String readLine() : Reads a line of text.A line is considered to be terminated by any one of
a line feed (‘\n’), a carriage return (‘\r’), or a carriage return followed immediately by a
linefeed.
•boolean ready() : Tells whether this stream is ready to be read.
04/16/2024
• void reset() : Resets the stream to the most recent mark.
• long skip(long n) : Skips characters.
//Java program demonstrating BufferedReader methods
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
class BufferedReaderDemo
{
public static void main(String[] args) throws IOException
{
FileReader fr = new FileReader("file.txt");
BufferedReader br = new BufferedReader(fr);
char c[]=new char[20];
//illustrating markSupported() method
if(br.markSupported())
{
System.out.println("mark() method is supported");
//illustrating mark method
br.mark(100);}
04/16/2024
//skipping 8 characters
br.skip(8);
//illustrating ready() method
if(br.ready())
{
//illustrating readLine() method
System.out.println(br.readLine());
//illustrating read(char c[],int off,int len)
br.read(c);
for (int i = 0; i <20 ; i++)
{
System.out.print(c[i]);
}
System.out.println();
//illustrating reset() method
br.reset();
for (int i = 0; i <8 ; i++)
{
//illustrating read() method
System.out.print((char)br.read());
}}}}
04/16/2024
Example of Java BufferedWriter
package com.javatpoint;
import java.io.*;
public class BufferedWriterExample {
public static void main(String[] args) throws Exception {
FileWriter writer = new FileWriter("D:\\testout.txt");
BufferedWriter buffer = new BufferedWriter(writer);
buffer.write("Welcome to javaTpoint.");
buffer.close();
System.out.println("Success");
}
}

04/16/2024
NPTEL LINK
https://www.youtube.com/watch?v=hBh_CC5y8-s
https://www.youtube.com/watch?v=8cm1x4bC610&t=11s
Innovative content of oops concepts
https://www.youtube.com/watch?v=LPT6m33Y6is
https://www.youtube.com/watch?v=7GwptabrYyk

04/16/2024
References
1. Herbert Schildt, Java The Complete Reference, 7 /9th Edition, Tata McGraw Hill, 2007.
2. https://www.geeksforgeeks.org
3. www.slideshare.net
4. https://www.javatpoint.com/
5. https://www.w3schools.com/java/
6. https://www.edureka.co
7. https://www.softwaretestinghelp.com

04/16/2024

You might also like