Java Thread Programming FAQ - 1

Thursday, January 29, 2009

Many a times as far as thread programming is concerned, the first thing which comes to our mind is the keyword synchronized (of course the other dangerous word is DEADLOCK!), because one can directly relate the word synchronized to java thread programming or in general to thread programming concepts, the designers of java were intelligent enough to define a new meaning to the keyword synchronized, simplifying the way multiple threads access a shared resource with the synchronized construct.

On one side, java thread programming may seem easy and interesting to learn with lots of excellent tutorials all around the web, but the real challenge comes when you use those concepts in your applications, many books have been written to cover the length and breadth of java thread programming in itself, when I was doing my SCJP 1.6, I found it very easy to learn and grasp the thread programming concepts from books, but when it comes to reading/writing code related to java threads and identifying hard to catch bugs, those learning skills differed from practice, which straightaway motivated me to write a FAQ series for java thread programming for my reference as well as yours.

I am writing this FAQ based on my experiences on java thread programming learning from mistakes, some of these when asked to yourself will bring more clarity to your understanding of java thread concepts. Lets start with some funny questions and then dig deep into it.

1. Why its a fun programming java threads?

Because there is no fun writing a java code without using threads in a real time application, also a programmer's understanding of java is not complete without a deep knowledge of threads, java game applications use threads, java stock ticker programs use threads, java server applications uses threads, J2ME applications use threads, so its always a fun to bring your own creativity in using threads wisely which would make a difference to thousands of end users.

2. Why its not so fun programming java threads?

Because you can not only kill threads in java but can kill the application as well with wrong usage of threads and there's always a DEADLOCK to add to the nightmare and its critical to ensure that your application is not a resource hog when it comes to fairplay when it's waiting for I/O, relinquishing control at the right time.

3. What are the methods of the Thread class and the Object class?

The following are some important methods of Thread class.

join()
sleep()
yield()
start()
run() - This is a method in Runnable interface but used here to distinguish between Thread and Object class methods in general (in the sense that it has to be implemented or overridden anyway by a thread).
interrupt()

The following are the important methods of Object class which are used by threads

wait()
notify()
notifyall()

4. What are the static and instance methods in a Thread class?

The following are the static methods in Thread class which apply to the currently running thread.

yield()
sleep()

The other methods that are specific to the Thread object are

start()
run()
join()
interrupt()

This is important to understand, the static and object methods in threads, there is a logic behind the static methods in the sense that the threads which voluntarily relinquish control and give a chance for other threads to run (fair play) would call the appropriate methods from their static contexts (when its a live thread running) and these methods should not be called on other thread objects, say an application thread A should not have the privilege to forcibly preempt another running thread, the operating system scheduler is there to take care of that.

5. What are the methods which are be called from synchronized context?

The following methods are called from synchronized context

All Object class methods which a thread may use as described above should be called from a synchronized context, like

wait()
notify()
notifyall()

The thread invoking these methods should have a lock on the object on which it calls these methods, an ideal example is a Producer-Consumer problem where a consumer thread waits for the producer to produce some data for reading(consuming), once its done, the producer notifies the consumer so that the consumer may read the data, the notifyall() method will notify multiple waiting threads, say for example a scenario where multiple reader threads reading the latest stock quote waits for the lock on a thread which gets the current stock quote and notifies them.

6. What are the thread methods which throws an exception which should be handled in a try/catch block?

join()
sleep()

The join() method joins after another thread completes or in other words stops execution and continue after the the thread on which it calls join completes, the sleep method goes to sleep state relinquishing control, both these calls can be interrupted by another thread so that they can come out from the wait/sleep state.

In addition, there are also other deprecated thread methods like stop, suspend, resume which throws SecurityException.

Ok, thats it for this post, we will see more code examples and other thread concepts in a future FAQ column.

Google Adsense Books and Online References

Monday, January 26, 2009

Over the past five years or so, Professional Blogging has come of ages with many success stories like Amit Agarwal, Darren Rowse, Joel Comm, Yaro Starak, Caroline Middlebrook to name a few, although the list doesn't end here, thanks to Google Adsense, an innovative idea to make money online through relevant ads which has taken online advertisement to a new high.

