tangara goh

Ranch Hand
+ Follow
since Dec 27, 2009
I am a beginner in Java and hope to pick up the trade secrets so that I can move on to Android development
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
2
Received in last 30 days
0
Total given
91
Given in last 30 days
3
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by tangara goh

Hi experts,

I am new to Mockito and JUnit.

So, I tried my hand on testing out the JNDI connection class :





But, when I run the test in Eclipse, it doesn't give me any clue to what error...

Can I know if I have missed out something important or how to make Junit tells me what is wrong or if the Connection works ?

Thanks!
2 days ago
I was looking for example of pagination and then at the jsp portion and then I came across this :

tech24salt.blogspot.com › 2013/06 › pagination-in-jsp-and-servlet









can someone tell me what is employee.do ?  why put a .do behind employee ?
1 week ago
JSP

Jeanne Boyarsky wrote:Adding group by won't help because then you'd have to use an aggregate. If you are worried about duplication, add a distinct to your select clause. I don't know how much duplication you'd have though. Id sounds pretty unique.



Hi Jeanne,

It is not adding Select distinct on t1.1a right ?

Select t1.a, t2.b, t2.c from t1 join t2 on t1.id = t2.id where t1.a = ?, t2.b = ?, t2.c = ?

I have use distinct on t1.id = t2.id but then it gives me error...

so, I am not sure where about to put Select distinct.

Could you kindly let me know ?

Tks.

Junilu Lacar wrote:

tangara goh wrote:Well, I am here for the reason of getting my concepts right.


That's a good start

I know POJO is a stateless class.


No, that is quite often not the case. See the definition of a Plain Old Java Object (POJO).

Any object that has instance fields is stateful. Any object whose state can be changed by any means, whether indirectly through a method call or directly via an assignment has mutable state. Any object whose state cannot be changed by any means after it is created has immutable state.

In order for it to be stateless, an object must have NO instance fields.

However, when I created more classes or rather servlet to be precise I discovered i need to access to properties of my POJO sometimes using static and sometimes non static pro properties of the same property(properties).


I don't understand what you mean by that, nor do I think others. Could you share a code example that illustrates what you're trying to explain?



Hi Junilu,

I managed to find the stackoverflow example which explains why used Singleton for enabling another class to access the class variable instead of static. So it will leave the ‘Base class’ to have non static.

Is that how things are done?

Jeanne Boyarsky wrote:If you don't care what the id is, you don't need a ?. It's only if you want t a specific value.

The ? you have for the other values are good.



Thanks Jeanne.

BTW, is it possible to add group by id at the end and it will make the data less duplicated ?

Tim Holloway wrote:

tangara goh wrote:

Campbell Ritchie wrote:The fact that you can find an example on the Net doesn't necesarily mean it is a good thing.



Yes.  That's the reason I am seeking for an answer and solution.

Basically, I am faced with a situation where I need the attributes or Class members to be static and non-static at the same time.

So, example, if I want it static, I will call the static member and if the data get changed again due to the use case, I want another class to be able to call the non-static Class member.

How do I accomplish that ?

I am using Java servlet and jsp so I researched and found out people are using dependency injection.

But, uisng Java servlet I don't think it is possible to use dependency injection to achieve the above static and non-staic accessing....



If you don't get your concepts straight, you're going to have a hard time.

Classes don't call classes. Methods invoke methods. Methods may access properties (members). If we're feeling generous, we'll let you use the term "call" for "invoke", but that's about it. Classes don't do anything. They're just containers for the methods and properties. Likewise, you cannot "call" a class, only methods within the class. This is true whether things are static or member scope.

Dependency injection is part of the concept of Inversion of Control (IoC), but I don't think that's relevant here. More to the point is that to make properties thread-safe, static and non-static are equally at risk. To be thread-safe, access to the property has to be synchronized.



Well, I am here for the reason of getting my concepts right.

I know POJO is a stateless class.

However, when I created more classes or rather servlet to be precise I discovered i need to access to properties of my POJO sometimes using static and sometimes non static pro properties of the same property(properties).

And I would like to know how to make it happen ?
I would like to seek advice on a query "

