hemkar kumar

+ Follow
since Nov 27, 2014
Merit badge: grant badges
For More
Cows and Likes
Total received
In last 30 days
Total given
Total received
Received in last 30 days
Total given
Given in last 30 days
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by hemkar kumar

Hi There,

I am stuck with some silly problem in one of my legacy application.

Problem goes like this.

i have one URL  where i pass some parameter in URL ( URL?param=value) and open the jsp say JSP1

That param i have used inside hidden field of JSP1 as given below.

Now  after filling form, which is present in that  JSP1 user has to submit the form . But if user clicks submit, action is given to land on same page (JSP1) where i need to fetch the value of hidden field and check whether data is present or not and based on that need to invoke some java code.

to fetch the hidden field i have below code in JSP1

But queryParamis being assigned null after submission of form.

it is a legacy application, i don't have much option to make lots of code changes. So can anyone suggest if there is any another way to handle this situation.
4 years ago
Hi there,

I am trying to learn Generics and currently following "java the complete reference".

I have created a  method (boolean isAvgEq(Gen<? > obj)) with wildcard, this method is suppose to return true if average is same for 2 arrays else false. There are 2 arrays in my class one of type Integer and another of type Float. My expectation is to print true as data is the same for both arrays. But it is returning false. Even I have checked the value by printing the average of both the array and it returned the same value of "3.0"

5 years ago

Stephan van Hulst wrote:

Note that ai and i are different variables.

Thanks, Stephan didn't even thought about it, kept thinking about high-level thread concepts. It is working now all because of you.

5 years ago

Stephan van Hulst wrote:Well, why would the value of i ever change once a thread is inside a while loop?

Hi Stephan,
Thanks for your attention. Yes, you are right.
But as per sample output which I have mentioned above, once the Even thread has printed "2"  it incremented the value of i by 1, as per code inside getAndIncrementAi(). Then why the Odd thread is not able to pick that updated value of "i" which should be 3, instead of value "i" read by the Odd thread is still 2. After that, both Thread went inside while loop waiting for next even or odd number.

I am trying to figure out where is the gap in my understanding.
5 years ago
Hi there,

Just trying to learn Threads concepts and i am trying to print odd and even number using 2 threads and program is copied below.
problem is this program is not working as expected.

Some time threads are able to pick correct number and based on that it is able to decides whether it should wait or it should print the number, but after some time both threads goes to waiting state and gets stuck there.

If i apply same logic using AtomicInteger than it is working file. you can check the code using AtomicInteger here

As per my understanding AtomicInteger will make all operation atomic so if i use only volatile i can not achieve that , to achieve atomicity i have added synchronised method to increment the value of number.

Please help me to understand where exactly i am going wrong.

Sample Output:
ODD THREAD Inside syncronized block with i=1
ODD THREAD printed :1
ODD THREAD Inside syncronized block with i=2
ODD THREAD Inside while loop with i=2
EVEN THREAD Inside syncronized block with i=2
EVEN THREAD printed :2
EVEN THREAD Inside syncronized block with i=3
EVEN THREAD Inside while loop with i=3
ODD THREAD Inside while loop with i=2
5 years ago
Hi There ,

I was trying to learn java.util.concurrent.Callable and i came to know that call() method of Callable can throw Exception and we will get it back if we call get() on future object. But just trying to figure out how to handle the case  when main thread is already dead and call method has thrown some exception.

Just to highlight i am using isDone() to check whether task is still executing.

I have refered these links but couldnt get much idea abut my case.

Thanks in advance. Hope someone is out there to clear my doubt.

Driver class:

Callable class:

Mian method over
5 years ago
My springform validation is not working as expected. I have checked the tutorials for form validation but not sure what exactly is the issue in my code.

User.java (Bean class)

Controller code:

JSP Form :

5 years ago

Tim Moores wrote:I believe your understanding is correct. If you have a Java 6 JRE, it should work.

I don't have JRE 1.6 instead I have JRE 1.8 installed. My doubt is if I am able to compile my code even without JRE 1.6 then is it not possible to run that same code without JRE 1.6?
7 years ago
My system is  having JDK 1.8 installed  and I am trying to run a java program without main, for compilation, I am using command and for running

compile time warning :
warning: [options] bootstrap class path not set in conjunction with -source 1.6
1 warning
Runtime Error:
Error: Main method not found in class Test, please define the main method as:
  public static void main(String[] args)
or a JavaFX application class must extend javafx.application.Application

Can someone guide me for running above code using JDK 1.6 which command I have to use. As per my understanding, we can't run this code without main above JDK 1.6.

7 years ago
Sorry, i found the issue. instead of double (primitive type), i am using Double (Wrapper class) in the overloaded method as argument type.

Anyway thanks for your valuable time and reading my issue.
7 years ago
Currently, I am learning method overloading where I came to know that in case compiler unable to find required method with the float argument than compiler will try to promote arguments to next level that is double.But in my case, automatic promotion is not happening instead I am getting compile time error mentioned below.

I have two classes one contains the main method and other contains overloaded methods.


7 years ago