Posts

Showing posts from August, 2025

๐Ÿ“š Other Stream Classes in Java เคœाเคตा เคฎें เค…เคจ्เคฏ เคธ्เคŸ्เคฐीเคฎ เค•्เคฒाเคธेเคธ

In Java, apart from basic byte and character streams, there are several specialized stream classes that provide advanced input-output operations. เคœाเคตा เคฎें, เคฌेเคธिเค• เคฌाเค‡เคŸ เค”เคฐ เค•ैเคฐेเค•्เคŸเคฐ เคธ्เคŸ्เคฐीเคฎ्เคธ เค•े เค…เคฒाเคตा, เค•เคˆ เคตिเคถेเคท เคธ्เคŸ्เคฐीเคฎ เค•्เคฒाเคธेเคธ เคนोเคคी เคนैं เคœो เคเคกเคตांเคธ เค‡เคจเคชुเคŸ-เค†เค‰เคŸเคชुเคŸ เค‘เคชเคฐेเคถเคจ เคช्เคฐเคฆाเคจ เค•เคฐเคคी เคนैं। Key Points / เคฎुเค–्เคฏ เคฌिंเคฆु:- These classes extend InputStream, OutputStream, Reader, Writer . เคฏे เค•्เคฒाเคธेเคธ InputStream, OutputStream, Reader, Writer เค•ो เคเค•्เคธเคŸेंเคก เค•เคฐเคคी เคนैं। Provide special operations like file merging, compression, object serialization. เคฏे เคตिเคถेเคท เค‘เคชเคฐेเคถเคจ เคœैเคธे เคซाเค‡เคฒ เคฎเคฐ्เคœिंเค—, เค•เคฎ्เคช्เคฐेเคถเคจ, เค‘เคฌ्เคœेเค•्เคŸ เคธीเคฐिเคฏเคฒाเค‡เคœेเคถเคจ เค•เคฐเคคी เคนैं। Often used in real-time applications where basic streams are not enough. เค‡เคจเค•ा เคช्เคฐเคฏोเค— เคฐीเคฏเคฒ-เคŸाเค‡เคฎ เคเคช्เคฒिเค•ेเคถเคจ เคฎें เคนोเคคा เคนै เคœเคนाँ เคฌेเคธिเค• เคธ्เคŸ्เคฐीเคฎ เคชเคฐ्เคฏाเคช्เคค เคจเคนीं เคนोเคคी। ๐Ÿ”น Common Other Stream Classes / เคธाเคฎाเคจ्เคฏ เค…เคจ्เคฏ เคธ्เคŸ्เคฐीเคฎ เค•्เคฒाเคธेเคธ Stream Class Use / เค‰เคชเคฏोเค— SequenceInputStream Combine multiple input streams PushbackInputStream         Push data...

Interactive Input and Output in Java เคœाเคตा เคฎें เค‡ंเคŸเคฐैเค•्เคŸिเคต เค‡เคจเคชुเคŸ เค”เคฐ เค†เค‰เคŸเคชुเคŸ

