Yu Sasaki's Blog

Icon

プログラミングとか英語とかの練習!

Eclipse WTP – progress

At the beginning of this week, I asked Darin Wright a question about how to locate the package that contains source lookup, and he replied to my email and posted a comment on the bug page.

I’m not familiar with the source locator used in web app’s. However, the issue is that a type with the same name (com.whatever.MyClass) exists in more than one application and the source locator finds one of them first. If there’s a way for the source locator to understand the context in which the source lookup is being performed (which module/web app?), then the source locator should be able to prioritize/order its search to look in the right place first.

This gave me a good insight of the cause of the bug.

I will try to figure out the source.

Filed under: open source

Release 0.1

Currently I’ve been working on the bug 173912, and with help of the comment at the bottom of the bug post, I tried locating the package which seemed related to the bug.

org.eclipse.debug.core.sourcelookup includes methods for source lookup, and one said this was the place where the bug might be located. However I was unable to find the source regarding the debug.core in CVS Repository.

Here’s my assumption of the cause of this bug.

There must be some locator method that mistakenly determines the app by only app’s project title.

Anyway I’ll try to locate the source code and analyze the bug more tomorrow.

See you!

Filed under: open source

Release 0.0 – Bug#173912

For the release 0.0 for OSD600, I’d like to work on the bug #173912 Debugger shows source from wrong web app

The bug seems a bit too difficult for me now, but I think it’s worth a try.

See you!

Filed under: Java, open source

Palindrome example using recursion in C

Today I tried resolving a problem with the palindrome example.

Here’s my code:

#include<stdio.h>
#include<string.h>

int do_palindrome(char *str, int offset){
	int ok = 1;
	int length = strlen(str);

	if(length/2 > 0)
		ok = (str[0] == str[length - 1 - offset])?
				do_palindrome(++str, ++offset):0;

	return ok;
}
int main(){
	int i = 0;
	int ok = 0;
	char* str[] = {"sasaki", "SOS", "12344321", "1234322",
                                             "555", "0", "ikki"};

	for(i=0 ; i<7 ; i++){
		ok = do_palindrome(str[i], 0);
		printf("%s is palindrome? : %d\n", str[i], ok);
	}

	printf("Finished!");
	return 0;

}

sasaki is palindrome? : 0
SOS is palindrome? : 1
12344321 is palindrome? : 1
1234322 is palindrome? : 0
555 is palindrome? : 1
0 is palindrome? : 1
ikki is palindrome? : 1
Finished!

According to Danny, our professor for DSA555, the keys to create a recursive function are the following:

1. Determine the base case

2. Make a progress toward the base.

If we apply the rule to our example above, the 1st rule is for “length/2 > 0.” The 2nd rule is how we make a progress toward the condition of “length/2 > 0.” Each time the function is recurred, we have to make sure the 1st, 2nd, 3rd… character is always compared with the last nth, n-1th, n-2th,… character at a time so that both sides get decreased in order to be closed to the center point.

This would be really hard if I do not know the rule.
I like abiding by a rule.

See you!

Filed under: DSA555

Eclipse WTP – Bug#173912

Today Jordan told me to reproduce some bugs in here. There are lots of bugs that need to be fixed, and I started browsing them. However, each bug has a different difficulty level, which is unknown to me, so a bug that seems easy at first glance might be actually a difficult bug, and vice versa. I have no idea. For the time being, I picked up one bug from the list and tried reproducing it.

Here’s the steps that I followed in order to reproduce the bug # 173912.

1. Create a dynamic web app named app1. Aim it at an APP server.
2. Create a class, com.whatever.MyClass, add the following methid, and save and close.
public String getGreeting() {
return “Number one!”;
}
3. Create a nother dynamic web project named app2.
4. Create a jsp index.jsp in app2 and also create com.whatever.MyClass and change “Number one!” to “Number two!”.
5. Set a breakpoint on the bean expression in app2’s index.jsp.
6. Add both projects to the server.

Here’s the screenshots for MyClass (in app1 and app2)

MyClass.java (in app1 and app2)

MyClass.java (in app1 and app2)

index.jsp (in app1 and app2)

index.jsp (in app1 and app2)

Next steps are the following:

8. Restart the server in debug mode.
9. Run app2’s index.jsp on the server.
10. When the breakpoint is hit, select “bean” in the Variables view in the debugger. Do <context menu>–>Open declared type. The Java editor will open, but on app1’s com.whatever.MyClass.

