package test.test;
import java.io.File;
public class Test {
public static void main(String[] args) {
filePrintUtil("/Users/poddepally/Downloads");
}
private static void filePrintUtil(String pathName) {
File file = new File(pathName);
File[] listFiles = file.listFiles();
for (File currentFile : listFiles) {
if (currentFile.isFile()) {
System.out.println(currentFile.getName()
+ ", length(bytes) =" + currentFile.length()
+ ", parent = " + currentFile.getParentFile().getName());
} else {
filePrintUtil(currentFile.getAbsolutePath());
}
}
}
}
Saturday, 31 August 2019
[Java] Print all the files under a given directory
Print all the files under a given directory. If there are subdirectories traverse them recursively and figure out all the files inside it.
Friday, 16 August 2019
Class Loaders in Java
Class loaders in the JVM is responsible for looking out for the requested class and load it on demand. Unless set otherwise, class loaders look at the default class path locations of java installation such as {JRE_HOME}/lib/rt.jar and {JRE_HOME/ext}. rt.jar file holds the java core class files such as String, integer, etc.
You can set the class path of the application by -cp flag while compilation/execution.
Java contains following type of class loaders by default:
Class loaders follows delegation model while looking for class file. That is, class loader will delegate the load process to parent class loader, if not found, takes the responsibility to load the requested class.
You can set the class path of the application by -cp flag while compilation/execution.
Java contains following type of class loaders by default:
- Bootstrap class loader: Looks for class files such as java.lang.* in rt.jar
- Extension class loader: Looks for class file in /ext location.
- Application class loader: Looks for class file in the location set by the application.
Class loaders follows delegation model while looking for class file. That is, class loader will delegate the load process to parent class loader, if not found, takes the responsibility to load the requested class.
Saturday, 3 August 2019
HTTP Status Codes
HTTP status codes are categorised into 5 buckets. These are very helpful during API development such as REST APIs.
| Status Code | Meaning |
|---|---|
| 1xx | informational |
| 2xx | Success |
| 3xx | Redirection |
| 4xx | Client error |
| 5xx | Server error |
Saturday, 27 July 2019
Design patterns in java
Design Pattern is a reusable and named solution to a recurring problem in a context.
There are 3 categories of patterns when classified by the purpose:
- Structural Design Patterns
- Strategy Pattern: Defines a family of algorithms, encapsulates them and makes them interchangeable thus Strategy lets algorithm vary independently from the clients that use it. Example: Collections Java, List
- Creational Design Patterns: Allows creational of the objects
- Abstract Design factory pattern
- Behavioural Design Patterns
- The Gang of Four: The Definitive Design Patterns Book
- Head first Design patterns
Thursday, 25 July 2019
Object Oriented Programming
Building blocks of OOP:
- Abstraction:
- Showing the essential details by hiding the complexity.
- In Java, achieved by Interfaces, Abstract classes.
- Encapsulation:
- Hiding the information. Can be field level or behavioural level.
- In Java, achieved by access specifiers.
- Inheritance:
- Inhering properties, methods of another class to avoid code duplication.
- In Java, achieved Extending a class or implementing any interface.
- Polymorphism:
- Allows the actual object to be decided at runtime, basically a subclass/interface can stand in for super class.
- In Java, achieved Extending a class or implementing any interface.
SOLID Principles
- Single Responsibility Priniciple
- One class should own a single responsibilty.
- Open-Closed Priniciple
- classes should be open for extension, closed for modification.
- Can be achieved by inheritance.
- Liskov Substitution Principle
- When you inherit a class, you should be able to substitute super class methods on sub class methods without any hussle.
- Interface segregation Principle
- Seggregate the interfaces in a way client can use.
- Dependency injection Principle
- High level module should not depend on low level module.
- Favor composition over inheritence.
- Program to an interface not implementation.
- DRY: Donot repeat yourself
Saturday, 29 December 2018
Best tutorials online
Following are some of best free tutorials that I come across online. These are super cool to follow.
Youtube channel: https://www.youtube.com/channel/UCYt1sfh5464XaDBH0oH_o7Q
Java tutorials:
Java Brains:
Official website: https://javabrains.ioYoutube channel: https://www.youtube.com/channel/UCYt1sfh5464XaDBH0oH_o7Q
jenkov tutorials:
Official website: http://tutorials.jenkov.com/Design Patterns:
Youtube channel(Christopher Okhravi): https://www.youtube.com/channel/UCbF-4yQQAWw-UnuCd2AzfzgSystem Design:
Tech Dummies channel on youtube:
Educative Course on System design:
Gaurav Sen's channel on youtube:
Object Oriented Design:
Educative course:
Sunday, 5 February 2017
SecureString in PowerShell
If you want to read secure string from a prompt, do the following:
$mySecureString = Read-Host 'Enter the string' -AsSecureString
To convert the SecureString to string, do the following:
$string= [Runtime.InteropServices.Marshal]::PtrToStringAuto([Runtime.InteropServices.Marshal]::SecureStringToBSTR($mySecureStrring))
Subscribe to:
Posts (Atom)