With that being said, there are enthusiastic wannabe professional bloggers all around the world looking for more information related to Google Adsense, Adwords, Ad Placement, Ad Optimization, Keywords, niche, etc, the problem is that with too much information, it really gets hard to find definitive a reference for Google Adsense for your success, When I began blogging, so was my case, although writing about technical subjects was my passion even otherwise, just wanted to add more spice to it by designing the blog well with the right templates for good user experience and of course some targeted and RELEVANT ads, so far it worked reasonably well and want to share some of the Google Adsense references which were very useful for me till date.

Even though there are lots of references on Google Adsense from code level to high level overview of its working, the following are some books/online references which I found were very effective, in the sense it says it all.

1. The AdSense Code: What Google Never Told You About Making Money with AdSense

Written by Joel Comm, this is a very reference which should be there in every professional blogger's bookshelf, of course if you use Google Adsense, even otherwise you can learn about finer aspects of designing a blog and techniques like Ad placement, Ad layouts, examples on how to blend relevant Ads with text which may be useful for the end user, keywords, etc. The title in fact puzzled me as it says "What Google Never Told You About Making Money With AdSense", initially I thought its all about making money through Adsense or generic tips on making money through Google Adsense, but when I completed the book I learnt a lot of technical aspects of Google Adsense as well, from Adsense code, Ad optimization, layout and placement, therefore my expectations were met.

There are lots of good reviews about this book and I am just one of the beneficiaries, in short if you want to be a professional blogger with Google Adsense as a revenue stream and want to work on it, then this is for you, the example sites mentioned in this book to illustrate different designs and Ad layouts are very valuable indeed and you need not be a core techie to go through those concepts and implement them.

Still want more data? Go through Darren Rowse's review on What Google Never Told You about Making Money with Adsense which motivated me to pursue this in first place.

2. Inside Adsense

The official blog for Google Adsense from Google Engineers, this is the page I usually land in for all updates related to Google Adsense from new features to tips for monetizing, exclusively for Adsense publishers, if you want to keep yourself up to date with the cool things happening in the Google Adsense world like the recent Ad Manager feature, then you should be one of its subscribers

There are still lot more things to add to the list, as and when I find something interesting ,be it a book or another definitive online resource for Google Adsense, it will be updated here.

PDF Text Parser: Converting PDF to Text in Java using PDFBox

Sunday, January 25, 2009

Converting PDF to text is an interesting task which has its use in many applications from search engines indexing PDF documents to other data processing tasks. I was looking for a java based API to convert PDF to text, or in other words a PDF Text parser in java, after going through many articles, the PDFBox project came to my rescue. PDFBox is a library which can handle different types of PDF documents including encrypted PDF formats and extracts text and has a command line utility as well to convert PDF to text documents.

I found the need to have a reusable java class to convert PDF Documents to text in one of my projects and the below java code does the same using the PDFBox java API. It takes two command line parameters, the input PDF file and the output text file, to which the parsed text from the PDF document will be written.

This code was tested with PDFBox 0.7.3 although it should work with other versions of PDFBox as well, it can be easily integrated with other java applications and can be used as a command line utility as well, the steps to run this code is furnished below.

Listing 1: PDFTextParser.java

