Posts

QA's approach 2 Java - File Handling -FileReader & FileWriter

Image
File Handling - Learn through Examples To have an insights into File Handling theory, follow the link -  File Handling Theory    Byte Stream implementation examples: Example1. Read Data from file & write to another file using FileReader & FileWriter package fileHandling; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class CharacterStream { public static void main(String[] args) throws IOException { String sourcePath = "C:/Users/user/workspace/New folder/javaForQA/src/fileHandling/Input.txt"; String destinationPath = "C:/Users/user/workspace/New folder/javaForQA/src/fileHandling/Output.txt"; FileReader inputStream = null; FileWriter outputStream = null; try { inputStream = new FileReader(sourcePath); outputStream = new FileWriter(destinationPath); int c; while ((c = inputStream.read()) != -1) { outputStream.write(c); } } finally { if (inpu...

QA's approach 2 Java - File Handling -FileInputStream & FileOutputStream Examples

Image
File Handling - Learn through Examples To have an insights into File Handling theory, follow the link - File Handling Theory    Byte Stream implementation examples: Example1. Read Data from file & write to another file using FileInputStream & FileOutputStream The flow of Data in this example is structured as follows: Create a package as follows with Input.txt, Output.txt & CopyBytes Class file We are going to  Read data from Input.txt to Input Stream & then to CopyBytes.java   Write data from CopyBytes.java to Output Stream & then to Output.txt file The below is the Execution logic file - > CopyBytes Class file  package fileHandling; import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.IOException; public class CopyBytes { public static void main(String[] args) throws IOException { FileInputStream in = null; FileOutputStream out ...

QA's approach 2 Java - File Handling Theory

Image
Java IO is an API that comes with Java which is targeted at reading and writing data (input and output). Most applications need to process some input and produce some output based on that input. For instance, read data from a file or over network, and write to a file or write a response back over the network. The Java IO package is primarily focused on input and output to files, network streams, internal memory buffers etc. However, the Java IO package does not contain classes to open network sockets which are necessary for network communication. For that purpose you need to use the Java Networking API. Once you have opened a socket (network connection) though, you read and write data to and from it via Java IO's InputStream and OutputStream classes. Basic Terminologies: Stream:  A stream is a sequence of data.  Streams in Java IO can be either byte based (reading and writing bytes) or character based (reading and writing characters). Java defines two types of strea...

QA's approach 2 Java - Creating Java Doc's in Eclipse

Image
How to Create Java Docs in Eclipse Consider the Bank Interest Rate Calculator Application & lets see how to create Java docs using Eclipse for it. Navigate to Projects Tab->Select Generate java Docs, JavaDoc Generation Window appears Provide the path of javadoc.exe using Configure under Javadoc command section Next select the project or package for which you wanted to generate Java docs., Click Finish Click on index.html

QA's approach 2 Java - Bank Interest Rate Calculator Application exhibiting RunTimePolymorphism

Image
Learn Runtime Polymorphism through Practical Example Application Bank Interest Rate Calculator Application exhibiting Runtime Polymorphism used to retrieve the Interest Rate of Bank by providing the Bank details at Runtime. Create the package structure with class names as follows Create class name with Bank package runTimePolymorphsimSimpleExmp; public class Bank { // Default interest Rate public Float getInterest() { return 6.5f; } } Create class name with Sbi extending Bank package runTimePolymorphsimSimpleExmp; public class Sbi extends Bank{ // SBI specific interest Rate public Float getInterest() { return 6.25f; } } Create class name with Hdfc extending Bank package runTimePolymorphsimSimpleExmp; public class Hdfc extends Bank{ // HDFC specific interest Rate public Float getInterest() { return 6.75f; } } Create class name with Icici extending Bank package runTimePolymorphsimSimpleExmp; public class Icici extends...

QA's approach 2 Java - Data Structures

What is a Data Structure? Its a container or a storage box which holds a collection of elements as a single unit.  Its a class grouping multiple elements into single entity. What can be done on this container? 1. New elements can be added 2. Added elements can be retrieved 3. Added elements can be deleted or replaced 4. Elements can be copied from this container to another container Some Data structures allows duplicates [Lists], allows null values [Set], stores or prints elements in ascending order, etc..

QA's approach 2 Java - Abstract Class vs Interface Theory

Abstract Class vs Interface, Differences, when to use? Why not create an object? Interface Interface is used when you want to define a contract and you don't know anything about implementation. (here it is total abstraction as you don't know anything). Interface is used in a situation, 1. When you know the contract methods but don't know anything about the implementation. 2. Your contract implementation can change in future. 3. You want to achieve dynamic polymorphism and loose coupling that is by just changing one line of code, you should be able to switch between contract implementer. 4. Since multiple inheritance is not supported in Java, you cannot inherit your class from two abstract classes. An interface is your only option in such situations. 5. If there is no default or common behavior among all the classes that are inheriting from abstract class then interface may be a better choice. Example Analogy for point 1: Redbus interface lists out all t...