Interactive Input and Output in Java means taking input from the user at runtime and providing dynamic output based on the input. เคœाเคตा เคฎें เค‡ंเคŸเคฐैเค•्เคŸिเคต เค‡เคจเคชुเคŸ เค”เคฐ เค†เค‰เคŸเคชुเคŸ เค•ा เค…เคฐ्เคฅ เคนै เคฐเคจเคŸाเค‡เคฎ เคชเคฐ เค‰เคชเคฏोเค—เค•เคฐ्เคคा เคธे เค‡เคจเคชुเคŸ เคฒेเคจा เค”เคฐ เค‰เคธเค•े เค†เคงाเคฐ เคชเคฐ เค†เค‰เคŸเคชुเคŸ เคฆेเคจा। Key Points / เคฎुเค–्เคฏ เคฌिंเคฆु:- Interactive Input : User enters data using console or GUI. เค‡ंเคŸเคฐैเค•्เคŸिเคต เค‡เคจเคชुเคŸ : เค‰เคชเคฏोเค—เค•เคฐ्เคคा เค•ंเคธोเคฒ เคฏा GUI เคธे เคกेเคŸा เคฆेเคคा เคนै। Interactive Output : Program responds according to input. เค‡ंเคŸเคฐैเค•्เคŸिเคต เค†เค‰เคŸเคชुเคŸ : เคช्เคฐोเค—्เคฐाเคฎ เค‡เคจเคชुเคŸ เค•े เค…เคจुเคธाเคฐ เค†เค‰เคŸเคชुเคŸ เคฆेเคคा เคนै। Common Classes : Scanner , BufferedReader , Console . เคธाเคฎाเคจ्เคฏ เค•्เคฒाเคธेเคธ : Scanner , BufferedReader , Console । ๐Ÿ’ป Example 1: Using Scanner for Interactive I/O import java.util.Scanner; public class InteractiveScanner { public static void main(String[] args) { Scanner sc = new Scanner(System.in); System.out.print("Enter your name: "); String name = sc.nextLine(); System.out.print("Enter your age: "); int a...

๐Ÿ“„ Random Access Files in Java เคœाเคตा เคฎें เคฐैंเคกเคฎ เคเค•्เคธेเคธ เคซाเค‡เคฒ्เคธ

In Java, Random Access Files allow us to read and write data from any position in a file without reading it sequentially. เคœाเคตा เคฎें เคฐैंเคกเคฎ เคเค•्เคธेเคธ เคซाเค‡เคฒ्เคธ เคนเคฎें เคซाเค‡เคฒ เค•े เค•िเคธी เคญी เคธ्เคฅाเคจ เคธे เคกेเคŸा เคชเคข़เคจे เค”เคฐ เคฒिเค–เคจे เค•ी เค…เคจुเคฎเคคि เคฆेเคคी เคนैं, เคฌिเคจा เค‰เคธे เค•्เคฐเคฎเคตाเคฐ เคชเคข़े। Key Features / เคฎुเค–्เคฏ เคตिเคถेเคทเคคाเคँ:- Direct Access: We can move to any file position using a file pointer. เคกाเคฏเคฐेเค•्เคŸ เคเค•्เคธेเคธ: เคนเคฎ เคซाเค‡เคฒ เคชॉเค‡ंเคŸเคฐ เค•ा เค‰เคชเคฏोเค— เค•เคฐเค•े เคซाเค‡เคฒ เคฎें เค•िเคธी เคญी เคธ्เคฅाเคจ เคชเคฐ เคœा เคธเค•เคคे เคนैं। Read and Write Both: Same file can be used for reading and writing. เคฐीเคก เค”เคฐ เคฐाเค‡เคŸ เคฆोเคจों: เคเค• เคนी เคซाเค‡เคฒ เคธे เคชเคข़ เค”เคฐ เค‰เคธเคฎें เคฒिเค– เคธเค•เคคे เคนैं। Class Used: RandomAccessFile (from java.io package). เค‰เคชเคฏोเค— เค•ी เค—เคˆ เค•्เคฒाเคธ: RandomAccessFile ( java.io เคชैเค•ेเคœ เคธे)। ๐Ÿ’ป Example 1: Writing to Random Access File import java.io.*; public class RandomAccessWrite { public static void main(String[] args) { try { RandomAccessFile raf = new RandomAccessFile("random.txt", "rw"); raf.writeUTF("...

Concatenating and Buffering Files in Java เคœाเคตा เคฎें เคซ़ाเค‡เคฒों เค•ो เคœोเคก़เคจा เค”เคฐ เคฌเคซเคฐ เค•เคฐเคจा

In Java, we can merge multiple files into a single file (concatenation) and use buffering to improve file I/O performance. เคœाเคตा เคฎें เคนเคฎ เค•เคˆ เคซाเค‡เคฒों เค•ो เคเค• เคนी เคซाเค‡เคฒ เคฎें เคœोเคก़ เคธเค•เคคे เคนैं (เค•ंเค•ैเคŸिเคจेเคถเคจ) เค”เคฐ เคฌเคซเคฐिंเค— เค•ा เค‰เคชเคฏोเค— เค•เคฐเค•े เคซाเค‡เคฒ I/O เค•ी เค—เคคि เคฌเคข़ा เคธเค•เคคे เคนैं। Key Concepts / เคฎुเค–्เคฏ เคฌिंเคฆु:- Concatenation: Combining multiple files into one. เค•ंเค•ैเคŸिเคจेเคถเคจ: เค•เคˆ เคซाเค‡เคฒों เค•ो เคเค• เคซाเค‡เคฒ เคฎें เคœोเคก़เคจा। Buffering: Using a buffer to reduce disk access and improve speed. เคฌเคซเคฐिंเค—: เคฌเคซเคฐ เค•ा เค‰เคชเคฏोเค— เค•เคฐเค•े เคกिเคธ्เค• เคเค•्เคธेเคธ เค•เคฎ เค•เคฐเคจा เค”เคฐ เค—เคคि เคฌเคข़ाเคจा। Streams Used: SequenceInputStream , BufferedInputStream , BufferedOutputStream . เค‰เคชเคฏोเค— เค•ी เค—เคˆ เคธ्เคŸ्เคฐीเคฎ्เคธ: SequenceInputStream , BufferedInputStream , BufferedOutputStream । ๐Ÿ’ป Example 1: Concatenating Two Files import java.io.*; public class ConcatFiles { public static void main(String[] args) { try { FileInputStream fis1 = new FileInputStream("file1.txt"); FileInputStream fis2 = new FileInputStream("file2.txt"); ...

Handling Primitive Data Types in Java I/O เคœाเคตा I/O เคฎें เคช्เคฐिเคฎिเคŸिเคต เคกेเคŸा เคŸाเค‡เคช्เคธ เค•ो เคธंเคญाเคฒเคจा

Java provides special Data Streams to read and write primitive data types like int , float , boolean , and char . เคœाเคตा เคกाเคŸा เคธ्เคŸ्เคฐीเคฎ्เคธ เคช्เคฐเคฆाเคจ เค•เคฐเคคा เคนै เคœो เคช्เคฐिเคฎिเคŸिเคต เคกेเคŸा เคŸाเค‡เคช्เคธ เคœैเคธे int , float , boolean , เค”เคฐ char เค•ो เคชเคข़เคจे เค”เคฐ เคฒिเค–เคจे เค•े เคฒिเค เค‰เคชเคฏोเค— เคนोเคคी เคนैं। Key Points / เคฎुเค–्เคฏ เคฌिंเคฆु:- DataOutputStream writes primitive data types to a file. DataOutputStream เคซाเค‡เคฒ เคฎें เคช्เคฐिเคฎिเคŸिเคต เคกेเคŸा เคŸाเค‡เคช्เคธ เคฒिเค–เคคा เคนै। DataInputStream reads primitive data types from a file. DataInputStream เคซाเค‡เคฒ เคธे เคช्เคฐिเคฎिเคŸिเคต เคกेเคŸा เคŸाเค‡เคช्เคธ เคชเคข़เคคा เคนै। These are useful for structured data storage. เคฏเคน เคธ्เคŸ्เคฐเค•्เคšเคฐ्เคก เคกेเคŸा เคธ्เคŸोเคฐेเคœ เค•े เคฒिเค เค‰เคชเคฏोเค—ी เคนैं। ๐Ÿ’ป Example 1: Writing Primitive Data Types import java.io.*; public class WritePrimitives { public static void main(String[] args) { try { FileOutputStream fos = new FileOutputStream("data.bin"); DataOutputStream dos = new DataOutputStream(fos); dos.writeInt(101); dos.writeUTF("Ajay"); ...

Reading and Writing Bytes in Java / เคœाเคตा เคฎें เคฌाเค‡เคŸ्เคธ เคชเคข़เคจा เค”เคฐ เคฒिเค–เคจा

Java provides Byte Streams to handle 8-bit data (bytes) for reading and writing files. เคœाเคตा เคฌाเค‡เคŸ เคธ्เคŸ्เคฐीเคฎ्เคธ เคช्เคฐเคฆाเคจ เค•เคฐเคคा เคนै, เคœो 8-เคฌिเคŸ เคกेเคŸा (เคฌाเค‡เคŸ्เคธ) เค•ो เคซाเค‡เคฒ เคธे เคชเคข़เคจे เค”เคฐ เคฒिเค–เคจे เค•े เคฒिเค เคช्เคฐเคฏोเค— เคนोเคคी เคนैं। Key Points / เคฎुเค–्เคฏ เคฌिंเคฆु:- Use FileInputStream for reading bytes from a file. เคซाเค‡เคฒ เคธे เคฌाเค‡เคŸ्เคธ เคชเคข़เคจे เค•े เคฒिเค FileInputStream เค•ा เค‰เคชเคฏोเค— เค•เคฐें। Use FileOutputStream for writing bytes to a file. เคซाเค‡เคฒ เคฎें เคฌाเค‡เคŸ्เคธ เคฒिเค–เคจे เค•े เคฒिเค FileOutputStream เค•ा เค‰เคชเคฏोเค— เค•เคฐें। Suitable for binary files like images, PDFs, and videos. เคฏเคน เคฌाเค‡เคจเคฐी เคซाเค‡เคฒ्เคธ เคœैเคธे เค‡เคฎेเคœ, PDF เค”เคฐ เคตीเคกिเคฏो เค•े เคฒिเค เค‰เคชเคฏुเค•्เคค เคนै। ๐Ÿ’ป Example 1: Writing Bytes to a File import java.io.FileOutputStream; import java.io.IOException; public class WriteBytesExample { public static void main(String[] args) { try { FileOutputStream fos = new FileOutputStream("bytefile.txt"); String data = "Hello Byte Stream!"; fos.write(data.getBytes()); fos.close(); Sy...

Reading and Writing Characters in Java เคœाเคตा เคฎें เค•เคฐैเค•्เคŸเคฐ เคชเคข़เคจा เค”เคฐ เคฒिเค–เคจा

Reading and writing characters in Java is done using Character Streams, which handle 16-bit Unicode characters. เคœाเคตा เคฎें เค•เคฐैเค•्เคŸเคฐ เค•ो เคชเคข़เคจे เค”เคฐ เคฒिเค–เคจे เค•े เคฒिเค เค•ैเคฐेเค•्เคŸเคฐ เคธ्เคŸ्เคฐीเคฎ्เคธ เค•ा เค‰เคชเคฏोเค— เค•िเคฏा เคœाเคคा เคนै, เคœो 16-เคฌिเคŸ เคฏूเคจिเค•ोเคก เค•เคฐैเค•्เคŸเคฐ เค•ो เคธंเคญाเคฒเคคे เคนैं। Key Points / เคฎुเค–्เคฏ เคฌिंเคฆु:- Use FileReader for reading characters from a file. เคซाเค‡เคฒ เคธे เค•เคฐैเค•्เคŸเคฐ เคชเคข़เคจे เค•े เคฒिเค FileReader เค•ा เค‰เคชเคฏोเค— เค•เคฐें। Use FileWriter for writing characters to a file. เคซाเค‡เคฒ เคฎें เค•เคฐैเค•्เคŸเคฐ เคฒिเค–เคจे เค•े เคฒिเค FileWriter เค•ा เค‰เคชเคฏोเค— เค•เคฐें। Wrap them in BufferedReader and BufferedWriter for efficiency. เคฆเค•्เคทเคคा เคฌเคข़ाเคจे เค•े เคฒिเค BufferedReader เค”เคฐ BufferedWriter เค•ा เค‰เคชเคฏोเค— เค•เคฐें। ๐Ÿ’ป Example 1: Writing Characters to a File import java.io.FileWriter; import java.io.IOException; public class WriteCharactersExample { public static void main(String[] args) { try { FileWriter writer = new FileWriter("charfile.txt"); writer.write("Hello, Character Stream!"); writer.close(); ...

Creation of Files in Java เคœाเคตा เคฎें เคซाเค‡เคฒ เคจिเคฐ्เคฎाเคฃ

File creation is an essential part of file handling in Java. We use the `File` class from the java.io package to create new files. เคœाเคตा เคฎें เคซाเค‡เคฒ เคนैंเคกเคฒिंเค— เค•ा เคเค• เคฎเคนเคค्เคตเคชूเคฐ्เคฃ เคนिเคธ्เคธा เคซाเค‡เคฒ เคจिเคฐ्เคฎाเคฃ เคนै। เคนเคฎ เคจเคˆ เคซाเค‡เคฒ เคฌเคจाเคจे เค•े เคฒिเค java.io เคชैเค•ेเคœ เค•ी `File` เค•्เคฒाเคธ เค•ा เค‰เคชเคฏोเค— เค•เคฐเคคे เคนैं। Key Points / เคฎुเค–्เคฏ เคฌिंเคฆु:- 1. Use File class to create new files.    เคจเคˆ เคซाเค‡เคฒ เคฌเคจाเคจे เค•े เคฒिเค File เค•्เคฒाเคธ เค•ा เค‰เคชเคฏोเค— เค•เคฐें। 2. `createNewFile()` method returns true if the file is created successfully.    `createNewFile()` เคฎेเคฅเคก true เคฒौเคŸाเคคा เคนै เคฏเคฆि เคซाเค‡เคฒ เคธเคซเคฒเคคाเคชूเคฐ्เคตเค• เคฌเคจเคคी เคนै। 3. If the file already exists, the method returns false.    เคฏเคฆि เคซाเค‡เคฒ เคชเคนเคฒे เคธे เคฎौเคœूเคฆ เคนै, เคคो เคฎेเคฅเคก false เคฒौเคŸाเคคा เคนै। ๐Ÿ’ป Example 1: Create a File import java.io.File; import java.io.IOException; public class CreateFileExample {     public static void main(String[] args) {         try {             File file = new File("myfile.txt");             if (fil...

Input/Output Exceptions in Java เคœाเคตा เคฎें เค‡เคจเคชुเคŸ/เค†เค‰เคŸเคชुเคŸ เคเค•्เคธेเคช्เคถเคจ्เคธ

Input / Output (I/O) exceptions occur when a program fails to read or write data from a file, device, or network. These exceptions are part of the java.io package and usually occur due to: เค‡เคจเคชुเคŸ / เค†เค‰เคŸเคชुเคŸ (I/O) เคเค•्เคธेเคช्เคถเคจ เคคเคฌ เคนोเคคी เคนै เคœเคฌ เคช्เคฐोเค—्เคฐाเคฎ เคซाเค‡เคฒ, เคกिเคตाเค‡เคธ เคฏा เคจेเคŸเคตเคฐ्เค• เคธे เคกेเคŸा เคชเคข़เคจे เคฏा เคฒिเค–เคจे เคฎें เค…เคธเคซเคฒ เคฐเคนเคคा เคนै। เคฏे เคเค•्เคธेเคช्เคถเคจ  java.io  เคชैเค•ेเคœ เค•ा เคนिเคธ्เคธा เคนोเคคी เคนैं เค”เคฐ เคฎुเค–्เคฏ เคฐूเคช เคธे เค‡เคจ เค•ाเคฐเคฃों เคธे เคนोเคคी เคนैं: File not found เคซाเค‡เคฒ เค•ा เคจ เคฎिเคฒเคจा Lack of read/write permissions เคชเคข़เคจे/เคฒिเค–เคจे เค•ी เค…เคจुเคฎเคคि เคจ เคนोเคจा Disk or device failure เคกिเคธ्เค• เคฏा เคกिเคตाเค‡เคธ เคซेเคฒ เคนोเคจा Network disconnection during I/O operations เคจेเคŸเคตเคฐ्เค• เค•เคจेเค•्เคถเคจ เคŸूเคŸ เคœाเคจा In Java some common I/O exceptions are as follows เคœाเคตा เคฎें เค•ुเค› เคธाเคฎाเคจ्เคฏ I/O เคเค•्เคธेเคช्เคถเคจ เคจिเคฎ्เคจ เคนै:- IOException – General exception for I/O errors เคธाเคฎाเคจ्เคฏ I/O เคเคฐเคฐ FileNotFoundException – File is missing or inaccessible เคซाเค‡เคฒ เค—ाเคฏเคฌ เคฏा เคเค•्เคธेเคธ เคจ เคนो เคฐเคนी เคนो EOFException – End of file reached unexpectedly เคซाเค‡เคฒ เค…เคšाเคจเค• เคธเคฎाเคช्เคค เคนो เค—เคˆ We ca...

Java File Class เคœाเคตा เคซाเค‡เคฒ เค•्เคฒाเคธ

The File class in Java is part of the java.io package and is used to represent the path of files and directories. The File class does not read or write data directly; it only provides information about files and directories and methods to create, delete, or check properties. เคœाเคตा เคฎें File เค•्เคฒाเคธ java.io เคชैเค•ेเคœ เค•ा เคนिเคธ्เคธा เคนै เค”เคฐ เค‡เคธเค•ा เคช्เคฐเคฏोเค— เคซाเค‡เคฒ เคเคตं เคกाเคฏเคฐेเค•्เคŸเคฐी เค•े เคชाเคฅ เค•ो เคช्เคฐเคฆเคฐ्เคถिเคค เค•เคฐเคจे เค•े เคฒिเค เค•िเคฏा เคœाเคคा เคนै। File เค•्เคฒाเคธ เคกेเคŸा เค•ो เคธीเคงे เคชเคข़เคคी เคฏा เคฒिเค–เคคी เคจเคนीं เคนै; เคฏเคน เค•ेเคตเคฒ เคซाเค‡เคฒ เค”เคฐ เคกाเคฏเคฐेเค•्เคŸเคฐी เค•ी เคœाเคจเค•ाเคฐी เค”เคฐ เค‰เคจ्เคนें เคฌเคจाเคจे, เคนเคŸाเคจे เคฏा เคšेเค• เค•เคฐเคจे เค•ी เคธुเคตिเคงा เคฆेเคคी เคนै। ๐Ÿ”น Constructors of File Class (เค•เคจ्เคธ्เคŸ्เคฐเค•्เคŸเคฐ्เคธ) File(String pathname) – Creates a new File instance using a given pathname. File(String pathname) – เคฆिเคฏे เค—เคฏे เคชाเคฅเคจेเคฎ เค•े เค†เคงाเคฐ เคชเคฐ เคจเคˆ File เค‘เคฌ्เคœेเค•्เคŸ เคฌเคจाเคคा เคนै। File(String parent, String child) – Creates a File object from directory and filename separately. File(String parent, String child) – เคกाเคฏเคฐेเค•्เคŸเคฐी เค”เคฐ เคซाเค‡เคฒ เค•ा เคจाเคฎ เค…เคฒเค—-เค…เคฒเค— เคฆेเค•เคฐ File เค‘เคฌ्เคœेเค•्เคŸ เคฌเคจाเคคा เคนै। ๐Ÿ”น Common Methods of Fil...

Character Stream in Java เคœाเคตा เคฎें เค•เคฐैเค•्เคŸเคฐ เคธ्เคŸ्เคฐीเคฎ

Character Stream in Java is used to read and write character data (16-bit Unicode) instead of raw bytes. เคœाเคตा เคฎें เค•เคฐैเค•्เคŸเคฐ เคธ्เคŸ्เคฐीเคฎ เค•ा เคช्เคฐเคฏोเค— เค•เคฐैเค•्เคŸเคฐ เคกेเคŸा (16-เคฌिเคŸ เคฏूเคจिเค•ोเคก) เค•ो เคชเคข़เคจे เค”เคฐ เคฒिเค–เคจे เค•े เคฒिเค เค•िเคฏा เคœाเคคा เคนै, เคจ เค•ि เค•ेเคตเคฒ เคฌाเค‡เคŸ्เคธ เค•े เคฒिเค। Character Streams are mainly used for text files because they handle Unicode automatically. เค•เคฐैเค•्เคŸเคฐ เคธ्เคŸ्เคฐीเคฎ्เคธ เค•ा เคช्เคฐเคฏोเค— เคช्เคฐाเคฏः เคŸेเค•्เคธ्เคŸ เคซाเค‡เคฒ्เคธ เค•े เคฒिเค เค•िเคฏा เคœाเคคा เคนै เค•्เคฏोंเค•ि เคฏे เคฏूเคจिเค•ोเคก เค•ो เคธ्เคตเคคः เคนैंเคกเคฒ เค•เคฐเคคी เคนैं। 1️⃣ Important Character Stream Classes Class Name Description (English) เคตिเคตเคฐเคฃ (Hindi) FileReader Reads data from file เคซाเค‡เคฒ เคธे เคกेเคŸा เคชเคข़เคคा เคนै FileWriter Writes data to file เคซाเค‡เคฒ เคฎें เคกेเคŸा เคฒिเค–เคคा เคนै BufferedReader Reads data using buffer เคฌเคซเคฐ เค•े เคธाเคฅ เค•เคฐैเค•्เคŸเคฐ เคชเคข़เคคा เคนै BufferedWriter Writes data using buffer เคฌเคซเคฐ เค•े เคธाเคฅ เค•เคฐैเค•्เคŸเคฐ เคฒिเค–เคคा เคนै PrintWriter Writes formatted text output เคช्เคฐिंเคŸ เค”เคฐ เคช्เคฐिंเคŸเคฒเคจ เคฎेเคฅเคก्เคธ เค•े เคธाเคฅ เคฒिเค–เคคा เคนै InputStreamReader Converts bytes to characters เคฌाเค‡เคŸ เค•ो เค•เคฐैเค•्เคŸเคฐ เคฎें เคฌเคฆเคฒเคคा เคนै OutputStreamWriter C...

Byte Stream in Java เคœाเคตा เคฎें เคฌाเค‡เคŸ เคธ्เคŸ्เคฐीเคฎ

Byte Stream in Java is used to read and write 8-bit binary data like files, images, audio, and video. เคœाเคตा เคฎें เคฌाเค‡เคŸ เคธ्เคŸ्เคฐीเคฎ เค•ा เค‰เคชเคฏोเค— 8-เคฌिเคŸ เคฌाเค‡เคจเคฐी เคกेเคŸा เค•ो เคชเคข़เคจे เค”เคฐ เคฒिเค–เคจे เค•े เคฒिเค เค•िเคฏा เคœाเคคा เคนै, เคœैเคธे เคซाเค‡เคฒ, เค‡เคฎेเคœ, เค‘เคกिเคฏो เค”เคฐ เคตीเคกिเคฏो। เคฌाเค‡เคŸ เคธ्เคŸ्เคฐीเคฎ เคฆो เคช्เคฐเค•ाเคฐ เค•ी เคนोเคคी เคนैं:- InputStream (เค‡เคจเคชुเคŸ เคธ्เคŸ्เคฐीเคฎ) OutputStream (เค†เค‰เคŸเคชुเคŸ เคธ्เคŸ्เคฐीเคฎ) 1️⃣ InputStream (เค‡เคจเคชुเคŸ เคธ्เคŸ्เคฐीเคฎ) InputStream is a superclass that reads data from a source like file, device, or socket. InputStream เคเค• เคธुเคชเคฐเค•्เคฒाเคธ เคนै เคœो เคกेเคŸा เค•ो เค•िเคธी เคธ्เคค्เคฐोเคค (เคซाเค‡เคฒ, เคกिเคตाเค‡เคธ, เคฏा เคธॉเค•ेเคŸ) เคธे เคชเคข़เคคी เคนै। ๐Ÿ”น Common Methods of InputStream Method Description (English) เคตिเคตเคฐเคฃ (Hindi) int read()          Reads next byte of data                       เค…เค—เคฒी เคฌाเค‡เคŸ เค•ो เคชเคข़เคคा เคนै int available() Returns number of available bytes เค‰เคชเคฒเคฌ्เคง เคฌाเค‡เคŸ्เคธ เค•ी เคธंเค–्เคฏा เคฒौเคŸाเคคा เคนै void close() Closes the stream เคธ्เคŸ्เคฐीเคฎ เค•ो เคฌंเคฆ เค•เคฐเคคा เคนै 2️⃣ OutputStream (เค†เค‰เคŸเคชुเคŸ เคธ्เคŸ्เคฐीเคฎ) Outp...

เคœाเคตा เคฎें เคซ़ाเค‡เคฒ เคนैंเคกเคฒिंเค— (Java File Handling in Hindi & English)

File handling in Java allows us to  read and write data permanently  in files. Using Java I/O (Input/Output) streams, we can store data, read it, and even process it efficiently. เคœाเคตा เคฎें เคซ़ाเค‡เคฒ เคนैंเคกเคฒिंเค— เคนเคฎें เคกेเคŸा เค•ो  เคธ्เคฅाเคฏी เคฐूเคช เคธे เคธेเคต เค”เคฐ เคชเคข़เคจे  เค•ी เคธुเคตिเคงा เคฆेเคคी เคนै। เคœाเคตा I/O (เค‡เคจเคชुเคŸ/เค†เค‰เคŸเคชुเคŸ) เคธ्เคŸ्เคฐीเคฎ्เคธ เค•ी เคฎเคฆเคฆ เคธे เคนเคฎ เคกेเคŸा เค•ो เคธ्เคŸोเคฐ, เคชเคข़ เค”เคฐ เคช्เคฐोเคธेเคธ เค•เคฐ เคธเค•เคคे เคนैं। 1️⃣ เคœाเคตा เคฎें เคธ्เคŸ्เคฐीเคฎ (Java Streams) A  stream  is a sequence of data. In Java, streams are used to  read and write data  from one location to another (like file, memory, or network). เคธ्เคŸ्เคฐीเคฎ  เคกेเคŸा เค•ा เคเค• เค•्เคฐเคฎ เคนोเคคा เคนै। เคœाเคตा เคฎें, เคธ्เคŸ्เคฐीเคฎ เค•ा เค‰เคชเคฏोเค—  เคกेเคŸा เคชเคข़เคจे เค”เคฐ เคฒिเค–เคจे  เค•े เคฒिเค เค•िเคฏा เคœाเคคा เคนै, เคœैเคธे เคซ़ाเค‡เคฒ, เคฎेเคฎोเคฐी เคฏा เคจेเคŸเคตเคฐ्เค•। Java I/O streams are mainly divided into two types: เคœाเคตा I/O เคธ्เคŸ्เคฐीเคฎ เคฎुเค–्เคฏเคคः เคฆो เคช्เคฐเค•ाเคฐ เค•ी เคนोเคคी เคนैं: 1️⃣  Character Stream  – เค•ैเคฐेเค•्เคŸเคฐ (2 เคฌाเค‡เคŸ เคฏूเคจिเค•ोเคก) เคกेเคŸा เค•े เคฒिเค Character Stream →  Reader  เค”เคฐ  Writer  เค•्เคฒाเคธेเคธ 2️⃣  Byte Stream  – เคฌाเค‡...

เคœाเคตा เคฎें เคธ्เคŸ्เคฐीเคฎ Java Streams in File Handling

เคธ्เคŸ्เคฐीเคฎ เคกेเคŸा เค•ो เคเค• เคœเค—เคน เคธे เคฆूเคธเคฐी เคœเค—เคน เคŸ्เคฐांเคธเคซเคฐ เค•เคฐเคจे เค•ा เคฎाเคง्เคฏเคฎ เคนोเคคी เคนै।  เคœाเคตा เคฎें เคธ्เคŸ्เคฐीเคฎ เคฆो เคช्เคฐเค•ाเคฐ เค•ी เคนोเคคी เคนै: 1️⃣ Character Stream – เค•ैเคฐेเค•्เคŸเคฐ (2 เคฌाเค‡เคŸ เคฏूเคจिเค•ोเคก) เคกेเคŸा เค•े เคฒिเค Character Stream →  Reader  เค”เคฐ  Writer  เค•्เคฒाเคธेเคธ 2️⃣ Byte Stream – เคฌाเค‡เคŸ (8-เคฌिเคŸ) เคกेเคŸा เค•े เคฒिเค Byte Stream → InputStream เค”เคฐ OutputStream เค•्เคฒाเคธेเคธ Buffering เค•े เคฒिเค → BufferedReader , BufferedWriter , BufferedInputStream , BufferedOutputStream Printing เค”เคฐ Formatting เค•े เคฒिเค → PrintWriter , PrintStream เคซ़ाเค‡เคฒ เคฎें เคกेเคŸा เค•ो เคธ्เคฅाเคฏी เคฐूเคช เคธे เคธेเคต เค•เคฐ เคธเค•เคคे เคนैं।  เคฌเคก़ी เคซाเค‡เคฒ्เคธ เค•ो เคชเคข़เคจा เค”เคฐ เคฒिเค–เคจा เค†เคธाเคจ।  เคธ्เคŸ्เคฐीเคฎ्เคธ เค”เคฐ เคฌเคซเคฐिंเค— เคธे เคชเคฐเคซॉเคฐ्เคฎेंเคธ เคฌेเคนเคคเคฐ। เคจेเคŸเคตเคฐ्เค•िंเค— เค”เคฐ เคกेเคŸाเคฌेเคธ เค‘เคชเคฐेเคถเคจ เคฎें เคกाเคŸा เคธ्เคŸ्เคฐीเคฎिंเค— เค†เคธाเคจ।

Java Input & Output Streams เคœाเคตा เค‡เคจเคชुเคŸ เคเคตं เค†เค‰เคŸเคชुเคŸ เคธ्เคŸ्เคฐीเคฎ

In every programming language, there is a mechanism to handle input and output.  In Java, input and output operations are mainly performed using streams, which are part of the java.io package. เคนเคฐ เคช्เคฐोเค—्เคฐाเคฎिंเค— เคฒैंเค—्เคตेเคœ เคฎें เค‡เคจเคชुเคŸ เค”เคฐ เค†เค‰เคŸเคชुเคŸ เค•ो เคธंเคญाเคฒเคจे เค•ी เคต्เคฏเคตเคธ्เคฅा เคนोเคคी เคนै।  เคœाเคตा เคฎें เค‡เคจเคชुเคŸ เค”เคฐ เค†เค‰เคŸเคชुเคŸ เค•ाเคฐ्เคฏ เคฎुเค–्เคฏ เคฐूเคช เคธे เคธ्เคŸ्เคฐीเคฎ्เคธ เค•ा เค‰เคชเคฏोเค— เค•เคฐเค•े เค•िเค เคœाเคคे เคนैं, เคœो java.io เคชैเค•ेเคœ เค•ा เคนिเคธ्เคธा เคนैं। Basic Console I/O Streams in Java  เคœाเคตा เคฎें เคฌेเคธिเค• เค•ंเคธोเคฒ I/O เคธ्เคŸ्เคฐीเคฎ्เคธ Java provides three standard I/O streams for console input and output: เคœाเคตा เคคीเคจ เคฎाเคจเค• I/O เคธ्เคŸ्เคฐीเคฎ्เคธ เคช्เคฐเคฆाเคจ เค•เคฐเคคा เคนै เค•ंเคธोเคฒ เค‡เคจเคชुเคŸ เค”เคฐ เค†เค‰เคŸเคชुเคŸ เค•े เคฒिเค: 1️⃣ System.out – Standard Output Stream เคฎाเคจเค• เค†เค‰เคŸเคชुเคŸ เคธ्เคŸ्เคฐीเคฎ This is used to print normal output to the console. เค‡เคธเค•ा เค‰เคชเคฏोเค— เค•ंเคธोเคฒ เคชเคฐ เคธाเคฎाเคจ्เคฏ เค†เค‰เคŸเคชुเคŸ เคช्เคฐिंเคŸ เค•เคฐเคจे เค•े เคฒिเค เค•िเคฏा เคœाเคคा เคนै। Example / เค‰เคฆाเคนเคฐเคฃ: public class Sample { public static void main(String[] args) { System.out.println("Hello World"); } } Output / เค†เค‰เคŸเคชुเคŸ: Hello World 2️⃣ System.err – St...

File Handling in Java เคœाเคตा เคฎें เคซ़ाเค‡เคฒ เคนैंเคกเคฒिंเค—

File Handling in Java allows us to create, read, write, and manage files on the system. It is part of java.io package which provides multiple classes and methods to handle files. เคœाเคตा เคฎें เคซ़ाเค‡เคฒ เคนैंเคกเคฒिंเค— เค•े เคฆ्เคตाเคฐा เคนเคฎ เคธिเคธ्เคŸเคฎ เคชเคฐ เคซाเค‡เคฒ เค•ो เคฌเคจाเคจा, เคชเคข़เคจा, เคฒिเค–เคจा เค”เคฐ เคช्เคฐเคฌंเคงिเคค เค•เคฐ เคธเค•เคคे เคนैं। เคฏเคน java.io เคชैเค•ेเคœ เค•ा เคนिเคธ्เคธा เคนै เคœो เคซ़ाเค‡เคฒ เคนैंเคกเคฒिंเค— เค•े เคฒिเค เค•เคˆ เค•्เคฒाเคธ เค”เคฐ เคฎेเคฅเคก เค‰เคชเคฒเคฌ्เคง เค•เคฐाเคคा เคนै। ๐Ÿ”น Common Classes for File Handling in Java Class Description (English) เคตिเคตเคฐเคฃ (Hindi) File Represents file or directory path เคซ़ाเค‡เคฒ เคฏा เคกाเคฏเคฐेเค•्เคŸเคฐी เค•ा เคช्เคฐเคคिเคจिเคงिเคค्เคต เค•เคฐเคคा เคนै FileReader Used to read data from a file character by character เคซ़ाเค‡เคฒ เค•ो เค•ैเคฐेเค•्เคŸเคฐ-เคฌाเคฏ-เค•ैเคฐेเค•्เคŸเคฐ เคชเคข़เคจे เค•े เคฒिเค FileWriter Used to write character data to a file เคซ़ाเค‡เคฒ เคฎें เค•ैเคฐेเค•्เคŸเคฐ เคกेเคŸा เคฒिเค–เคจे เค•े เคฒिเค BufferedReader Reads text efficiently line by line เคŸेเค•्เคธ्เคŸ เค•ो เคฒाเค‡เคจ-เคฌाเคฏ-เคฒाเค‡เคจ เคช्เคฐเคญाเคตी เคฐूเคช เคธे เคชเคข़เคคा เคนै BufferedWriter Writes text efficiently to a file เคŸेเค•्เคธ्เคŸ เค•ो เคช्เคฐเคญाเคตी เคฐूเคช เคธे เคซ़ाเค‡เคฒ เคฎें เคฒिเค–เคคा เคนै FileInputStream Reads binary data...

Loop Control in Java Applet (เคœाเคตा เคเคช्เคฒेเคŸ เคฎें เคฒूเคช เค•ंเคŸ्เคฐोเคฒ)

In Java Applets, we can use loop control statements to create animations or repeated patterns . By using loops like for , while , or do-while , we can draw multiple shapes, apply different colors, and create moving effects. เคœाเคตा เคเคช्เคฒेเคŸ เคฎें เคนเคฎ เคฒूเคช เค•ंเคŸ्เคฐोเคฒ เคธ्เคŸेเคŸเคฎेंเคŸ เค•ा เค‰เคชเคฏोเค— เค•เคฐเค•े เคเคจीเคฎेเคถเคจ เคฏा เคฆोเคนเคฐाเค เคœाเคจे เคตाเคฒे เคชैเคŸเคฐ्เคจ เคฌเคจा เคธเค•เคคे เคนैं।  for , while เคฏा do-while เคฒूเคช เค•ा เค‰เคชเคฏोเค— เค•เคฐเค•े เคนเคฎ เคเค• เคนी เค†เค•ृเคคि เค•ो เคฌाเคฐ-เคฌाเคฐ เคตिเคญिเคจ्เคจ เคฐंเค—ों เคฎें เคฌเคจाเค•เคฐ เคฎूเคตिंเค— เค‡เคซेเค•्เคŸ เคคैเคฏाเคฐ เค•เคฐ เคธเค•เคคे เคนैं। ๐ŸŒˆ Example: Color Changing Rectangles using For Loop This example draws multiple rectangles in different shades of red using a for loop. เคฏเคน เค‰เคฆाเคนเคฐเคฃ for เคฒूเคช เค•ा เค‰เคชเคฏोเค— เค•เคฐเค•े เคฒाเคฒ เคฐंเค— เค•ी เคตिเคญिเคจ्เคจ เคถेเคก्เคธ เคฎें เค•เคˆ เค†เคฏเคคें เคฌเคจाเคคा เคนै। // File Name: ForLoopApplet.java import java.awt.*; import java.applet.*; public class ForLoopApplet extends Applet { public void paint(Graphics g) { Color newColor = new Color(0,0,0); for(int i=0; i<10; i++) { newColor = new Color(i*20+55, 0, 0); // Different red shades...

Java Graphics (AWT) - All Shapes in One Applet example program

import java.awt.*; import java.applet.*; public class AllGraphicsShapesApplet extends Applet {     TextField txtShape = new TextField("0");     int intShapeChoice;     public void init() {         add(txtShape);     }     public void paint(Graphics g) {         g.drawString(" 1. Line", 10, 60);         g.drawString(" 2. Rectangle", 250, 60);         g.drawString(" 3. Filled Rectangle", 10, 80);         g.drawString(" 4. Oval", 250, 80);         g.drawString(" 5. Filled Oval", 10, 100);         g.drawString(" 6. Arc", 250, 100);         g.drawString(" 7. Filled Arc", 10, 120);         g.drawString(" 8. Polygon", 250, 120);         g.drawString(" 9. Filled Polygon", 10, 140);         try {          ...

Java Graphics (AWT) – Lamp Design Example Program

import java.awt.*; public class Lamp extends java.applet.Applet {     public void paint(Graphics g) {         g.fillRect(0,250,290,290);        // Lamp platform         g.drawLine(125,250,125,160);      // Lamp stand         g.drawLine(175,250,175,160);         g.drawArc(85,157,130,50,-65,312); // Bottom of shade         g.drawArc(85,87,130,50,62,58);    // Top of shade         g.drawLine(85,177,119,89);        // Left side         g.drawLine(215,177,181,89);       // Right side         g.fillArc(78,120,40,40,63,-174);  // Dots         g.fillOval(120,96,40,40);         g.fillArc(173,100,40,40,110,180);     } }

Java Swing – Introduction เคœाเคตा เคธ्เคตिंเค— เคชเคฐिเคšเคฏ, Swing Core Components เคธ्เคตिंเค— เค•े เคฎुเค–्เคฏ เค…เคตเคฏเคต

Swing, เคœाเคตा เค•ा Modern GUI (Graphical User Interface) Toolkit เคนै, เคœो เคช्เคฒेเคŸเคซॉเคฐ्เคฎ-เค‡ंเคกिเคชेंเคกेंเคŸ Desktop Applications เคฌเคจाเคจे เค•े เคฒिเค เคช्เคฐเคฏोเค— เค•िเคฏा เคœाเคคा เคนै। Swing is Java’s modern GUI toolkit used to create platform-independent desktop applications . ๐Ÿ–ฅ️ Swing เค•ी เคตिเคถेเคทเคคाเคँ / Features of Swing Lightweight Components Swing เค•े เคธเคญी GUI components lightweight เคนोเคคे เคนैं เค”เคฐ เคช्เคฒेเคŸเคซॉเคฐ्เคฎ เคชเคฐ เคจिเคฐ्เคญเคฐ เคจเคนीं เคนोเคคे। All Swing components are lightweight and platform-independent. Rich Set of Components Swing เคฎें JButton, JTextField, JCheckBox, JTable, JMenu, JProgressBar เค†เคฆि เคœैเคธे เคฌเคนुเคค เคธे advanced GUI components เคฎौเคœूเคฆ เคนैं। Swing provides advanced GUI components like JButton, JTextField, JCheckBox, JTable, JMenu, JProgressBar , etc. Pluggable Look and Feel Swing เคเคช्เคฒिเค•ेเคถเคจ เค•ा look and feel change เค•िเคฏा เคœा เคธเค•เคคा เคนै, เคœैเคธे Windows, Metal เคฏा Nimbus। Swing applications support changing their look and feel , e.g., Windows, Metal, Nimbus. MVC Architecture Swing components Model-View-Controller (MVC) architec...

๐Ÿ”บ Draw Polygon เค”เคฐ Polyline in Java (Graphics Class)

Polygon เค”เคฐ Polyline เคœाเคตा เค—्เคฐाเฅžिเค•्เคธ เคช्เคฐोเค—्เคฐाเคฎिंเค— เคฎें เคเคธे shapes เคนैं เคœिเคจเคฎें เค•เคˆ connected lines เคนोเคคी เคนैं। In Java Graphics programming, Polygons and Polylines are shapes formed using multiple connected lines . Polygon (เคฌเคนुเคญुเคœ) → Closed shape (เคถुเคฐुเค†เคค เค”เคฐ เค…ंเคค เคœुเฅœे เคนोเคคे เคนैं) Polyline (เคชॉเคฒीเคฒाเค‡เคจ) → Open shape (เคถुเคฐुเค†เคค เค”เคฐ เค…ंเคค เคœुเฅœे เคจเคนीं เคนोเคคे) 1️⃣ Polygon in Java เคœाเคตा เคฎें polygon เคฌเคจाเคจे เค•े เคฒिเค Graphics Class เค•े drawPolygon() เค”เคฐ fillPolygon() methods เค•ा เค‰เคชเคฏोเค— เคนोเคคा เคนै। To draw polygons in Java, we use Graphics Class methods drawPolygon() and fillPolygon() . Syntax / เคช्เคฐाเคฐूเคช: g.drawPolygon(int xPoints[], int yPoints[], int nPoints); g.fillPolygon(int xPoints[], int yPoints[], int nPoints); xPoints[] → X-axis เค•े เคธเคญी points yPoints[] → Y-axis เค•े เคธเคญी points nPoints → เค•िเคคเคจे points polygon เคฎें เคนोंเค—े Example 1: Draw a Triangle import java.applet.Applet; import java.awt.*; public class PolygonExample extends Applet { public void paint(Graphics g) { int...

Draw Arc and Filled Arc in Java (Graphics Class)

In Java, we can draw shapes like arcs or semi-circles using  Graphics Class  methods  drawArc()  and  fillArc() . เคœाเคตा เคฎें Arc เคฏा Semi-Circle เคœैเคธी เค†เค•ृเคคिเคฏाँ เคฌเคจाเคจे เค•े เคฒिเค Graphics Class เค•े drawArc() เค”เคฐ fillArc() methods เค•ा เค‰เคชเคฏोเค— เค•िเคฏा เคœाเคคा เคนै। 1️⃣ drawArc() Method เคฏเคน เคฎेเคฅเคก เค•ेเคตเคฒ arc เค•ी outline เคฌเคจाเคคा เคนै। This method only draws the outline of an arc . Syntax / เคช्เคฐाเคฐूเคช: g.drawArc(int x, int y, int width, int height, int startAngle, int arcAngle); x, y → เคตเคน เคชॉเค‡ंเคŸ เคœเคนां เคธे rectangle เค•ा top-left corner เคถुเคฐू เคนोเค—ा width, height → arc เค•ो เค˜ेเคฐเคจे เคตाเคฒे rectangle เค•ी เคšौเคก़ाเคˆ เค”เคฐ เคŠँเคšाเคˆ startAngle → arc เค•เคนाँ เคธे เคถुเคฐू เคนोเค—ा (0° = 3 o’clock direction) arcAngle → arc เค•ा degree (positive = anticlockwise, negative = clockwise) 2️⃣ fillArc() Method เคฏเคน เคฎेเคฅเคก arc เค•ो color เคธे เคญเคฐ เคฆेเคคा เคนै । This method fills the arc with the current color . Syntax / เคช्เคฐाเคฐूเคช: g.fillArc(int x, int y, int width, int height, int startAngle, int arcAngle); Example 1: Draw Simple Arc i...