Showing posts with label Programming. Show all posts
Showing posts with label Programming. Show all posts

Jul 31, 2015

Good tool Java Decompiler - View source codes from jar or .class file

One problem of using SVN is that you might meet conflicts and end up losing your own codes. I met the problem once: I did an update, and there are conflicts. I tried to revert the update but found out that the revert is reverting my local change but keep the update! Now I lost my local development work...

Luckily I have a compiled jar file which I build last time, but they are all .class files. How to view the original files?

Java Decompiler comes to the resue!
http://jd.benow.ca/


Use this tool to open a jar file or .class file, you will see all the contents:
It's structured and clear! Thanks to the author!


If you think this article is useful, please click the ads on this page to help. Thank you very much.

Apr 23, 2015

Apache Commons CLI not working? No, it's a junk character problem

I am using Apache command line interface to accept run time parameters.



While in my code, I am using -t to specify run time topology name.
But to my surprise, it didn't work. I took 2 hours to debug this problem and finally by chance I compare the result and find our that

It's complaining about the - character. What is wrong with it?


I used Notepad++ and there is good plugin called HexEditor and it gives our the answer



This is causing strange problem.

You may ask why. This is because when someone sent me the command from Outlook, it was already junked. 
OK. the lesson and learn here is to be careful of the characters you pasted from Outlook, especially when it's in Chinese environment. We may try to type the command again to avoid problems.

If you find this article is useful, please click the ads on this page to help. Thank you very much.

Jan 6, 2015

[Solved]HBase Java program Joda time problem - NoSuchMethodError: org.joda.time.DateTime.now()

I am writing a HBase program and use Joda time as my time type. I have a simple api call

System.out.println(DateTime.now())  which DateTime was imported as

In Eclipse the code is compiled successfully, but when I tried to execute it it poped up a strange error:  NoSuchMethodError: org.joda.time.DateTime.now()

What? DateTime.now() is a well-known API and I check the source code, it's available since Joda jar 2.0, in my maven dependency it clearly shows that my joda jar library is 2.0. Then I even manually added a latest version which is version 2.6 and clearly see that the 2.6 version is picked up.

But, the problem still exists. What's wrong with Joda?
Then I see that in my project, I also have storm-core api, which also has a joda-time dependency, so I exclude it. Now I see that
in Eclipse the DateTime also has library, and it points to jruby-complete-1.6.8.jar, then it tells me whether the problem is.


Root cause:
1. my HBase program imported external jars, one of them is jruby-complete-1.6.8.jar, which internally has a joda-time reference, but it's a very low version.

2. somehow this version got picked up and makes DateTime.now() has a problem as it's only available after 2.0

Solution
1. remove the external library jruby-complete-1.6.8.jar in Java Build Path (as the screenshot above, choose the jruby-complete-1.6.8.jar and click Remove)
2. Use maven to add jruby-complete-1.6.8 dependency


org.jruby
jruby-complete
1.6.8
        provided



3. Add Joda-time dependency and make sure it comes first as the screenshot below shows

joda-time
joda-time
2.6



DateTime.now() is a wonderful world!

If you find this blog is useful, please kindly click the ads on this page to help. Thank you very much.

Aug 21, 2013

[Solved] Jetty HTTP 500 "A full JDK (not just JRE) is required"

Today I am deploying Jetty in my machine, my machine configuration is:
OS: windows 7, JDK: jdk1.7.0_25, Jetty: Jetty9
And I have configured JAVA_HOME in system environment and also add %JAVA_HOME%\bin in Path

I can start Jetty:
Java -jar start.jar

And I can see in console it successfully started.
But when I try to access the web application via browser, I met a strange problem:

ERROR:
PWC6345: There is an error in invoking javac.  A full JDK (not just JRE) is required



SOLUTION:

1. Edit jetty.xml which is under the jetty installation folder \etc folder, for example C:\Program Files\jetty-distribution-9.0.5.v20130815\etc

2. Add a section

    org.apache.jasper.compiler.disablejsr199
    true
  


within section





It's a happy world now!
The solution was referring Jetty document: http://wiki.eclipse.org/Jetty/Howto/Configure_JSP

If you think this article is useful, please click the ads on this page to help. Thank you very much.

Aug 7, 2013

[Solved] Chrome Debugger Cannot Modify Local Variable