1: /*
2: * PDFTextParser.java
3: * Author: S.Prasanna
4: *
5: */
6:
7: import org.pdfbox.cos.COSDocument;
8: import org.pdfbox.pdfparser.PDFParser;
9: import org.pdfbox.pdmodel.PDDocument;
10: import org.pdfbox.pdmodel.PDDocumentInformation;
11: import org.pdfbox.util.PDFTextStripper;
12:
13: import java.io.File;
14: import java.io.FileInputStream;
15: import java.io.PrintWriter;
16:
17: public class PDFTextParser {
18:
19: PDFParser parser;
20: String parsedText;
21: PDFTextStripper pdfStripper;
22: PDDocument pdDoc;
23: COSDocument cosDoc;
24: PDDocumentInformation pdDocInfo;
25:
26: // PDFTextParser Constructor
27: public PDFTextParser() {
28: }
29:
30: // Extract text from PDF Document
31: String pdftoText(String fileName) {
32:
33: System.out.println("Parsing text from PDF file " + fileName + "....");
34: File f = new File(fileName);
35:
36: if (!f.isFile()) {
37: System.out.println("File " + fileName + " does not exist.");
38: return null;
39: }
40:
41: try {
42: parser = new PDFParser(new FileInputStream(f));
43: } catch (Exception e) {
44: System.out.println("Unable to open PDF Parser.");
45: return null;
46: }
47:
48: try {
49: parser.parse();
50: cosDoc = parser.getDocument();
51: pdfStripper = new PDFTextStripper();
52: pdDoc = new PDDocument(cosDoc);
53: parsedText = pdfStripper.getText(pdDoc);
54: } catch (Exception e) {
55: System.out.println("An exception occured in parsing the PDF Document.");
56: e.printStackTrace();
57: try {
58: if (cosDoc != null) cosDoc.close();
59: if (pdDoc != null) pdDoc.close();
60: } catch (Exception e1) {
61: e.printStackTrace();
62: }
63: return null;
64: }
65: System.out.println("Done.");
66: return parsedText;
67: }
68:
69: // Write the parsed text from PDF to a file
70: void writeTexttoFile(String pdfText, String fileName) {
71:
72: System.out.println("\nWriting PDF text to output text file " + fileName + "....");
73: try {
74: PrintWriter pw = new PrintWriter(fileName);
75: pw.print(pdfText);
76: pw.close();
77: } catch (Exception e) {
78: System.out.println("An exception occured in writing the pdf text to file.");
79: e.printStackTrace();
80: }
81: System.out.println("Done.");
82: }
83:
84: //Extracts text from a PDF Document and writes it to a text file
85: public static void main(String args[]) {
86:
87: if (args.length != 2) {
88: System.out.println("Usage: java PDFTextParser ");
89: System.exit(1);
90: }
91:
92: PDFTextParser pdfTextParserObj = new PDFTextParser();
93: String pdfToText = pdfTextParserObj.pdftoText(args[0]);
94:
95: if (pdfToText == null) {
96: System.out.println("PDF to Text Conversion failed.");
97: }
98: else {
99: System.out.println("\nThe text parsed from the PDF Document....\n" + pdfToText);
100: pdfTextParserObj.writeTexttoFile(pdfToText, args[1]);
101: }
102: }
103: }
Explanation:

The above code takes two command line parameters, the input PDF file and the output text file, the method pdftoText in line 31 handles the text parsing functionality and the writeTexttoFile method in line 70 writes the parsed text to the output file.

Compliling and Running the code:

I used PDFBox 0.7.3 to compile/run the above code, so you need to add those jars in your java project settings.

1. Download PDFBox 0.7.3 from here.
2. Unzip PDFBox-0.7.3.zip.
3. Under the PDFBox-0.7.3 folder, add the jars in the lib (PDFBox-0.7.3.jar) and external directory (other external packages used by PDFBox-0.7.3) to the classpath to compile/run the code, it should work fine.

Note: I used JDK 1.6 to compile the above code.

Division of two numbers without using division operator, Algorithm, C - Code

Saturday, January 24, 2009

I was asked for the C solution for this by some of my friends, the code for division of two numbers without using the division operator, even though I had written about it in my sun blog using python, this time I would like to explain the code for division of two numbers without divide operator using the C language which would be useful for C fans as well.

For the sake of completeness, I would like to highlight the algorithm, which is quite simple. Before that one should understand some basics of bit shifting.

1. Left shifting an unsigned number by 1 multiplies that number by 2.
2. Right shifting an unsigned number by 1 divides that number by 2.

Therefore the procedure for the division algorithm, given a dividend and a divisor would be to left shift (multiply by 2) the divisor till it reaches dividend/2, then continue this routine with the the difference between the dividend and divisor and divisor till the point where dividend is less than divisor or their difference is zero. This is similar to finding an element in a sorted list using the binary search algorithm, the C code is furnished below.

