Skip to main content

Posts

Showing posts with the label java

5 class design principles [S.O.L.I.D.] in Java

Classes are the building blocks of your java application. If these blocks are not strong, your building (i.e. application) is going to face the tough time in future. This essentially means that not so well-written can lead to very difficult situations when the application scope goes up or application faces certain design issues either in production or maintenance. On the other hand, set of well designed and written classes can speed up the coding process by leaps and bounds, while reducing the number of bugs in comparison. In this post, I will list down 5 most recommended design principles, you should keep in mind, while writing your classes. These design principles are called SOLID, in short. They also form the best practices to be followed for designing your application classes. Single Responsibility Principle Open Closed Principle Liskov’s Substitution Principle Interface Segregation Principle Dependency Inversion Principle Lets drill down all of them one by ...

20 very useful Java code snippets for Java Developers

Following are few very useful Java code snippets for Java developers. Few of them are written by me and few are taken from other code reference. Feel free to comment about the code and also add your code snippet. 1. Converting Strings to int and int to String String a = String.valueOf( 2 );   //integer to numeric string int i = Integer.parseInt(a); //numeric string to an int 2. Append text to file in Java Updated: Thanks Simone for pointing to exception. I have changed the code. BufferedWriter out = null ; try {      out = new BufferedWriter( new FileWriter(”filename”, true ));      out.write(”aString”); } catch (IOException e) {      // error processing code } finally {      if (out != null ) {          out.close();      } } 3. Get name of current method in Java Stri...