Monday, May 20, 2013

SED Command Examples in UNIX and Linux, Find and Replace using Regular Expression

SED command in UNIX  is stands for stream editor and it can perform lot's of function on file like, searching, find and replace, insertion or deletion. Though most common use of SED command in UNIX is for substitution or for find and replace. By using SED you can edit files even without opening it, which is much quicker way to find and replace something in file, than first opening that file in VI Editor and then changing it. In this SED command tutorial we will see some practical examples of SED command in UNIX based systems e.g. Linux. I must say having a good grip on find, grep, sort, vi editor and SED can take you next level of UNIX and Linux working experience. These are very powerful UNIX command and helps with lot of different tasks in server. By the way we will use following text file for our SED common example. As I have said before, best way to learn any UNIX command is to use them in your day to day task, and a good example is a good start. This file contains details of some popular android and iPhone smartphones, e.g. Model, company, price etc, separated by colon. You can also use any CSV file for this example.

Friday, May 17, 2013

How to Generate Random Numbers in Java between Range - Example Tutorial

In software development and programming world we often needs to generate random numbers, some time random integers in a range e.g. 1 to 100 etc. Thankfully, Random number generation in Java is easy as Java API provides good support for random numbers via java.util.Random class, Math.random() utility method and recently ThreadLocalRandom class in Java 7, along with more popular features like String in Switch and ARM blocks. While random() method seems most convenient way of generating randoms in Java it only return random doubles, on the other hand by using Random,  you can generate pseudo-random integer, floating point numbers e.g. double and even random boolean values. In this article Java tutorial, we will see how to generate random numbers in Java, examples to generating random integers and real numbers, and random numbers within a range e.g. between 1 to 6. we will also explore difference between Math.random() and java.util.Random class in Java.

Tuesday, May 14, 2013

Difference between Abstract class vs Interface in Java and When to use them

When to use interface and abstract class is one of the most popular object oriented design questions and almost always asked in Java, C# and C++ interviews. In this article, we will mostly talk in context of Java programming language, but it equally applies to other languages as well. Question usually starts with difference between abstract class and interface in Java, which is rather easy to answer, especially if you are familiar with syntax of Java interface and abstract class. Things start getting difficult when interviewer ask about when to use abstract class and interface in Java, which is mostly based upon solid understanding of popular OOPS concept like Polymorphism, Encapsulation, Abstraction, Inheritance and Composition. Many programmer fumbles here, which is natural because most of them haven't gone through real system design process and haven’t seen the impact of choosing one over other. Repercussion of design decisions are best known during maintenance phase, a good design allows seamless evolution while maintaining a fragile design is nightmare. As I have said previously, some time object oriented design interview questions also helps to understand a topic better, but only if you are willing to do some research and not just mugging the answer. Questions like when to use abstract class and interface falls under same category. In order to best understand this topic, you need to work out some scenarios, examples etc. It's best to get this kind of knowledge as part of your work but even if you don't get there, you can supplement them by reading some good books like Head First design pattern and doing some object-oriented software design exercises. In this article, we will learn difference between abstract class and interface in Java programming language and based upon our understanding of those differences, we will try to find out some tips and guidelines to decide when its better to use abstract class over interface or vice-versa.
SoftwareTop Blogs Visit blogadda.com to discover Indian blogs Computers BlogsWeb Directory