Listing 1: division_bitshifting.c

 1: /* 
2: Division of two numbers without using division operator
3: Author: S.Prasanna
4: */
5:
6: #include<stdio.h>
7:
8: int dividend, divisor, remainder;
9:
10: /* Division function Computes the quotient and remainder of two numbers
11: using bit shifting */
12: int division(int tempdividend, int tempdivisor) {
13:
14: int quotient = 1;
15:
16: if (tempdivisor == tempdividend) {
17: remainder = 0;
18: return 1;
19: } else if (tempdividend < tempdivisor) {
20: remainder = tempdividend;
21: return 0;
22: }
23:
24: while (tempdivisor <= tempdividend) {
25: /* Here divisor <>
26: divisor and quotient */
27: tempdivisor = tempdivisor << 1;
28: quotient = quotient << 1;
29: }
30:
31: /* We have reached the point where divisor > dividend,
32: therefore divide divisor and quotient by two */
33: tempdivisor = tempdivisor >> 1;
34: quotient = quotient >> 1;
35:
36: /* Call division recursively for the difference to get the
37: exact quotient */
38: quotient = quotient + division(tempdividend - tempdivisor, divisor);
39:
40: return quotient;
41: }
42:
43: /* Division of two numbers without using division operator */
44: void main() {
45:
46: printf ("\nEnter the Dividend: ");
47: scanf("%d", &dividend);
48: printf("\nEnter the Divisor: ");
49: scanf("%d", &divisor);
50:
51: printf("\n%d / %d: quotient = %d", dividend, divisor, division(dividend, divisor));
52: printf("\n%d / %d: remainder = %d", dividend, divisor, remainder);
53: getch();
54: }
The algorithm explanation is very simple, the division function in line 12 is a recursive procedure which implements the division logic described above using bit shift operators, the best way to understand it would be to execute the above division algorithm with break points or debuggers to track the flow.

DirectX Installation Problem - Possible Solution

Monday, January 19, 2009


Today I was trying to uninstall DirectX from my Windows XP box to install the latest DirectX version (DirectX 9C), for newbies DirectX is a collection of APIs used to handle multimedia applications in Windows platforms, its mainly designed for game programming to improve their performance using the DirectX video acceleration feature. The terms DirectDraw, Direct3D, DirectPlay, DirectSound, DirectMusic are often synonymous with DirectX and the DirectX runtime in general powers multimedia games in Windows.

Though there is no uninstaller available for DirectX, I tried to remove DirectX by removing the registry entry by Googling for DirectX uninstallation. For uninstalling DirectX, I removed the DirectX registry entry on Windows XP by running regedit and removing DirectX key (HKEY_LOCAL_MACHINE -> SOFTWARE -> Microsoft -> DirectX).

Now to install DirectX (DirectX 9c), I used the DirectX web setup procedure as can be found in Microsoft's DirectX End-User Runtime Web Installer page here.

But then, the installation failed throwing the below error message as shown in the screenshot below.

Fig 1: DirectX Web setup installation failure error

Fig 2: DirectX Web setup installation failure

The partial installation error log is shown below (DXError.log in C:\Windows\Logs)

Current DirectX may be a older version which does not have directx key in the registry.

--------------------
[01/19/09 16:10:21] module: dxupdate(Oct 27 2008), file: dxupdate.cpp, line: 4515, function: DirectXUpdateDownloadPlugIn

GetDXVersion() failed.

--------------------
[01/19/09 16:10:22] module: DXWSetup(Oct 27 2008), file: dxupdate.cpp, line: 386, function: DownloadPlugIn

DirectXUpdateDownloadPlugIn() failed.

--------------------
[01/19/09 16:10:22] module: DXWSetup(Oct 27 2008), file: psheets.cpp, line: 498, function: PreinstDlgProc

DownloadPlugIn() failed.

--------------------
[01/19/09 16:11:33] module: dxupdate(Oct 27 2008), file: dxupdate.cpp, line: 175, function: GetDXVersion

Failed API: RegOpenKeyEx()
Error: (2) - The system cannot find the file specified.

The registry key removal caused the installation problem, therefore NEVER remove any DirectX registry entry to uninstall DirectX, unless you have a proper uninstallation procedure, which DirectX doesn't have currently, don't try to remove DirectX by other means, or if you do so, take a backup of your registry, then the dxdiag diagonostic tool also displayed a Version not found message as shown in the figure below.

Fig 3: dxdiag showing DirectX version not found after the DirectX registry entry is removed

The Solution: Now I need to make sure that the installation procedure succeeds, somehow I need to recreate the DirectX registry entry. Therefore I looked at another Windows XP box and found that DirectX entry and recreated the DirectX registry key with its value (HKEY_LOCAL_MACHINE -> SOFTWARE -> Microsoft -> DirectX) in my box as shown in the figure below.


