Monday, 10 November 2014
Newyork times used Hadoop to archive data..
Newyork times used Hadoop to archive data..
The technology is moving fast & efficient.
The New York Times using Hadoop to convert about 4 million entities to PDF
in just under 36 hours
http://timesmachine.nytimes.com/timesmachine/1912/04/16/p/1
Wednesday, 24 September 2014
India scripts history, becomes the first country to send Mars Orbiter in first attempt
Cost - $71 million which is $29 million less than the cost of hollywood movie GRAVITY.
Is't it amazing?
Read more in
http://indianexpress.com/article/india/india-others/india-succeeds-putting-spacecraft-in-martian-orbit/
Wednesday, 3 September 2014
Java Program for calculating business days considering public holidays
This is in continuation to my previous post...
This is a Java Program for calculating business days considering public holidays
public long getNumberOfBusinessDays(Date start, Date end)
{
if (start == null || end == null)
return 0;
long daysWithoutSunday = 0;
int w1 = 0;
int w2 = 0;
long actualNumberOfBusinessDays = 0;
Calendar c1 = GregorianCalendar.getInstance();
c1.setTime(start);
w1 = c1.get(Calendar.DAY_OF_WEEK);
c1.add(Calendar.DAY_OF_WEEK, -w1 + 1);
Calendar c2 = GregorianCalendar.getInstance();
c2.setTime(end);
w2 = c2.get(Calendar.DAY_OF_WEEK);
c2.add(Calendar.DAY_OF_WEEK, -w2 + 1);
//end Saturday to start Saturday
long days = (c2.getTimeInMillis() - c1.getTimeInMillis())/(1000*60*60*24);
daysWithoutSunday = days-(days*2/7);
if (w1 == Calendar.SUNDAY)
w1 = Calendar.MONDAY;
if (w2 == Calendar.SUNDAY)
w2 = Calendar.MONDAY;
/*
* Check if the there are dates which are falling in public holidays?
* Currently handling only Christmas & New Year days.
*/
long numberOfBusinessDaysWithoutSundayAndSaturday = daysWithoutSunday - w1 + w2;
actualNumberOfBusinessDays = numberOfBusinessDaysWithoutSundayAndSaturday;
while (numberOfBusinessDaysWithoutSundayAndSaturday > 0 && start.before(end))
{
if (isPublicHoliday(start))
actualNumberOfBusinessDays -= 1;
start = addDay(start);
numberOfBusinessDaysWithoutSundayAndSaturday -= 1;
}
return actualNumberOfBusinessDays;
}
public static boolean isPublicHoliday(Date date)
{
Calendar cal = Calendar.getInstance();
cal.setTime(date);
int w1 = cal.get(Calendar.DAY_OF_WEEK);
// check if New Year's Day & not falls on a Saturday or Sunday because weekends are already taken care
if (cal.get(Calendar.MONTH) == Calendar.JANUARY && cal.get(Calendar.DAY_OF_MONTH) == 1 && w1 != Calendar.SUNDAY && w1 != Calendar.SATURDAY)
return true;
// check if Christmas & not falls on a Saturday or Sunday because weekends are already taken care
if (cal.get(Calendar.MONTH) == Calendar.DECEMBER && cal.get(Calendar.DAY_OF_MONTH) == 25 && w1 != Calendar.SUNDAY && w1 != Calendar.SATURDAY)
return true;
return false;
}
private static Date addDay(Date date)
{
Calendar cal = Calendar.getInstance();
cal.setTime (date);
cal.add (Calendar.DATE, 1);
return cal.getTime();
}
This is a Java Program for calculating business days considering public holidays
public long getNumberOfBusinessDays(Date start, Date end)
{
if (start == null || end == null)
return 0;
long daysWithoutSunday = 0;
int w1 = 0;
int w2 = 0;
long actualNumberOfBusinessDays = 0;
Calendar c1 = GregorianCalendar.getInstance();
c1.setTime(start);
w1 = c1.get(Calendar.DAY_OF_WEEK);
c1.add(Calendar.DAY_OF_WEEK, -w1 + 1);
Calendar c2 = GregorianCalendar.getInstance();
c2.setTime(end);
w2 = c2.get(Calendar.DAY_OF_WEEK);
c2.add(Calendar.DAY_OF_WEEK, -w2 + 1);
//end Saturday to start Saturday
long days = (c2.getTimeInMillis() - c1.getTimeInMillis())/(1000*60*60*24);
daysWithoutSunday = days-(days*2/7);
if (w1 == Calendar.SUNDAY)
w1 = Calendar.MONDAY;
if (w2 == Calendar.SUNDAY)
w2 = Calendar.MONDAY;
/*
* Check if the there are dates which are falling in public holidays?
* Currently handling only Christmas & New Year days.
*/
long numberOfBusinessDaysWithoutSundayAndSaturday = daysWithoutSunday - w1 + w2;
actualNumberOfBusinessDays = numberOfBusinessDaysWithoutSundayAndSaturday;
while (numberOfBusinessDaysWithoutSundayAndSaturday > 0 && start.before(end))
{
if (isPublicHoliday(start))
actualNumberOfBusinessDays -= 1;
start = addDay(start);
numberOfBusinessDaysWithoutSundayAndSaturday -= 1;
}
return actualNumberOfBusinessDays;
}
public static boolean isPublicHoliday(Date date)
{
Calendar cal = Calendar.getInstance();
cal.setTime(date);
int w1 = cal.get(Calendar.DAY_OF_WEEK);
// check if New Year's Day & not falls on a Saturday or Sunday because weekends are already taken care
if (cal.get(Calendar.MONTH) == Calendar.JANUARY && cal.get(Calendar.DAY_OF_MONTH) == 1 && w1 != Calendar.SUNDAY && w1 != Calendar.SATURDAY)
return true;
// check if Christmas & not falls on a Saturday or Sunday because weekends are already taken care
if (cal.get(Calendar.MONTH) == Calendar.DECEMBER && cal.get(Calendar.DAY_OF_MONTH) == 25 && w1 != Calendar.SUNDAY && w1 != Calendar.SATURDAY)
return true;
return false;
}
private static Date addDay(Date date)
{
Calendar cal = Calendar.getInstance();
cal.setTime (date);
cal.add (Calendar.DATE, 1);
return cal.getTime();
}
Java program to calculate the number of business days between two dates.
This is a Java program to calculate the number of business days between two dates..
This program will exclude only Saturdays & Sundays and not the public holidays.
This program will exclude only Saturdays & Sundays and not the public holidays.
public long getNumberOfBusinessDays(Date start, Date end){if (start == null || end == null)return 0;long daysWithoutSunday = 0;int w1 = 0;int w2 = 0;Calendar c1 = GregorianCalendar.getInstance();c1.setTime(start);w1 = c1.get(Calendar.DAY_OF_WEEK);c1.add(Calendar.DAY_OF_WEEK, -w1 + 1);Calendar c2 = GregorianCalendar.getInstance();c2.setTime(end);w2 = c2.get(Calendar.DAY_OF_WEEK);c2.add(Calendar.DAY_OF_WEEK, -w2 + 1);//end Saturday to start Saturdaylong days = (c2.getTimeInMillis() - c1.getTimeInMillis())/(1000*60*60*24);daysWithoutSunday = days-(days*2/7);if (w1 == Calendar.SUNDAY)w1 = Calendar.MONDAY;if (w2 == Calendar.SUNDAY)w2 = Calendar.MONDAY;return daysWithoutSunday-w1+w2;}
Monday, 21 July 2014
Good for Java Interview Preparations
I found this in internet which I think very useful. This is not a promotional stuff, but for my reference.
http://java-success.blogspot.co.uk/2014/06/top-50-core-java-interview-questions.html
http://java-success.blogspot.co.uk/2014/06/top-50-core-java-interview-questions.html
Wednesday, 9 July 2014
how to clean up svn when crashed
There are times when we see the blow error in your svn or cygwin tool
svn: Working copy ‘/myrepo/repodirectory’ locked
svn: run ’svn cleanup’ to remove locks (type ’svn help cleanup’ for details)
if you run svn status at this stage you will see all the files & folders will have a "L" , meaning, it is locked.
The easiest way to resolve this issue is to provide the below command in the command prompt
(assuming that the command is executed from the root of the workspace
svn cleanup .
The above command will basically unlock all the folders/subfolder and files recursively.
svn: Working copy ‘/myrepo/repodirectory’ locked
svn: run ’svn cleanup’ to remove locks (type ’svn help cleanup’ for details)
if you run svn status at this stage you will see all the files & folders will have a "L" , meaning, it is locked.
The easiest way to resolve this issue is to provide the below command in the command prompt
(assuming that the command is executed from the root of the workspace
svn cleanup .
The above command will basically unlock all the folders/subfolder and files recursively.
Thursday, 29 May 2014
Update specific lines in a file using Java 1.7 >
import java.io.BufferedReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
import java.nio.charset.Charset;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.List;
import java.util.StringTokenizer;
/**
* This class creates the correction file from the original file.
* This class performs the following tasks.
*
* 1) Convert the original files to correction files. The input for the class are the original files, which is
* test_file.txt
* 2) Creates the correction files namely, test_file_correction.txt
* 3) The difference between the original file and the correction file are as follows
* a) if the source reference is XYZ, then it would be replaced with XYZ/AMENDED and
* respective name space would be replaced with original name appended with "_correction"
* b) Similar to above, O_XYZ will be changed to O_XYZ/AMENDED
*
* @author ppillai
*
*/
public class SourceGenerator {
public static void main(String[] args) {
List lines = null;
String sourceFileName1 = "dev\\xyz\\test_file.txt";
String targetFileName1 = "dev\\xyz\\test_filecorrection.txt";
String targetFileName = null;
ArrayList listOfFiles = new ArrayList();
listOfFiles.add(sourceFileName1);
listOfFiles.add(sourceFileName2);
int count = 0;
for (String sourceFileName : listOfFiles)
{
lines = readFile(sourceFileName);
targetFileName = targetFileName1;
try (PrintWriter pw = new PrintWriter(new FileWriter(targetFileName)))
{
for(String line: lines)
{
line = processLines(line);
if (line != null)
pw.println(line);
}
pw.close();
count+=1;
}
catch (IOException ioe) {
ioe.printStackTrace();
}
}
}
private static List readFile(String FileName) {
Path FilePath = Paths.get(FileName);
try (BufferedReader fileReader = Files.newBufferedReader(FilePath, Charset.defaultCharset())) {
List lines = new ArrayList<>();
String line = null;
while ((line = fileReader.readLine()) != null )
lines.add(line);
return lines;
}
catch (IOException ioe) {
ioe.printStackTrace();
}
return null;
}
private static String processLines(String line)
{
if (!line.contains("_notification"))
{
if (line.contains("\"XYZ\""))
{
line = line.replaceAll("\"XYZ\"",XYZ_NEW);
line = line.replaceAll("Tag:XYZ","Tag:"+XYZ_PENDING);
}
if (line.contains("\"O_XYZ\""))
{
line = line.replaceAll("\"O_XYZ"","O_XYZ/AMENDED");
line = line.replaceAll("Tag:O_XYZ","Tag:"+"O_XYZ/AMENDED");
}
}
return line;
}
}
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
import java.nio.charset.Charset;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.List;
import java.util.StringTokenizer;
/**
* This class creates the correction file from the original file.
* This class performs the following tasks.
*
* 1) Convert the original files to correction files. The input for the class are the original files, which is
* test_file.txt
* 2) Creates the correction files namely, test_file_correction.txt
* 3) The difference between the original file and the correction file are as follows
* a) if the source reference is XYZ, then it would be replaced with XYZ/AMENDED and
* respective name space would be replaced with original name appended with "_correction"
* b) Similar to above, O_XYZ will be changed to O_XYZ/AMENDED
*
* @author ppillai
*
*/
public class SourceGenerator {
public static void main(String[] args) {
List
String sourceFileName1 = "dev\\xyz\\test_file.txt";
String targetFileName1 = "dev\\xyz\\test_filecorrection.txt";
String targetFileName = null;
ArrayList
listOfFiles.add(sourceFileName1);
listOfFiles.add(sourceFileName2);
int count = 0;
for (String sourceFileName : listOfFiles)
{
lines = readFile(sourceFileName);
targetFileName = targetFileName1;
try (PrintWriter pw = new PrintWriter(new FileWriter(targetFileName)))
{
for(String line: lines)
{
line = processLines(line);
if (line != null)
pw.println(line);
}
pw.close();
count+=1;
}
catch (IOException ioe) {
ioe.printStackTrace();
}
}
}
private static List
Path FilePath = Paths.get(FileName);
try (BufferedReader fileReader = Files.newBufferedReader(FilePath, Charset.defaultCharset())) {
List
String line = null;
while ((line = fileReader.readLine()) != null )
lines.add(line);
return lines;
}
catch (IOException ioe) {
ioe.printStackTrace();
}
return null;
}
private static String processLines(String line)
{
if (!line.contains("_notification"))
{
if (line.contains("\"XYZ\""))
{
line = line.replaceAll("\"XYZ\"",XYZ_NEW);
line = line.replaceAll("Tag:XYZ","Tag:"+XYZ_PENDING);
}
if (line.contains("\"O_XYZ\""))
{
line = line.replaceAll("\"O_XYZ"","O_XYZ/AMENDED");
line = line.replaceAll("Tag:O_XYZ","Tag:"+"O_XYZ/AMENDED");
}
}
return line;
}
}
Monday, 19 May 2014
Check your math skills....
1) Can you arrive at a total of 37 by using five fives? Any maths operator is allowed and you can group the fives as you like (eg 555 5 5). There is more than one solution
2) Replace the question marks with any of + - * / to make the equation below correct:
(6?2) ? (3?4) ?
(6?2) = 25
3) Each of the letters S – Z has one of the eight values
listed. No two have the same value. Match each value with its corresponding
letter.
Values: 2, 6, 10, 12, 16,
18, 20, 26
Z + S = X
V – X = Y
U + Z = T
W – V = Z
T + U = W
Y + U = S
4) The
last of four sisters got married
yesterday. There has been a wedding a
year for the last four years, all on the 16th April. Dee married yesterday, Carol last year, Babs
the year before and Abbi the year before that.
Abbi is older than Dee. The
strange thing is that each bride was married when her age was exactly the same
as the sum of the digits of the ages of her three sisters. All daughters were married before their 30th
birthday. How old is each daughter?
5) Jake and three classmates were comparing the number of medals
they’d won at the swimming gala. “I’ve
got one more than you”, said Jake. “And
I have two more than you”, said one pupil to another. “I’ve got three more than you” said one to
another. “I’ve got four more than you”,
“And I’ve got five more than you”, “I’ve got six more than you”, as their
voices rose to a clamour, but we don’t know who was talking to whom. They managed to win 27 medals between them,
how many did Jake win?
6) Fifty minutes ago, it was four times as many minutes past 9pm as
the number of minutes it currently is until midnight. What is the current time?
7) 1.
Brother and sister Albert and Florence are now adults, with
their ages totaling 64. When asked how
old they are, Albert replies: “I am five times as old as Florence was, when I
was as old as she is now”. How old are they?
8) What is the smallest combination of notes and coins you would need in order to make
every combination between 1p and £10?
9) I need to make as many Union Jacks as possible for a Eurovision
party. They are to measure 2 feet by 3
feet. The material costs £1.50 per foot
and comes in a roll five feet wide, which can be bought in any length (down to
the inch). I have a total of £12.60 to
spend on cloth – how many whole flags can I make?
10 ) A salmon’s tail weighs 8 kilos. Its head weighs the same as the tail plus one
half of the body, and the body weighs as much as the head and tail
combined. How much does the salmon weigh
in total?
11) Using only plus and minus, create an equation by inserting the fewest of them possible into 987654321
= 100. Eg 98 + 7 – 6 + 5 – 4 + 3 - 2 –
1 = 100. The numbers must stay in the
same order.
12) .
In my garden is a web with 13 spiders and flies in it. There is a total of 94 legs in the web. How many spiders are there?
13) If I drive to my friend’s at an average speed of 30mph, then
return at an average speed of 20mph, what is my average speed for the round
trip?
14)After 10 days in the USA I had a pocketful of 55 coins, which
totalled exactly 10 dollars. There are
more nickels (5 cents) than one cent coins, more dimes (10 cents) than nickels,
and more quarters than dimes. How many
of each coin do I have?
15) If 3 schoolboys eat 3 boxes of cornflakes in 3 weeks and 4
schoolgirls eat 4 packets of cornflakes in 4 weeks and 6 teachers eat 6 paclets
of cornflakes in 6 weeks then how many cornflakes will feed 12 schoolboys, 12
schoolgirls and 12 teachers for 12 weeks?
Answers:
1) (5+5)/5)power 5 +5
2)
More than one answer possible:
(6 - 2) * (3 + 4) - (6 / 2) = 25
(6*2) - (3-4 )+
(6*2)= 25
3) S=12; T=16; U=10; V=20; W=26; X=18; Y=2; Z=6
4) Abbi is 27, Babs is 28, Carol is 20, and Dee is 21, 21 = 2+7+2+8+2+0.
A year ago, they were 26, 27, 19, and 20, 19 = 2+6+2+7+2+0.
Two years ago, they were 25, 26, 18, and 19, 26 = 2+5+1+8+1+9.
Three years ago, they were 24, 25, 17, and 18, 24 = 2+5+1+7+1+8.
5) (The medals won were 4, 5, 8 and 10)
6)11:34pm
7) Albert is 40 and Florence is 24
8) 1p, 2p, 2p, 5p, 10p, 10p, 20p, 50p, £1, £1, £2, £5 or 1p, 2p, 2p, 5p, 10p, 20p, 20p, 50p, £1, £2, £2, £5
9) Six. You can buy 8.4 feet of material with the money, so there will be a rectangle of 8.4 x 5. Cut this into two rectangles, 8.4 x2 and 8.4 x 3. Two flags and four flags respectively can be made from the two rectangles.
10) 64 kg
11) 98 – 76 + 54 + 3 +21 = 100
12) 8
13) 24 mph
14) 35 quarters $8.75
9 dimes .90
6 nickels .30
5 pennies .05
Total $10.00
15) 108 packs
Thursday, 15 May 2014
Tier 1 (General) Extension Changes
For those who are applying for Tier (Gen -Extn), please note that there are changes in the fees and maintenance fund.
There has been changes in the official website as well.
The new official website is
https://www.gov.uk/tier-1-general
There has been changes in the official website as well.
The new official website is
https://www.gov.uk/tier-1-general
Tuesday, 13 May 2014
Java Interview Questions
Q) Integer a =10; Integer b =10; Integer c =a+b; How many Objects will create here ?
Ans : Zero objects would be created.
When the Integer class is loaded, values between -128 to 127 are cached and thus the values would be fetched from cache unless you explicitly declare Integer a =new Integer(10);
Q) Where does String literal pool gets created in?
Ans) PermGen before Java 7. After Java 7 it is moved to heap.
Q) Where does String literal pool gets created in?
Ans) PermGen before Java 7. After Java 7 it is moved to heap.
Thursday, 1 May 2014
How to Recall a message from Outlook
You will get many links when you look for "recall message from outlook". I'm writing below the simple steps.
1. In outlook go to Send Items
2. Select the email which you intend to recall
3. From the "Actions" option, select the Recall message option.
Done.
1. In outlook go to Send Items
2. Select the email which you intend to recall
3. From the "Actions" option, select the Recall message option.
Done.
Subscribe to:
Posts (Atom)