In Java, files can be processed by either streams or buffers. java.io Library – helps in file processing by streams, where this is a classic one.java.nio Library – helps in file processing by buffers, using nio(non blocking IO) is the latest one supported from Java 1.5 Streams are used to process files in Java.io package. … Continue reading “Read/Write File In Java (java.io)”
Category: Java
Polymorphism
1. Overview Polymorphism refers to different behavior of an object for same method name in Object Oriented Programming. Every child class can have different unique behavior for the method it extends from the Parent class or more than one method with same name with different arguments behave differently. All child class has its own unique … Continue reading “Polymorphism”
Abstraction
Abstraction is a concept in Object oriented programming where only required behavior and property will be shown/visible to the user/application. In Java, data abstraction can be done in Java using abstract class / Interfaces. Abstract Class are classes where we cannot create objects, however classes which are extending have to implement those functionalities, not defined … Continue reading “Abstraction”
Inheritance what?&why?
Inheritance is an important feature where a class can be extended and reused by another class. A inherited class can be called as subclass or childclass. The class which is inherited is called as Base class or Parent class or Super class. The main advantage of inheritance is re-usability. A class can be extended in … Continue reading “Inheritance what?&why?”
String vs StringBuffer
String is a final class hence cannot be extended by any class. Any class which cannot be extended can also be called as immutable class. StringBuffer is a class which can be extended (mutable). Every time a new string is appended/added/removed to a string object, it creates a new string object and added to the … Continue reading “String vs StringBuffer”
Classes & Objects
Java is a object Oriented Programming language. Programming deals with defining objects states and behaviors. In Java, Objects are logical representation of a real world objects or a conceptual thing. Class is a template, which defines the structure of the Object and its behavior.Using a class, we can create any number of objects., Example:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
Class Vehicle { int numberOfWheels; int numberOfDoors; String vehicleName; public void startEngine() { System.out.println("Execute ON Engine Command"); } public void shutDownEngine() { System.out.println("Execute OFF Engine Command"); } } public class Driver { public static void main(String args[]) { Vehicle car = new Vehicle(); Vehicle bike = new Vehicle(); } } |
Zip/UnZip Multiple Files In Java
For Zipping a file in Java, we have to Get the File Stream or Byte Stream Initialize a ZipOutputStream. Create a ZipEntry for each files or byte arrays and add it in ZipOutputStream and close the Zip Entry. Once completed, update the ZipOutputStream by calling finish(). Save it using FileOutputStream or Get the bytearray using … Continue reading “Zip/UnZip Multiple Files In Java”
CountdownLatch
CountDownLatch is another concurrency class, in which makes one thread wait for other until it reaches the threshold limit mentioned.Reach for the threshold limit, is counted by calling countdown() method present in CountDownLatch class.Every time countdown() method is called, the count is decremented by 1, finally when arrives at zero, the awaiting will stop. Assume … Continue reading “CountdownLatch”
Observer Design Pattern
Observer Pattern is design Pattern which describes one to many relationship, which helps in publisher-subscriber model, where one publisher can notify to multiple subscribers.Usually one or more subscriber classes will be there for this pattern, and these classes will be notified based on the publisher notification change. Java Swing listeners are part of an Observer … Continue reading “Observer Design Pattern”
ForkJoinPool
ForkJoinPool is the core of the concurrency frameworks which follows divide and conquer approach in completing the tasks. Fork – Recursively break the single task into multiple smaller tasks till the threshold. Join – Join the multiple smaller tasks results and produce the output recursively. Initialise the maximum number of worker threads.
1 |
ForkJoinPool forkJoinPool = new ForkJoinPool(3); |
RecursiveAction class … Continue reading “ForkJoinPool”