Select t1.a, t2.b, t2.c from t1 join t2 on t1.id = t2.id where t1.a = ?, t2.b = ?, t2.c = ?

My questions :

1) if I do not know the id, should I put a ? in the query
2) do I need to set prepared statement for id ?

Thanks in advance.

Campbell Ritchie wrote:The fact that you can find an example on the Net doesn't necesarily mean it is a good thing.



Yes.  That's the reason I am seeking for an answer and solution.

Basically, I am faced with a situation where I need the attributes or Class members to be static and non-static at the same time.

So, example, if I want it static, I will call the static member and if the data get changed again due to the use case, I want another class to be able to call the non-static Class member.

How do I accomplish that ?

I am using Java servlet and jsp so I researched and found out people are using dependency injection.

But, uisng Java servlet I don't think it is possible to use dependency injection to achieve the above static and non-staic accessing....

Campbell Ritchie wrote:

tangara goh wrote:. . . how to make a variable static thread-safe then ? . . .

I think I shall join the Winston Gutkowski School of Computing and tell you there should be no such thing as a static variable in the first place.

singleton pattern . . . ..

Many people think it is called the Singleton Anti‑Pattern. Another thing you should probably avoid.



I Google and I found java static variable.

Tim Moores wrote:

Avi Sarma wrote:numOfTickets is not an object. yes. it is a variable which is not thread safe so made it static.


Note that making a variable static does not make it thread-safe to use. To the contrary, it increases the chance of concurrency issues because now all threads have access to it.



Hi Tim,

I chance upon this 'thread', could you explain how to make a variable static thread-safe then ?

Do we use singleton pattern in the case of different classes need to access a 'member variable' of a POJO class ?

To be more specific, cos I am also not sure what term to use.  When I mean member variable :

Example :



However, I also learnt that a singleton pattern uses synchronized which is bad.

Hope to have your views.

Thanks.

Stephan van Hulst wrote:Get rid of the attributes. Show us the latest version of your code, and the error message.



The problem is that there isn't any error at all.  And with the added fn:users.length, it is not printing anything at all....as in not showing that row of data earlier on.
1 month ago
JSP

Dave Tolls wrote:If you want to display everything in the list, why are you using the begin.end attributes of the tag?



Because it is not printing everything.  It only printed the first row.

Hence, at first I tried to use {fn:length(users)} to see if it captured the length of the attributes users.

But, it will give me error even though I have put in the import fn Taglib.

1 month ago
JSP

Stephan van Hulst wrote:You know, you can easily solve these problems by yourself if you just format your code correctly:

XML tags must either have a closing tag, or must be self closing. I can count 4 unclosed start tags, and one closing tag without a start tag.

By the way, did you mean to enclose the last four counts in double quotes? That's not necessary for XML element values.



Thanks for your hints.  I got it.  I guess I am exhausted and flat from coping with so much things...i wonder if other people will get this kind of tiredness...

Anyway, I hope to seek your advice on why I still can't get the list to be printed after adding this :



as suggested by this : https://stackoverflow.com/questions/15905055/jstl-message-dont-know-how-to-iterate-over-supplied-items-with-foreach



1 month ago
JSP

Ron McLeod wrote:

tangara goh wrote:Cos I have closed off <c:/forEach> so why is it unbalanced ?


I see two problems with your markup:

1. The first <c:forEach> tag is self-closing, but you have a </c:forEach> tag later-on in the document.
2. There doesn't appear to be an opening <table> tag anywhere.

Hi Ron, Even after removing the / at the varStatus I am still getting same error :( I have further removed all the / that is under each </td>

1 month ago
JSP

Junilu Lacar wrote:Check out https://docs.oracle.com/javaee/6/api/javax/servlet/jsp/jstl/core/LoopTagStatus.html to see other properties of varStstus you can use.



Hi Junilu,

I have read the link.  However, I do not think you can use .getCount() inside JSP/JSTL right ?

Anyway, I get to learn .count from stackoverflow ...

Could you let me know why am I getting that error ?

Cos I have closed off <c:/forEach> so why is it unbalanced ?

Anyway I can find out what unbalanced mean ?
1 month ago
JSP