Sunday, August 2, 2020

When to use notify() and notifyAll() in Java

As a programmer, you must not rely on any particular selection algorithm or treatment of priorities, at least if you are trying to write a Java program that is platform-independent. For example, because you don't know what order threads in the wait set will be chosen for resurrection by the notify command, you should use notify (as opposed to notify all) only when you are absolutely certain there will only be one thread suspended in the wait set. If there is a chance more than one thread will be suspended in the wait set at any one time, you should probably use notify all.

Otherwise, on some Java virtual machine implementations, a particular thread may be stuck in the wait set for a very long time. If a notify always selects the most recent arrival from the wait set and the wait set always contains multiple threads, some threads that have been waiting the longest may never be resurrected.

2 Ways to test Exception in JUnit : Annotation vs try-catch

Error handling is a core part of coding but most of the time it just went under the radar when it comes to unit testing. How do we write a JUnit test that verifies that an exception is thrown? With the try-catch construct, of course, except that this time, the code throwing an exception is a good thing—the expected behavior. The approach shown in the below code is a common pattern for testing exception-throwing behavior with JUnit.

Tuesday, July 14, 2020

3 Best books to prepare OCAJP 7 (1Z0- 803) Exam - Java SE 7 Certification

Even though the latest OCAJP exam is OCAJP8, the OCAJP7 still the most popular one, at least from the email I receive, I can say that more readers ask for OCAJP7 recommendations and preparation tips than OCAJP8. I have always said the three golden rules of success in the OCAJP exam are selecting a good book, writing programs, and doing mock exams like Whizlabs or Enthuware practice tests. In this article, you will find some good OCAJP7 books to deal with the first part. For those, who are new to the structure of Java SE 7 certification, it's now divided into two parts, the OCAJP and OCPJP. The OCAJP stands for Oracle Certified Associate Java Programmer and it's an associate-level exam.

Friday, June 19, 2020

Top 10 WebSites to Learn Java Online for FREE

Top 10 Websites to Learn Java Online for FREE
-------------------------------------------
Programming Java for Beginners - The Ultimate Java Tutorial from Udemy http://codecondo.com/go/learnjava/
CodingBat - The Website for practicing Java Online http://codingbat.com/

Java Basics Tutorials from Oracle http://www.oracle.com/technetwork/topics/newtojava/overview/index.html
Introduction to Programming in Java - The book http://introcs.cs.princeton.edu/java/home/

Learn Java Online - Website to learn Java Interactive http://www.learnjavaonline.org/
Learn Java The Hard way - https://learnjavathehardway.org/
Programming By doing - http://programmingbydoing.com/

Java for Complete Beginners - The FREE Video Tutorial https://www.udemy.com/java-tutorial
Java Programming Tutorials for beginner - The newboston Video tutorial https://www.youtube.com/course?list=ECFE2CE09D83EE3E28

Object-Oriented Programming with Java - The University course http://mooc.cs.helsinki.fi/programming-part1/registration-and-how-get-started

Thursday, April 23, 2020

10 Advanced Java Books for Experienced Developers


1) Effective Java
This is the first book every intermediate Java developer should read. It's not for beginners, and expert already knows most of the trick buts its absolutely critical for Java developer with a couple of years of experience. This book is your first step towards becoming an expert Java developer.

If you are working in Java for a couple of years and want to move from that advanced level, here are a couple of books to read.
-------------------------------------------

2) Java Concurrency in Practice

3) Java 9 Modularity

4) Definite guide of Java Performance by Scott Oaks

5) Head First Design Pattern

6) Test-Driven

7) Well-grounded Java Developer

8) Java NIO by

9) Java By Comparision

10) Refactoring

11) Modern Java in Action
This is the bonus book but how can you be a Java expert without knowing anything about Java 8 even after 1.5 years or its launch? So you must read this book to get a feel of new Java 8 features and motivation behind them.

Friday, April 17, 2020

Top 10 Java HashMap, Hashtable, ConcurrentHashMap Interview Question

