Friday, February 26, 2016
Java interview questions
The difference between the method sleep and wait
both throws InterruptedException (how to handle InteruptedException?)
Java return and finally - what will be printed out?
public void testFinally(){
System.out.println(setOne2().toString());
}
protected StringBuilder setOne(){
StringBuilder builder=new StringBuilder();
try{
builder.append("Cool");
return builder.append("Return");
}finally{
builder.append("+1");
}
}
protected StringBuilder setOne2(){
StringBuilder builder=new StringBuilder();
try{
builder.append("Cool");
return builder.append("Return");
}finally{
builder=null;
}
}
System.out.println(setOne2().toString());
}
protected StringBuilder setOne(){
StringBuilder builder=new StringBuilder();
try{
builder.append("Cool");
return builder.append("Return");
}finally{
builder.append("+1");
}
}
protected StringBuilder setOne2(){
StringBuilder builder=new StringBuilder();
try{
builder.append("Cool");
return builder.append("Return");
}finally{
builder=null;
}
}
Wednesday, February 17, 2016
About Marriage and divorce in Ontario
Q We are already married and do not have a marriage
contract. Now we think it might be a good idea to have
one. Is it too late?
A No, it’s not too late. You can sign a marriage contract after you
are married. Remember that it must be in writing and signed by
you and your spouse in front of a witness who must also sign the
contract. If you write your contract yourselves, each of you should
have your own lawyer look it over before you sign it.
Q I am getting married in a few months. I don’t own a lot but I
do have the china set my mother got when she was married.
It is worth about $2,000. When I marry, does the china set
become my husband’s too?
A No. The china is your property. If your marriage ends, you can
keep the china. But if the china has increased in value when your
marriage ends, you and your spouse will share the increase in
value.
If you have a marriage contract, it could say that the china is your
property and that any increase in the value of the china during
your marriage will not be shared with your spouse if your
marriage ends.
If you and your spouse cannot agree on how to settle the
issues between you, you can go to court and ask a judge to decide for
you.
Separation agreements and court orders resolve family matters
when you separate but they do not legally end your marriage. The only
way to do this is to get a divorce. Only a court can give you a divorce.
It’s my wife’s fault our marriage is over. She started seeing
someone else and has decided that she wants out of the
marriage. Why should I have to share the value of my
property with her now just so this new guy gets it?
A Your spouse’s new relationship has no effect on the division of
property at the end of your marriage. The law on dividing family
property has nothing to do with why your marriage has ended.
The law sees a marriage as an equal partnership. When it is
over, the financial benefits of the partnership have to be divided
evenly and fairly. The calculations are made without looking at
who is at fault or who is to blame.
Usually a spouse's behaviour does not affect how property is divided.
contract. Now we think it might be a good idea to have
one. Is it too late?
A No, it’s not too late. You can sign a marriage contract after you
are married. Remember that it must be in writing and signed by
you and your spouse in front of a witness who must also sign the
contract. If you write your contract yourselves, each of you should
have your own lawyer look it over before you sign it.
Q I am getting married in a few months. I don’t own a lot but I
do have the china set my mother got when she was married.
It is worth about $2,000. When I marry, does the china set
become my husband’s too?
A No. The china is your property. If your marriage ends, you can
keep the china. But if the china has increased in value when your
marriage ends, you and your spouse will share the increase in
value.
If you have a marriage contract, it could say that the china is your
property and that any increase in the value of the china during
your marriage will not be shared with your spouse if your
marriage ends.
If you and your spouse cannot agree on how to settle the
issues between you, you can go to court and ask a judge to decide for
you.
Separation agreements and court orders resolve family matters
when you separate but they do not legally end your marriage. The only
way to do this is to get a divorce. Only a court can give you a divorce.
It’s my wife’s fault our marriage is over. She started seeing
someone else and has decided that she wants out of the
marriage. Why should I have to share the value of my
property with her now just so this new guy gets it?
A Your spouse’s new relationship has no effect on the division of
property at the end of your marriage. The law on dividing family
property has nothing to do with why your marriage has ended.
The law sees a marriage as an equal partnership. When it is
over, the financial benefits of the partnership have to be divided
evenly and fairly. The calculations are made without looking at
who is at fault or who is to blame.
Usually a spouse's behaviour does not affect how property is divided.
Tuesday, January 19, 2016
Solace JMS issue
Solace JMS provider implementation has an obvious bug, in SolMessageProducer.java, method
protected void sendMessage(Destination destination, Message message, int deliveryMode, int priority, long timeToLive)
the parameter priority is never used, it sets the priority to 0 directly:
solMsg.setJMSPriority(0);
It causes that the JMSPriority cannot be set to other value. It exists until the current version: sol-jms-7.1.2.226
QBrowser is an excellent Java Swing GUI client. It can browse the queue/topic with minor modification.
https://java.net/nonav/projects/mq/sources/mq5/content/mq/src/share/java/examples/applications/qbrowser/QBrowser.java?rev=38
Hermes should be more powerful, but it's too complex and you can only treat it as a black box. I cannot configure it to connect Solace based on the below document. Already set SECURITY_PRINCIPAL to username@vpn Got the error
jndi lookup failed - 401 incomplete authentication configuration
http://dev.solacesystems.com/integration-guides/hermes-jms/
The JMS API provides no mechanism for browsing a topic. Messages usually disappear from a topic as soon as they appear: if there are no message consumers to consume them, the JMS provider removes them. Although durable subscriptions allow messages to remain on a topic while the message consumer is not active, no facility exists for examining them.
protected void sendMessage(Destination destination, Message message, int deliveryMode, int priority, long timeToLive)
the parameter priority is never used, it sets the priority to 0 directly:
solMsg.setJMSPriority(0);
It causes that the JMSPriority cannot be set to other value. It exists until the current version: sol-jms-7.1.2.226
QBrowser is an excellent Java Swing GUI client. It can browse the queue/topic with minor modification.
https://java.net/nonav/projects/mq/sources/mq5/content/mq/src/share/java/examples/applications/qbrowser/QBrowser.java?rev=38
Hermes should be more powerful, but it's too complex and you can only treat it as a black box. I cannot configure it to connect Solace based on the below document. Already set SECURITY_PRINCIPAL to username@vpn Got the error
jndi lookup failed - 401 incomplete authentication configuration
http://dev.solacesystems.com/integration-guides/hermes-jms/
The JMS API provides no mechanism for browsing a topic. Messages usually disappear from a topic as soon as they appear: if there are no message consumers to consume them, the JMS provider removes them. Although durable subscriptions allow messages to remain on a topic while the message consumer is not active, no facility exists for examining them.
Wednesday, January 13, 2016
Git note
Git (DVCS)
Eclipse help on EGit is a good document to start Git
1. There is no master repository. No need to be online to perform actions.
2. Every changesets contain pointers to the previous changeset (with a unique hash value). Makes merge much easier.
3. Origin is the name of the default remote, but you can have many remotes per repository.
4. It's generally considered good practice to rebase changes prior to pushing to a remote tree to avoid these kind of fan-outs, but it's not necessary to do so.
git pull = git fetch+ git merge。pull的话,拉取远程分支并与本地分支合并,fetch只是拉远程分支,怎么合并,可以自己再做选择。
Eclipse help on EGit is a good document to start Git
1. There is no master repository. No need to be online to perform actions.
2. Every changesets contain pointers to the previous changeset (with a unique hash value). Makes merge much easier.
3. Origin is the name of the default remote, but you can have many remotes per repository.
4. It's generally considered good practice to rebase changes prior to pushing to a remote tree to avoid these kind of fan-outs, but it's not necessary to do so.
Git Complete: The definitive, step-by-step guide to Git
1. Install Git
2.
Sign up and create a repository github-demo on (init with readme)
https://github.com
3.
Origin is the name of the default remote, but you can have many remotes per repository.
1. Install Git
2.
Sign up and create a repository github-demo on (init with readme)
https://github.com
3.
Origin is the name of the default remote, but you can have many remotes per repository.
git config --list --show-origin
git version
git config --global user.name "xxx xxx"
git config --global user.email "xxxxxx@gmail.com"
You can verify this by the following two commands:
git config user.email
git config user.name
git config --global --list
git clone https://github.com/auspix/github-demo.git
git status
git add start.txt --put the file from working directory to staging area
git commit -m "Adding start txt file" --move the file from staging to local repository
git push origin master --origin refers to the github copy of our repository, master refers to our default and only branch in the repository
4. Start with a fresh project
git init fresh-project
cd fresh-project/.git
cd ..
git status
5.
Download bootstap project from http://www.initializr.com/
cd C:\git\other_repo\initializr-verekia-4.0
git init
git status
git add .
git status
git commit -m "My first commit, inline"
git pull origin master --get changes from remote repo to local to make sure we are up-to-date, should always to a pull before a push
git push origin master
git help
git help pull
git help push
6.
go to the home folder, notepad++ .gitconfig
git config --global core.editor "'C:/Apps/Notepad++/notepad++.exe' -multiInst -notabbar -nosession -noPlugin"
git commit -am "Adding more messages" --to integrate add and commit into one single command
git ls-files --show all tracked filese
git add . --add all files under current folder recursivly
git reset HEAD level1-file.txt --move back the file from staging to working area (opposite to git add level1-file.txt)
git checkout -- level1-file.txt --discard changes in working directory and return to last commit
7.
git mv start.txt start2.txt --rename the file name
git add -A --add all files include the renaming and deletion, if you rename from OS, then use this command
git rm --to delete the git indexed file
git log --to show the commit history
git log -- level3-fileNEW.txt --show the specified file log
8.
git diff --show the difference between working area and staging area
git diff HEAD --show the difference between working area and local repo
git diff --staged HEAD --show the difference between staging area and the local repo
git diff -- TheFile --only compare the specified file
git diff master origin/masetr --compare local repo with remote repo (origin/maseter)
9.
git branch mynewbranch --create new branch
git checkout mynewbranch --switch to the new branch
10.
notepad++ .gitignore
fast forward merge is only possible if there's no commit on the target branch just like there's never new branch
git merge copyright-branch --no-ff --disable fast forward merge
git checkout master
git merge simple-changes -m "Merging from branch simple-changes"
11.
git stash --record the current state of the working directory and the index, but go back to a clean working directory.
git stash apply --Like pop, but do not remove the state from the stash list.
git stash list --show the stash
git stash drop --drop the stash
12.
git tag myTag --just a marker/label on current command (for milestone ...)
git tag --list
git tag --delete myTag
git version
git config --global user.name "xxx xxx"
git config --global user.email "xxxxxx@gmail.com"
You can verify this by the following two commands:
git config user.email
git config user.name
git config --global --list
git clone https://github.com/auspix/github-demo.git
git status
git add start.txt --put the file from working directory to staging area
git commit -m "Adding start txt file" --move the file from staging to local repository
git push origin master --origin refers to the github copy of our repository, master refers to our default and only branch in the repository
4. Start with a fresh project
git init fresh-project
cd fresh-project/.git
cd ..
git status
5.
Download bootstap project from http://www.initializr.com/
cd C:\git\other_repo\initializr-verekia-4.0
git init
git status
git add .
git status
git commit -m "My first commit, inline"
git pull origin master --get changes from remote repo to local to make sure we are up-to-date, should always to a pull before a push
git push origin master
git help
git help pull
git help push
6.
go to the home folder, notepad++ .gitconfig
git config --global core.editor "'C:/Apps/Notepad++/notepad++.exe' -multiInst -notabbar -nosession -noPlugin"
git commit -am "Adding more messages" --to integrate add and commit into one single command
git ls-files --show all tracked filese
git add . --add all files under current folder recursivly
git reset HEAD level1-file.txt --move back the file from staging to working area (opposite to git add level1-file.txt)
git checkout -- level1-file.txt --discard changes in working directory and return to last commit
7.
git mv start.txt start2.txt --rename the file name
git add -A --add all files include the renaming and deletion, if you rename from OS, then use this command
git rm --to delete the git indexed file
git log --to show the commit history
git log -- level3-fileNEW.txt --show the specified file log
8.
git diff --show the difference between working area and staging area
git diff HEAD --show the difference between working area and local repo
git diff --staged HEAD --show the difference between staging area and the local repo
git diff -- TheFile --only compare the specified file
git diff master origin/masetr --compare local repo with remote repo (origin/maseter)
9.
git branch mynewbranch --create new branch
git checkout mynewbranch --switch to the new branch
10.
notepad++ .gitignore
fast forward merge is only possible if there's no commit on the target branch just like there's never new branch
git merge copyright-branch --no-ff --disable fast forward merge
git checkout master
git merge simple-changes -m "Merging from branch simple-changes"
11.
git stash --record the current state of the working directory and the index, but go back to a clean working directory.
git stash apply --Like pop, but do not remove the state from the stash list.
git stash list --show the stash
git stash drop --drop the stash
12.
git tag myTag --just a marker/label on current command (for milestone ...)
git tag --list
git tag --delete myTag
git push -u origin myNewBranch
# Pushes your newly created local branch "myNewBranch"
# to the remote "origin".
To list all the remotes, run git remote
git pull = git fetch+ git merge。pull的话,拉取远程分支并与本地分支合并,fetch只是拉远程分支,怎么合并,可以自己再做选择。
Friday, November 20, 2015
Use Excel to create the indexed performance graph
Use Excel to create the indexed performance graph
1. Generate the original data like the below:
Date Amount Index
20150107 100559.08 3373.95
20150108 102548.36 3293.46
20150109 102860.37 3285.41
20150112 103072.33 3229.32
2. Use format to convert the data to indexed data
The formula should be like =C2/$C$2*100 wrap with $ to make it fix
Date Amount Index
1/7/2015 100 1/0/1900
1/8/2015 101.9782202 97.61436891
1/9/2015 102.2884955 97.37577617
1/12/2015 102.499277 95.71333304
3. Use Data -> Text to Columns to convert the text yyyymmdd to date YMD
4. Select all transformed data (include the header), and insert line (first one is good if there are a lot of data, all may select grapth with markders)
References:
http://academics.smcvt.edu/cbauer-ramazani/AEP/BU113/finance/create_index_graph.htm
http://www.extendoffice.com/documents/excel/2777-excel-convert-yyyymmdd-to-date.html
1. Generate the original data like the below:
Date Amount Index
20150107 100559.08 3373.95
20150108 102548.36 3293.46
20150109 102860.37 3285.41
20150112 103072.33 3229.32
2. Use format to convert the data to indexed data
The formula should be like =C2/$C$2*100 wrap with $ to make it fix
Date Amount Index
1/7/2015 100 1/0/1900
1/8/2015 101.9782202 97.61436891
1/9/2015 102.2884955 97.37577617
1/12/2015 102.499277 95.71333304
3. Use Data -> Text to Columns to convert the text yyyymmdd to date YMD
4. Select all transformed data (include the header), and insert line (first one is good if there are a lot of data, all may select grapth with markders)
References:
http://academics.smcvt.edu/cbauer-ramazani/AEP/BU113/finance/create_index_graph.htm
http://www.extendoffice.com/documents/excel/2777-excel-convert-yyyymmdd-to-date.html
Thursday, November 19, 2015
VC++ scheduler/timer and other sources
http://download.csdn.net/detail/Jeffrey_Ming/1195343
http://blog.csdn.net/clever101/article/details/47756047
http://download.csdn.net/detail/hero20025627hxh/1663637
http://download.csdn.net/detail/zhouzhenyang1990/3075088
http://download.csdn.net/detail/s672038161/3206737
http://download.csdn.net/detail/houhuijuan/3446698
http://download.csdn.net/detail/notsunny/8740609
http://download.csdn.net/detail/sunanguo/880743
http://download.csdn.net/detail/fish_1001/8604645
#include <ctime>
#include <iostream>
#include <windows.h>
using namespace std;
int main() {
while(true){
time_t t = time(0); // get time now
struct tm * now = localtime( & t );
if(now->tm_min>39){//begin
cout << "current min " << now->tm_min << ", sec = " << now->tm_sec << endl;
}
if(now->tm_min>40){//end
cout << "will break, current min " << now->tm_min << ", sec = " << now->tm_sec << endl;
break;
}
Sleep(3000);
}
}
http://blog.csdn.net/clever101/article/details/47756047
http://download.csdn.net/detail/hero20025627hxh/1663637
http://download.csdn.net/detail/zhouzhenyang1990/3075088
http://download.csdn.net/detail/s672038161/3206737
http://download.csdn.net/detail/houhuijuan/3446698
http://download.csdn.net/detail/notsunny/8740609
http://download.csdn.net/detail/sunanguo/880743
http://download.csdn.net/detail/fish_1001/8604645
#include <ctime>
#include <iostream>
#include <windows.h>
using namespace std;
int main() {
while(true){
time_t t = time(0); // get time now
struct tm * now = localtime( & t );
if(now->tm_min>39){//begin
cout << "current min " << now->tm_min << ", sec = " << now->tm_sec << endl;
}
if(now->tm_min>40){//end
cout << "will break, current min " << now->tm_min << ", sec = " << now->tm_sec << endl;
break;
}
Sleep(3000);
}
}
Subscribe to:
Posts (Atom)