Fig 4: DirectX Registry Entry

Creating the DirectX entry is very simple, all you need to do is

1. Open regedit
2. Go to HKEY_LOCAL_MACHINE -> SOFTWARE -> Microsoft
3. Right click, create a new Key DirectX
4. Goto DirectX, create a new binary Value InstalledVersion and assign the value shown above
5. Create another String named Version and assign the value shown above

Unfortunately, the version I entered is the latest DirectX release version (from the other Windows XP box), so the installer assumed that my system was installed with the latest version after checking the DirectX registry entry and therefore didn't install DirectX 9.

Then I did one more tweak, which is modifying the DirectX Version string to 0.00.00.0000 in the DirectX registry entry (Open regedit, Go to HKEY_LOCAL_MACHINE -> SOFTWARE -> Microsoft -> DirectX, right click the Version String, click modify and change its value to 0.00.00.0000), as shown in the below figure.


Fig 5: Changing Version String in DirectX

Upon invoking the installer, this time it worked fine, it downloaded and installed the latest DirectX version as was shown in the figure below.

Fig 6: DirectX Installation completed Successfully

The lesson: Never remove registry entry to uninstall anything.

A list of free text editors with enhanced features

Sunday, January 18, 2009

Sometimes having a text editor which would provide enhanced features like syntax highlighting, large size file handling, improved editing functionality, tabbed display and so on would increase the productivity of programmers to a great extent and in that sense I will list some free text editors which are doing a great job in this area, giving a better user experience with their own feature set which would make life easy for any software developer.

These are some of the ones which I use frequently and thought it would be wise to list them to not only for evangelizing, but to list the options you have for selecting your own text editor with extra features, although this list would not be complete with cool text editors evolving time and again, the features and the experience of using these text editors should give you an idea of how far the text editors have come of their age from notepad days.

1. Crimson Editor:

A simple, yet powerful and professional source code editor for Windows, which I use most often, some of the features include syntax highlighting for multiple languages like Java, C, C++ and so on with tabbed display (a defacto standard these days in all applications from text editors to browsers). One can also extend their syntax highlighting feature to other languages using a custom syntax file, although I haven't tried it, it allows extensibility of the syntax highlighting feature for a language of your choice. The text editor loads quickly and lists previously opened files each time you invoke it and automatic reloading from disk enhances the feature set of this cool text editor.


Its name says it all, the symbol ++ has earned its own distinction not only in arithmetic, but also as a super set and this editor justifies the use of ++ quite comprehensively. Though I don't want to get into the individual features of this powerful editor as it it listed in their web and some features are quite common in other enhanced text editors as well, but I love the interface it has, trivial feature as you may call it, the line number display for code still has its influence on programmers troubleshooting code, also I heard from some of my friends that it can handle large files as well. WYSIWYG (What You See Is What You Get) style printout of source code, auto completion feature for popular languages and macro recording makes it my favorite choice of an open source editor, sourceforge rocks!


This editor does more than text edit though, as I mentioned earlier every editor has its own distinctive features which makes it unique, so is the case with this. A very convenient feature is the file system view in the left tab through which you can easily navigate your target file or source, file comparison utility is is a handy feature when you have different versions of source code to identify the changes. Overall, an editor which looks for ways to innovate with browser style features like bookmarking and unlimited undo/redo (looks like there are some who rollback too many changes to their dislike).


This is the text editor for you if you need a free version, but can pay for more advanced features (like spell checker and other customizations) with full support. The award winning editor has a Wordpad like appearance, but with their own extensions and additional features, would offer more, their basic version Notetab Light is a freeware although you can download the evaluation version of Notepad pro to see how it would suit for you.

Though these are my personal choices, the advanced text editor world doesn't end here, for a complete list of enhanced text editors and the features they support, do look at this wikipedia article which has a comparison table of all sophisticated text editors with respect to some standard enhanced features.

The sed command in Unix and Linux and its common usage

Wednesday, January 14, 2009

In my last post on shell programming, we have seen how to use grep command to search patterns in files and print them, coupled with some useful text manipulation commands with grep with other commands like sed. The grep command used with other commands or piped to other commands is something we should avoid as we become a mature UNIX programmer because when the pattern matching task becomes more sophisticated, one should use specialized commands like sed to accomplish the task.