Java HashMap, Hashtable, ConcurrentHashMap Interview Question
--------------------------------------------------------------
How to synchronize HashMap in Java?
How to sort HashMap in Java on values?
What is the difference between Hashtable and HashMap?
What is the difference between HashSet and HashMap
Difference between HashMap and ArrayList in Java?
What is the difference between HashMap and LinkedHashMap?
What is the difference between ConcurrentHashMap and HashMap?
How does get() method of HashMap works internally?
What are the different ways to iterate over each entry in HashMap?
How to loop over Map in Java?
How HashSet internally works in Java?
Difference between TreeMap and TreeSet in Java

Sunday, April 12, 2020

Top 5 Microsoft SQL Server Books for DBAs and Developers

Top 5 Microsoft SQL SERVER Books for DBAs and Developers

SQL Server Execution Plans by Grant Fritchey
Learn the basics of capturing plans, how to interrupt
them in their various forms, graphical or XML, and then
how to use the information you find. Diagnose the most
common causes of poor query performance so you
can optimize your SQL queries and improve your
indexing strategy.

SQL Server Concurrency: Locking, Blocking
and Row Versioning
by Kalen Delaney
Your application can have world-class indexes and
queries, but they won’t help you if you can’t get your data
because another application has it locked. That’s why
every DBA and developer must understand SQL Server
concurrency, and how to troubleshoot any issues.

SQL Server Transaction Log Management
by Tony Davis and Gail Shaw
Tony Davis and Gail Shaw strive to offer just the right level
of detail so that every DBA can perform all of the most
important aspects of transaction log management.

Troubleshooting SQL Server: A Guide for the
Accidental DBA
by Jonathan Kehayias and Ted Krueger
Three SQL Server MVPs provide fascinating insight into
the most common SQL Server problems, why they occur,
and how they can be diagnosed using tools such as
Performance Monitor, Dynamic Management Views, and
server-side tracing performance, so you can optimize
your SQL queries and improve your indexing strategy.


Defensive Database Programming
by Alex Kuznetsov
The goal of defensive database programming is to
help you to produce resilient T-SQL code that robustly
and gracefully handles cases of unintended use,
and is resilient to common changes to the database
environment.

That's all about top 5 good Microsoft SQL SERVER books. 

Monday, March 16, 2020

20 grep, egrep and fgrep command examples in UNIX/Linux



1) How to find all matching lines in a file in UNIX?

$ grep "good" dict.txt

2) How to exclude lines in a file, which matches patterns using the GREP command?

$ grep -v

2) How to count the number of matching lines in a file in Linux?

$ grep -c "good" dict.txt

3) How to perform case insensitive search for a keyword in a text file?

grep command support case insensitive search through grep -i option, where i stands for ignore case. This is quite useful if you are looking for strings like "error", "Error" and "ERROR" in a file. without case insensitive search you may not get the full picture if your developers are using different cases for the same keyword. Doing a case the insensitive search will give you the full idea.

4) How to display matched keywords as colored in grep output?

5) How to perform a recursive search using grep command in UNIX?

By using grep -R option, which performs a recursive search to sub-directories

6) How to make your grep command faster?

 grep is very slow on UTF-8. Use “LANG=C grep …” to increase speed.

$ echo $LANG

en_US.UTF-8

$ time grep ‘^….’ /usr/share/dict/words >/dev/null

real 2m16.795s

user 2m10.536s

sys 0m0.087s

$ export LANG=C

$ time grep ‘^….’ /usr/share/dict/words >/dev/null

real 0m0.031s

user 0m0.028s

sys 0m0.003s

6) How to display lines above and below matching lines using grep command in Linux

grep support an option called --context

You have even option to display n number of lines after the match, or just show lines above and below of matching lines using -A and -B.

7)

How to learn more about grep command in Linux box itself, use the following commands :

man grep

info grep

8) How to search for a given string in multiple files in UNIX

how to print the name of all files which contains a particular String

9) How to use regular expression with grep command in UNIX.

You can use a basic set of regular expressions with grep command as shown below. There are two ways to use regular expression with grep command either by using grep -e option or grep --regex option

10) How to search for full words in a file in Linux using GREP

grep -w

11) How to display only the name of the files, which matches a given pattern?

Here we don't want matching lines to be printed, we only want to know the files, which contains matching lines.

grep -l option is our solution