I found it's strange that Chrome Debugger doesn't allow modify modify local variables. For example:

you have a variable: instanceType, which original value is "VERTICA"
in the console, you write:
instanceType="MAPR"
But when you type instanceType again, it still shows
"VERTICA"


I did some search but found it's a know problem, and yet not be fixed in latest Chrome build. Luckily I found an easy solution, which is to use Canary Chrome:
 https://www.google.com/intl/en/chrome/browser/canary.html


With the debugger tool of Chrome Canary,



Aha, what a happy world!

If you think this article is useful, please click the ads on this page to help. Thank you very much.

Jul 11, 2013

Use CURL to test POST RESTful API

I was working one specific task about RESTful API and it took me sometime, and after finish it I think it's worth sharing.

The task is: I need to implement a POST RESTful API, which accepts multiple parameters. And I will make it be able to call by a C++ or shell script.

The API looks like this, and in JAVA codes:


@POST
@Path("updatecache")
public void postCache(@QueryParam("instanceID") String instanceID, @QueryParam("startTime") String startTime, @QueryParam("endTime") String endTime) {
        /*The implementation details are hidden herer*/
}

To test it in POSTMAN

To test it in CURL, it took me really a long time, and

curl -H "user:abc" -H "password:abc" -X POST "http://localhost:8080/dsm/resources/heatmap/updatecache?instanceID=96&startTime=2013-06-29%2000:00:00&endTime=2013-07-02%2010:00:00"

Note: the URL should be double quoted. Because Typing & in the command line means run the preceding command in the background , because of this anything after the & is being treated as a new command.

If you think this article is useful, please click the ads on this page to help. Thank you very much.

Jun 27, 2013

Study Notes on Java Code Conventions September 12, 1997

When I was finding some resources, I happened to find an interesting document:

Java
Code Conventions

September 12, 1997 

I was very curious about what rules our respected programmer predecessors made on how to code Java, and these rules are still the rules today. The document can be found here: http://www.oracle.com/technetwork/java/codeconventions-150003.pdf, and below is the notes that I find useful for myself, and maybe useful for you.

1. Initialization
Try to initialize local variables where they’re declared. The only reason not to initialize a

variable where it’s declared is if the initial value depends on some computation occurring first.

2. Number Per Line
One declaration per line is recommended since it encourages commenting. In other words,
    int level; // indentation level
   int size; // size of table
is preferred over
    int level, size;

3. Return Statements
A return statement with a value should not use parentheses unless they make the return value
more obvious in some way. Example:
    return;
   return myDisk.size();

   return (size ? size : defaultSize);

4. if Statements 
Always use braces {}, and avoid the following error-prone form:
    if (condition) //AVOID! THIS OMITS THE BRACES {}!
        statement;

5. switch Statement
A switch statement should have the following form:
    switch (condition) {
        case ABC:
            statements;
            /* falls through */
        case DEF:
            statements;
            break;
        case XYZ:
            statements;
            break;
        default:
            statements;
            break;
    }
Every time a case falls through (doesn’t include a break statement), add a comment where the
breakstatement would normally be. This is shown in the preceding code example with the
/* falls through */ comment.
Every switch statement should include a default case. The break in the default case is
redundant, but it prevents a fall-through error if later another case is added.

6. Casts should be followed by a blank
    myMethod((byte) aNum, (Object) x);
   myFunc((int) (cp + 5), ((int) (i + 3))+ 1);

7. Variable Assignments
Avoid assigning several variables to the same value in a single statement. It is hard to read.
Example:
    fooBar.fChar = barFoo.lchar = 'c'; // AVOID!

8.Special Comments
Use XXX in a comment to flag something that is bogus but works. Use FIXME to flag something that is bogus and broken.


Feb 1, 2013

How to download source code from code.google.com

Google host is a good place to manage application source codes and do cooperation work. But it took me quite a while to figure out how to download source codes from there.

For example, when I went to this website to download a plugin to run jetty
http://code.google.com/p/run-jetty-run/source/checkout

It clearly says that user can use a svn command to download the codes:


But in my command line window, it failed like this:

Luckily I found a tool to do this:
http://downloadsvn.codeplex.com/

This is the tool and it works perfectly well.

If you find this article useful, please kindly click the ads on this page to help. Thank you.

Dec 4, 2012