I always wanted to explore sed as using grep command beyond whats it there for always resulted in an unreadable code, therefore I explored sed for sometime and decided to list some common applications of sed command in pattern matching and text manipulation which I hope will be useful for other UNIX programmers also.

As always, for some customary introduction about sed (stream editor), its a command used to read text files line by line and search, substitute, remove lines matching a pattern and does many other interesting text manipulation functions. It outputs the transformed text to the console by default, although you can redirect it to another file or selectively supress it using one of the sed options. Most applications of sed command were in text substitution, but its not limited to it.

The sed command ....

sed options sed-script filename

Though a man page will help you in this, some common options in sed are listed below

sed -e filename - Executes an inline sed-script on the input file (although it can be used to execute multiple line sed commands by using \ separator, the wise way is to use a sed script file for that).
sed -f filename - Execute the series of sed commands in sed-script-file on the input file
sed -n filename - Doesn't print the result of the sed command to the console by default, instead one should use the "/p" flag inside the sed command/script to print the desired output.

Applications of sed command:

sed command can be used to search and manipulate input text in many ways, though mainly used for substitution, it can also do numerous other pattern matching tasks like searching and printing lines which matches a pattern, removing lines which matches a pattern, deleting specific lines in the input file, etc, some common uses of sed command were shown below.

For the sake of simplicity and to make life easy, we won't be using any of the sed command line options described above, starting from simple ones, here we go.

The text file used to illustrate the below sed commands is shown below.
bash-3.00# cat textfile.txt
This is line 1
This is line 2
This is line 3
This is line 4
This is line 5
bash-3.00#
1. Deleting lines in a file using sed command

1.1. Deleting the first line in the input file
bash-3.00# sed '1d' textfile.txt
This is line 2
This is line 3
This is line 4
This is line 5
1.2 Deleting the last line in the input file
bash-3.00# sed '$d' textfile.txt
This is line 1
This is line 2
This is line 3
This is line 4
bash-3.00#
1.3 Deleting arbitary lines in the input file

To delete the lines 2 through 4 in the above file, use the following sed command
bash-3.00# sed '2,4d' textfile.txt
This is line 1
This is line 5
the 'd' flag is used to delete lines, though the single quote is not mandatory in the above commands (you can simply use sed 1d textfile.txt to delete the first line in the input file), its advisable to use it as a good practice and will be useful when you use the -e option at times to execute a series of sed commands inline.

2. Replace or substitute all occurrences of a pattern using sed command

In the above text file, if you need to replace all occurrences of the pattern "line" with the text "line number", the following sed command can be used (the 's' flag in the sed command is used to substitute text which matches a pattern).
bash-3.00# sed 's/line/line number/g' textfile.txt        
This is line number 1
This is line number 2
This is line number 3
This is line number 4
This is line number 5
Note: The /g flag in the above command is used to instruct sed to substitute globally i.e all occurrences of the input pattern in the line will be replaced and as a result all words matching the pattern in the input file will be substituted by the other, without /g only the first word matching the pattern in a line will be replaced.


3. Delete all occurrences of a pattern in a file using sed command

This is a simple application of the /s flag where the target string is none.

For example, to remove all occurrences of word "line" in the above file, the sed command would be
bash-3.00# sed 's/line//' textfile.txt
This is 1
This is 2
This is 3
This is 4
This is 5
Note that the word to be replaced upon matching the pattern is none in the above command ('/s/line//')

To remove all occurrences of the character space in the above input file, the sed command would be
bash-3.00# sed 's/ //g' textfile.txt
Thisisline1
Thisisline2
Thisisline3
Thisisline4
Thisisline5
Also note that if you don't use single quotes in the above sed command, then the space pattern should be enclosed in quotes for the command to work.
bash-3.00# sed s/' '//g textfile.txt
Thisisline1
Thisisline2
Thisisline3
Thisisline4
Thisisline5

4. Deleting lines which matches a pattern using sed command

To delete lines which matches a pattern, use the /d flag along with the pattern to be matched, for example, to delete lines matching the pattern "line 1" in the above file, the command would be
bash-3.00# sed '/line 1/d' textfile.txt
This is line 2
This is line 3
This is line 4
This is line 5
Now using the above commands, one can also delete the first and last line in a file which matches a pattern.