Here’s the screenshots for the steps above.

Trying to debug "app2"

Trying to debug "app2"

At this point, I’m debugging app2, and when the debugger reaches the breakpoint that I made in the index.jsp (app2) it should display the debug perspective and all the debugging information regarding app2 MyClass.

Instead, it displayed app1 MyClass information.

MyClass in app1 is displayed instead of the one in app2

MyClass in app1 is displayed instead of the one in app2

So the point of this bug is, when you have different projects which have the same structures, the debugger mixes up one another and yields mixed up information. I’m not sure why this happens. Anyway it for sure happens and I successfully reproduced the bug.

I tried to locate the cause of the bug.

What?

org.eclipse.debug.core.sourcelookup

I assume this source look up thing relates to the bug, however it’s a bit hard to decipher this.

See you!

Filed under: Java, open source

JDBC – using MySQL to make a connection between my local host and remote database

I created a “Student table” last time, and today I learned how to make a connection on Eclipse so I tried doing it.

I was given a code for SELECT statement using ORACLE driver.

My task was to make some modification in the code so that it can establish a connection with the remote host using mysql driver, instead of Oracle one, and successfully process the SELECT statement.

I changed the code like this:

// Invoke the dbQuery method
String driverName = “com.mysql.jdbc.Driver“;
String serverName = “zenit.senecac.on.ca“;
String portNumber = “3306“;
String databaseName = “my_account“;

String url = “jdbc:mysql://” +
serverName + “:” + portNumber
+ “/” + databaseName;

String u = “my_account“;
String p = “my_password“;

String query = “SELECT * FROM  Students“;

SELECT * FROM Students

SELECT * FROM Students

Works fine!

See you!

Filed under: EJB605, Java, Servlets & JSP

Learning the structure of Servlet

Today I learned Servlet in EJB605 class, and felt like learning it in more detail so I’ve read through some chapters of Java book.

Here are my understandings:

In the javax.servlet package, there is an interface called “Servlet” and followings are abstract methods to be overridden in future implemented classes.

Servlet interface

  • service(ServletRequest, ServletResponse)
  • init(ServletConfig)
  • destroy()
  • (a few more methods follow)

The interface is implemented by javax.servlet.GenericServlet class, which is an abstract class again, and that class is inherited by javax.servlet.http.HttpServlet class, which is now all set for being inherited by a Servlet we can implement. Here’s the hierarchy.

  • Servlet interface
    • implemented by GenericServlet class
      • extended by HttpServlet class

        • extended by our Servlet class (the most derived)

After a Servlet gets loaded by Web container, it initiates an object by calling the constructor of the Servlet. Then it calls init() method, and service() method follows. In the service() method, one of doX() method is called (or used to delegate another doX) to process the client request. After finishing the service, destroy() method is called to finish the life of Servlet.

The service() method has two parameters – HttpServletRequest and HttpServletResponse.

The interesting thing here to me is both are interfaces extended (not implemented) from the other interfaces – ServletRequest and ServletResponse.

  • ServletRequest interface
    • extended by HttpServletRequest interface
  • ServletResponse interface
    • extended by HttpServletResponse interface

I didn’t know the fact that an interface can extend another interface…so this was an eye opener. Anyway, the service() method has parameters of references for two objects that implemented HttpServletRequest and HttpServletResponse interfaces polymorphically. How the actual classes for these interfaces implement their methods are all dependent on vendor, so we do not need to care about it. A variety of methods are available in each request and response objects.

See you!

Filed under: EJB605, Java, Servlets & JSP

JDBC – using mysql driver on Mac

Today I learned how to interact with JDBC.

Tasks were :

  • Create a table called “Students” onto mysql database in my zenit account
  • Insert Students data into the table

At first time, I had a problem with importing the mysql driver.

I needed to set up a CLASSPATH environment variable so that the Java compiler can make use of the driver wherever it’s placed, but I had no idea how to set up classpath on my Mac. After googling, I found out some ways to set up CLASSPATH on Mac, and the easiest way that I figured out is this: putting the following line in my .bashrc file.

export CLASSPATH=/Library/Java/Extensions/mysql-connector-java-3.1.8-bin.jar;

Now that my Java compiler knows where to get the actual mysql driver class by CLASSPATH keyword, I am able to compile my Java program with the following simple command.