12) How to show only the matched String

13) How to show the position of the match in the line

14) How to show numbers while display grep output

15) egrep command examples

16) fgrep command examples

That's all on this list of grep command examples in UNIX/Linux. We have learned a lot of good options of grep command, in fact, I would say Every Linux user must know these grep option to take full advantage of grep command in Linux. Let us know if you got any cool grep tips.

Saturday, February 22, 2020

10 most useful command in VI Editor in Unix

1) finding form up "/" for ClOrdID , use n and shift n for navigation.
2) finding form bottom "?" looking for Execution Report 35=R
3) find and replace
Vi Replace Command

One other shortcut that might be worth mentioning is that 1,$ and % both indicate all the lines in the file. Therefore,

    :1,$s/search_string/replacement_string/g
and

    :%s/search_string/replacement_string/g


How to remove ^M from unix files using VI editor

1) ^M is DOS line break charater which shows up in unix files when uploaded from a windows file system in ascii format.
To remove this, open your file in vi editor and type
:%s/(ctrl-v)(ctrl-m)//g
and press Enter key.
Important!! - press (Ctrl-v) (Ctrl-m) combination to enter ^M character, dont use â€Å“^” and M.
2) Your substitution command may catch more ^M then necessary. Your file may contain valid ^M in the middle of a line of code for example. Use the following command instead to remove only those at the very end of lines:
:%s/(ctrl-v)(ctrl-m)$//g

3) In some flavors of vi (e.g. RedHat), vi does it for you with:
:set fileformat=unix

4) the simplest way is to use the command dos2unix

5) If you wan to use space in file name the inclose the name in between quotes

''

4) Seeing command history in Vim
5) saving data and quiting
6) Inserting data
7) deleting data
8) cut copy past, pasting above line and below line
9) opening multiple file in VI and navigating between them
10) using ctrl+Z for suspending process
11) running bash commands from VI
12) Shortcut of keyboard  also work in VI editor  , like my favorite shortcut ctrl+w worked there.
Ctrl +R is act as Redo in VI editor.

VI mein agar yadi kisi directory ke name mein / hai aur wo aapko replace karna hai to usko escape kar do with \     e.g. \/ .
2.Abhijit told me how to open another rfile in VI and then navigate between that  ^filename for opening the file and then :e #1 , :e #2 for navigating the file , we did this before by opening five files together while doing CST morning check and then using  :n for navigating to next file.

Also for opening VI in readonly mode use the option  â€Å“VI –R â€Å“ option.
In VIM we can use :help for getting help or :help fixdel for a specifc thing.
How to execute shell commands inside vi ?
!command , or select an ara using V/v and hit ! and then type the command and the selected area will lbe deleted ,fed into the command and replaced with the output of the command.

If we are doing something in VI and wanted to go shell without closing the vi then we can use command â€Å“!sh” and go to the shell finish the work, do exit and comes back to vi. ! is used to execute shell commands from shell e..g !date.
• After doing ls –l abc.txt if you want to open abc.txt you can use vi !$ (last argument)

10 most useful VI shortcut
-----------------------------
CTRL + R -- Redo
yy -- yank
dd -- delete , 5dd
p and shift+P - Paste
5. how do you get visual block in VI , you can get the visual block by pressing ctrl+V and then use yy to copy the selcted block , it can be use to copy a region from VIM into the windows clipboard without using the mousse , V(move) + y or lower case v for sections of lines or Ctrl+v for blocks.
:e for opening a new file from inside VI
VI - R for opening a file in readonly mode.




Top 10 questiosn in Thread


-------------------------------------
One of my room mate have been preparing for java interview from past few days.
1) Since start() method of Thread class eventually calls run() method ? why should we not directly call run() method ?

2) I have two  separate threads running separate task but I want them to run in a specic order ? how can I acheive this ?

3) What will happen if I call start() method on a running thread ?

4) What is the difference between sleep() and wait() method ?

5) What are the ways you can stop Thread ?

6) How do you find if a thread holds a lock or not ?

7) What is deadlock and how will you fix this ?

8) What is the difference between interuppted() and isInteruppted() ?

9) How do you acheive thread intercommunication ?

10) What is volatile modifier ?