Tallan's Technology Blog

Tallan's Top Technologists Share Their Thoughts on Today's Technology Challenges

Author Archive

Java could be a pain to C# developers (Pass by Reference)

In C++ and C#, developers have freedom to modify variables by directly having access to memory location.
In C++,
#include <stdio.h>
void swapnum(int &i, int &j)
{
int temp = i;
i = j;
j = temp;
}

int main(void)
{
int a = 10;
int b = 20;
swapnum(a, b);
printf(“A is %d and B is %d\n”, a, b);
return 0;
}
In C#,
int a = 1;
modify(ref a); //now a=2
void modify(ref int a)
{
a = 2;
}
In Java, however, there’s no such thing as pass by reference. Even the so-called pointers (created by ‘new’ operator) are passed by copy of the reference.
Thus, if you do the following,
String a…

Pass by reference

In C++ and C#, developers have freedom to modify variables by directly having access to memory location.
In C++,
#include <stdio.h>
void swapnum(int &i, int &j) {
int temp = i;
i = j;
j = temp;
}
int main(void) {
int a = 10;
int b = 20;
swapnum(a, b);
printf(“A is %d and B is %d\n”, a, b);
return 0;
}
In C#,
int a = 1;
modify(ref a); //now a=2
void modify(ref int a)
{
a = 2;
}
In Java, however, there’s no such thing as pass by reference.  Even the so-called pointers (created by ‘new’ operator) are passed by copy of the reference.
Thus, if you do the following,
String a = “a”;
modify(a); //a doesn’t change, since a is being passed as a copy of the pointer a.
void modify(String a)
{
a = “b” //this a is a different pointer, thus does not affect the real ‘a’ pointer outside of the method.
}
As you can see, there’s no direct way of modifying…

Cache as a cross-cutting concern

I have been recently asked to look into the cache feature within Springmodule in Java community.
Since my current project utilizes spring and aop, I thought it would be a great idea to utilize AOP to cache data.
I actually wrote a prototype file and it was a very rudimentary yet working prototype.  However, I soon realized that Springmodules already created such feature, and it toally is a great feature to use.
Using simple AOP concept, you intercept the method call and using method parameters as HashKeyGenerator input values, the Springmodules’s cache simply get/put data from/into cache storage.  Currently, I configured it to using OSCache for its native support by Springmodule Cache Provider.
https://springmodules.dev.java.net/docs/reference/0.8/html/cache.html
I believe as the frameworks such as Spring evolves, developers can truly focus on their logic and development without worries of logging, security, cache, and any other cross-cutting concerns.  AOP is…

Cache as a cross-cutting concern

I have been recently asked to look into the cache feature within Springmodule in Java community.
Since my current project utilizes spring and aop, I thought it would be a great idea to utilize AOP to cache data.
I actually wrote a prototype file and it was a very rudimentary yet working prototype. However, I soon realized that Springmodules already created such feature, and it toally is a great feature to use.
Using simple AOP concept, you intercept the method call and using method parameters as HashKeyGenerator input values, the Springmodules’s cache simply get/put data from/into cache storage. Currently, I configured it to using OSCache for its native support by Springmodule Cache Provider.
https://springmodules.dev.java.net/docs/reference/0.8/html/cache.html
I believe as the frameworks such as Spring evolves, developers can truly focus on their logic and development without worries of logging, security, cache, and any other cross-cutting concerns. AOP is…

Hibernate: Merge vs SaveOrUpdate

In my previous and current project, I have run into cases where I needed to save an object to database using hibernate, and from time to time, I run into some sort of Hibernate Session Exception.
I did a bit of google search, and it turns out that when saving an object, I needed to make sure the object was attached to Hibernate session.
This can be very tedious issue, since that means if you need to save an object that is not attached to a session, you need to do these.

Retrieve the object using the Id value found within the object passed to you.
Update the property values one by one
Save the object back within the same Hibernate Session

Here’s a quick summary that I found out about MERGE and SaveOrUpdate.
void saveOrUpdate(object)->object must be attached to a hibernate session (including all sub objects…

Process vs Thread

Yesterday, Google launched their first web browser application, named Chrome.
http://www.google.com/chrome
And here’s an interesting cartoon that describes Google’s take on web browser.
http://www.google.com/googlebooks/chrome/
What’s interesting is the idea of Process vs Thread.
Google’s Chrome uses Process for individual window, tab, and even plug-in.
In contrast, Firefox, the popular open source web browser, utilizes multiple threads for managing its windows, tabs and even plug-ins.
I think some of you remember that Internet Explorer has always been using Process for windows management. Any new windows are launched via new processes, and people did not like this idea, I guess. Firefox, instead, created one process application.
Of course, Internet Explorer 7 uses threads, but only on the tabs.
So, google’s take on web browser application is to use all process and no thread. I find this quite interesting, because as we all know, process takes more memory space than thread does….

Uploading file: the .NET MVC way

In ASP.NET, the traditional way of uploading files is as follows.
<form id=”form1″ runat=”server”>
<asp:FileUpload ID=”FileUpload1″ runat=”server” />
<p>
<asp:Button ID=”Button1″ runat=”server” Text=”Upload”
OnClick=”Button1_Click” /></p>
<p>
<asp:Label ID=”Label1″ runat=”server”></asp:Label></p>
</form>
And you have access to the uploaded file like this.
protected void Button1_Click(object sender, EventArgs e)
{
//FileUpload1.PostedFile
}
In .NET MVC, you can achieve the same with the following code.
<form action=”/controller/action/” accept-charset=”UNKNOWN” enctype=”multipart/form-data” method=”post”>
<label for=”file1″>file1</label>
<input id=”file1″ name=”file1″ size=”20″ type=”file” />
</form>
The controller side
foreach (string fileName in Request.Files)
{
HttpPostedFile file = Request.Files[fileName ];
}
It is important to understand the fundamental difference between the traditional web-form based .NET programming methods and the .NET MVC methods. You can still use the server controls, but you can only use them for read-only data rendering purpose, since ViewState is no longer an option in .NET MVC.
-SK

\\\