Feelings and Experiences of CCD-333 Exam - Cloudera Certified Developer for Apache Hadoop (CCDH)

In October this year, I took a Cloudera Certified Developer for Apache Hadoop exam, which number is CCD-333. I successfully passed the exam, and looking back upon, all the efforts paid had value. This is a new exam and there is few materials in the internet talking about it, now I want to write something to share my feelings and experiences, which may help people who are preparing for the exam.


Part 1: Exam Preparation - Learning
1. Hadoop The Definite Guide 3rd


This is the book you must read before the exam, which explain very well and in details of Hadoop. I took a three days training by Cloudera certified trainer, but that class is an overview level training and is not very detailed. After the exam, I found the many questions examed are in the Definite Guide book rather than the training.
And very important, it's better that you read very carefully of Chapter 2 to 8 of this book, and maybe add chapter 9 and 10. I read them twice. But for chapter 11 to 16 which talks about the ecosystem of Hadoop (HBase, Hive, Pig etc.) , you don't need to read them if only for preparing the exam.

Part 2: The Exam CCD-333
The CCD-333 exam is 90 minutes with 60 questions, and the requirement is to score 67% or above. The exam tests many areas, the section scores below listing them precisely:

I feel that it exams a lot in the Input and Outpout of MapReduce, you need to understand the flow and details of MapReduce, and in the exam itself, I feel that time is sufficient to finish the exam.

Part 3: The certification

I wish this article is helpful for those who are preparing for this exam. All the best!

If you found this article useful, please click the ads on this page. Thank you very much.



Aug 30, 2011

TortoiseSVN Trick - How to update your authentication information

Today I changed my NT password as required by IT. When I use TortoiseSVN, it prompts wrong authentication error: Oh, I saved my name and password in SVN for a long time. That is the old NT password.

But how can I update it? I didn't find a place about updating... The answer is this: in TortoiseSVN,
go to Settings-->Saved Data. Clear Authentication data, then when you doing a commit, an authentication dialog will pop up for you to input the new values. This works!


May 26, 2010

Batch Command

Just want to quote a userful link http://dos.rsvs.net/DOSPAGE/BATCHCOM.HTM .

May 13, 2010

Generate logs for your setup during installation


You might have met the condition that you failed to install an application, but from the error message the installation, it's still hard to know find out the reason. At this time, you need to generate a log file for your installation. The steps are:
1, run register.exe go to HKEY_LOCAL_MACHINE\SOFTWARE\Policies\Microsoft\Windows\Installer,
a)add a string item
Logging, value: voicewarmup
2)add a DWORD item
Debug, value 7



2, after installation, go to temp directory, **** means your ID (like john, or administrator)
C:\Documents and Settings\*****\Local Settings\Temp,
The name of log file starts with Msi.... You can analyze all the actions within it.

Apr 16, 2010

Oops! Unhandled exception has ccurred in your application


We all hope that every day in our life is peaceful, joyful, and wonderful. But in reality, life will play joke on you. Treat or trick? Trick might be the answer.

Like today, I was played with a trick.
When I installed HP Neoview ADO.NET, all the process is good, as expected. But soon after, an error message box jumped out. As normal, I saved my current work, restart my computer (I have no time to deal with it). But after restart, the error still existed. Resistance? Sturben? I would use my second weapon - System Restore. I carefully chosed a Restore Point, but unexpectedly, system restore failed. Oh, I have no choice but to face the problem directly.

I checked the error message:

System.Configuration.ConfigurationErrorsException: Configuration system failed to initialize ---> System.Configuration.ConfigurationErrorsException: Section or group name 'HP.Data.Neoview' is already defined. This can not be defined multiple times. (c:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Config\machine.config line 118)

Isn't it simple? It even told you which line the error is. So just go the machine.config and remove a reduntant line, it works.

It's that simple? It's that simple, expecially for programmers.

Nov 13, 2009

Visual Studio 2005 convert to 2008 error: The project is under source control

Today I solved a problem when I tried to covert visual studio 2005 project to visual studio 2008 project, I met a prolem "The project is under source control". My solution is:
1, make all the read only files to readable (uncheck the readonly checkbox)
2, open the *.csproj file with UltraEdit, and remove the four lines of tags which begin with "Scc"

...
...
...
...

No, it's OK now.