javac -cp CLASSPATH -d classes db/*.java

If I don’t use CLASSPATH, I have to use the following long command.

javac -cp /Library/Java/Extensions/mysql-connector-java-3.1.8-bin.jar -d classes db/*.java

See you!

Filed under: EJB605, Java

Response to “Learning to be at the festival”

I saw the lecture video : Getting started in Open Source projects, or “Learning to be at the festival”: David Humphrey.

The video was very interesting. I like the way David described diving into an open source community as going to the festival.

As he told us last week, we do not need to be a main people who plays a significant role in the community, but I can be one of participants who enjoy the atmosphere – “because you are there, you are part of it.” The video encouraged me in a way I got an urge to learn and get most out of the involvement in the Eclipse WTP project.

I will try IRC to find some community formed for Eclipse development.

Filed under: open source

Running Eclipse using 32 bit JVM instead of 64 on Apple Mac

I decided to go for Eclipse WTP development, and Jordan asked me to read this tutorial to get a grasp of how to work on.

I’m going to make notes regarding the tutorial and problems that I faced.

Actually I am kinda new to Eclipse so I needed to learn a lot of terminologies relating to this tutorial.

Here’s the summary of some of key terminologies that I learned.

  • Eclipse WTP – WTP is a short for  Web Tools Platform. Eclipse WTP is one of top projects of Eclipse. Eclipse WTP’s goal is to become sort of a defact-standard in web-development by providing Web/J2EE development tools. WTP consists of two sub-projects: WST (Web Standard Tool), JST (J2EE Standard Tool).
  • WST basically covers non-Java development portion such as HTML, XML, SQL….
  • whereas JST covers Java-development portion such as JSP, JDBC, Servlet… WTP integrates these two portions and produces one powerful IDE for web development.
  • JRE – Java Runtime Engine, and JVM is an instance of this.

Let me start my first tutorial for Eclipse.

In this tutorial, we assume that current WTP has the following bug.

When a Web Application is running, in the server view the ToolTip window must display the date nd time when the window is created.

The following picture shows where the problem is.

Bug

Bug

In the picture above, we want tooltip area to display current system date and time instead of “Tomcat v6.0 Server at localhost”

So I started working on this pseudo-bug based on the tutorial. I did not encounter any problems until I reached the point where I was to deploy the change that I made for the target platform.

In the step 4 : Running your Eclipse Application, when I clicked on “Run” on my Development platform, it was supposed to launch the Target platform automatically.

Instead, I encountered the following errors.

java.lang.UnsatisfiedLinkError: Cannot load 32-bit SWT libraries on 64-bit JVM

This seems my Mac JVM is 64-bit and SWT (what is this?) needs 32-bit JVM in order to use.

I was a bit confused about the fact that I needed 32-bit JVM instead of 64-bit.

For the time being, I started looking for 32-bit version of JVM using google.

And I found terribly interesting thing here:

Apple is not supporting the 64-bit carbon API. SWT is written using carbon so it must be 32-bit. Apple won’t support 32-bit JDK 1.6. Therefore SWT won’t run on JDK 1.6 (along with any other Java program that had natives that made carbon calls).

Oh, I got it! In short, Apple doesn’t like Java.

At the moment, I could have moved to another platform to work on such as Windows / Linux…. but I wanted to persist with Mac because if I cannot solve this problem, I will be likely to end up mainly working with Windows / Linux platform most of the time during this semester, which is not good for me because I love Mac!

So I started further googling.

and I found a lot of websites attempting to install a lot of things to try to solve this problem.

and finally I found one comment at the end of the article in this blog which was the easiest and simplest way to solve this problem.

What I needed to do was just type in “-d32” in VM argument field

VM argument

VM argument

This forces Eclipse to use 32-bit JVM instead of 64-bit JVM. Very simple answer.

Now that I’m ready for using 32-bit JVM, I can apply changes that I made!

Here’s the result:

Now it displays the current date and time

Now it displays the current date and time

Now it’s working.

Yeah!

See you!

———————————–

In this article, the author is talking about OS X 10.6 Snow Leopard:

There are some major news regarding Java in Snow Leoprad. First, it ships with Java 6 only. This includes 32-bit and 64-bit versions. The 32-bit is something which was unknown until the release of SL and it means Java 6 will be available on older intel machines which are not 64-bit capable (Intel Core Duo). Second, the 64-bit version is the default for users running 64-bit capable machines (Intel Core 2 Duo).

So since Snow Leoprad, which is the latest version of Mac OS, even though it has a capability of running both 32 and 64 bit JVM, Eclipse is defaulted to run 64-bit version of JVM.

Filed under: Java, open source