5. Deleting the first line which matches a pattern using sed command
bash-3.00# sed '/line/{1d;}' textfile.txt
This is line 2
This is line 3
This is line 4
This is line 5
In the above command, '1d' is used in braces to indicate that its a command (to delete the specific line, which matches a pattern), this is the way to separate sed flags in command/scripts.

6. Deleting the last line which matches a pattern using sed command
bash-3.00# sed '/line/{$d;}' textfile.txt
This is line 1
This is line 2
This is line 3
This is line 4
Hope you got to know some common sed command functionality, the next time if you think about sed instead of grep/sed pipe for text processing, you have improved a level in UNIX shell scripting.

Blogging books and online resources for beginners

Thursday, January 8, 2009

When you start blogging, the questions which might flash immediately are

1. Which platform to choose
1. How to get ideas for your blog
3. How to get traffic, improve page rank, SEO, etc
4. How to attract and RETAIN (not so easy part) visitors to the blog
5. How to be a professional blogger (everything from your blog title, URL and the text matters)
6. How to monetize your blog

Questions galore, but even though the above questions are common and may seem quite trivial, the answers are not, in this article I want to share my experience on some good readings on this subject, if you are serious about blogging, be it a full time or part time or hobby, the following readings and websites may be helpful.



This is the ideal beginners book for wannabe professional, full time bloggers. It just has four simple chapters, Planning, Publishing, Profiting from a blog and doing your own blogging business, though I brought to get learn finer aspects of professional blogging, but then realized that this book is for beginners to get a grip on blogging on their way to becoming a professional blogger.

What you will learn.... Most of the things would seem trivial to you if you already blog, but you will learn a lot of new things as well like popular blogging applications, services, hosted and free blogs, their pros and cons and selecting the right platform which will suit for you, etc, also there are good tips on how to add relevant ads which would suit your blog, which platforms are Ad friendly in that you can easily deploy your ad, etc.

The other parts of this book covers on details like how to generate traffic (like which sites you need to submit your blog to get more search results), page rank and SEO services.

The last part of this reading discusses about the most exciting part, i.e profiting from a blog, the ways to generate revenue, the sources for regular stream of revenue, the effective and popular advertising/affiliate vendors, finally it sums up well with making your own business out of a blog after you know the basics, in my opinion, this should be the FIRST book in blogging for beginners as its just short and sweet, I just completed this one travelling in a flight.

2. ProBlogger: Secrets for Blogging Your Way to a Six-Figure Income

This is the book you should start once you complete the previous one, assuming that you have the basic knowledge about blogging and want to fine tune your blogging skills in your quest to become a ProBlogger, then you landed on the right place. Though I brought this one to get more technical details on how to customize blog layouts, monetize, etc, but this book somehow satisfied me in the sense that I got some new information which I can effectively put into use.

Like any other blogging books, Darren Rowse mentions his background too, how he lived, blogged and how that interest turned him into a professional blogger in years, everything in a short and concise way,which should be inspiring for any aspiring ProBlogger, giving a prelude about his journey to achieving six figure income through blogging should motivate any ProBlogger for sure.

Unlike the first book which is for beginners, here you will learn some specific steps to set up your blog platform, selecting the blogging service, how to find a topic of interest, the business oppurtunity, some common pitfalls to avoid, SEO services, tracking, retaining visitors and monetizing, I am sure that this would be your way to six figure income as well one day if you use wisely.

Online References:

1. http://www.problogger.net/ - Darren Rowse's blog for ProBloggers, an excellent online resource for bloggers of all level.
2. http://www.labnol.org/ - The official blog of Amit Agarwal, India's only professional full time blogger till date who writes about technology, but do read his about me page which should motivate ProBloggers to reaffirm their belief that one can be successful as a blogger and make a comfortable living out of it,also he has some excellent articles on blogging basics.

Finally some small tips from a rookie blogger (which is me)....

1. Once you start blogging, just go on and on and on without any stops.
2. Read and learn from all resources online and book readings.
3. Be Patient, but make progress, attracting and retaining visitors will not happen in a day.
4. Most importantly, focus on your expertise and choose an area YOU like, to be successful.



Copyright © 2008 Prasanna Seshadri, www.prasannatech.net, All Rights Reserved.
No part of the content or this site may be reproduced without prior written permission of the author.