Win a copy of Five Lines of Code this week in the OO, Patterns, UML and Refactoring forum!

Hrishikesh Ghatnekar

Greenhorn
+ Follow
since Oct 25, 2004
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Hrishikesh Ghatnekar

Gone through the post but answer is still not clear to me.

The following code will go in the java file and not is ant /xml file


AntClassLoader classLoader =
(AntClassLoader) getClass().getClassLoader();
String taskPath = classLoader.getClasspath();



Can you please tell me what are the changes needed in the xml file?
12 years ago
Hi,

Currently we are facing a very strange problem related to class path.

We have a program which we normally run by using ant.

To cut long story short , our program runs when we set the classpath using command prompt , and doesn't run when we try to run it through the ant ( which contains the same class path )

Here are the details


Non Working situation..


Our ant file contains following entire

</description>

<import file="prog.xml"/>
<!-- Import the prog properties -->
<property file="${prog.installLocation}/bin/prog.properties"/>


<target name="startPROG" description="Start the PROG">
<startPROG/>
</target>

....

And prog. xml contains following entries


<!-- Define the location of the prog -->
<property name="prog.installLocation" value="F:\ourprog\try"/>

<!-- ClassPath -->
<path id="task.classpath">
<pathelement location="${prog.installLocation}/lib/abc8.0-7.jar" />
<pathelement location="${prog.installLocation}/lib/abc8.0-3.jar" />
<pathelement location="${prog.installLocation}/lib/xyz8.0-227.jar" />

</path>
<echo>prog.installLocation is = "${prog.installLocation}"</echo>
<property name="cp" refid="task.classpath"/>
<echo message="Classpath is ${cp}"/>
<taskdef name="startPROG"
classname="net.xyz.ant_tasks.PROGTask"
classpathref="task.classpath" />



Now the abc8.0-7.jar , xyz8.0-227.jar contains a xml and a property file of same name , say ourprog.properties , ourprogram.xml. Though the name are same the contains are different.


When we try to run our program like , ant startPROG

We get message can not find ourprog.properties.



Now working solution


Open a command prompt

set classpath=F:\ourprog\try\abc8.0-7.jar;F:\ourprog\try\abc8.0-3.jar;F:\ourprog\try\xyz8.0-227.jar;

and then run the same command , ant startPROG
and the program WORKS.



Any idea what is going wrong here , and how can I debug further?
12 years ago
Ok , Suppose I create a static variable inside a class.

Class myclass{

Static String aa = �xyz�;
///
///

}


Now this class variable is used in different places in the code.

Sysout ( �The value is �+ Myclass.aa);


In ideal case, every time the variable is accessed , it should print / return the "xyz" value.


My question is , Is there any possibility that the value of aa will be returned different than �xyz� ( Say null )anywhere in code?
( Nobody changes the string aa or assigns null to it)
12 years ago
Is it possible that

the vale of a static variable is different within a same JVM at different code locations at SAME point of time ? ( Of course nobody modified the value at any point of time)
12 years ago
Can you help in finding the answer for following?

1)Is there any way in java to access the value of the private variable outside the class?
12 years ago
Well I tired with the modifications suggested , but the result is still the same

import java.util.*;
class general
{
public static void main(String[] args)
{
System.out.println("Hello World! general");
general gg = new general ();
gg.takeit(new HashMap(), long 18);
}
public void takeit( HashMap dd , long ee)
{
System.out.println("long value is "+ee);
}
}

---------- javac ----------
general.java:10: '.class' expected
gg.takeit(new HashMap(), long 18);
^
1 error



Can somebody please help?
12 years ago
I am trying to compile following program and it is giving me error

"general.java:8: '.class' expected
gg.takeit(new Hashmap(), long 18L); "

Can somebody tell me what is wrong in the below program?



class general
{
public static void main(String[] args)
{
System.out.println("Hello World! general");
general gg = new general ();
gg.takeit(new Hashmap(), long 18);
}


public void takeit( Hashmap dd , long ee)
{
System.out.println("long value is "+ee);

}



}
12 years ago
Yes, Very Much correct.

Thanks for the help


:-)
14 years ago
Hi,

I am trying to create one singleton class and planning to use it in my application.
My question is what will be difference if I try to access the methods of the singletone class in following ways

1)Singletone.getInstance().methodName()
2)Singletone.methodName()

In Second case how come the program work without going thorough the constructor?


The code for my program can be

public class Singltone_impl {

private static Singltone_impl validator = null;

protected Singltone_impl() {
System.out.println("In Singltone_impl constructor <=");
init();
System.out.println("Singltone_impl constructor <=");
}

protected void init() {
System.out.println("In Singltone_impl init <=");
System.out.println("In Singltone_impl init =>");
}

public static Singltone_impl getInstance() {
synchronized (Singltone_impl.class) {
if (validator != null) {
return validator;
} else {
validator = new Singltone_impl();
return validator;
}
}
}

public static boolean validate(String email_id) {
System.out.println("In Singltone_impl validate ");
if (email_id == null || email_id.trim().length() < 1) {
System.out.println("Singltone_impl , email ID not present , returning false ");
return false;
}
else {
System.out.println("TRRRRRRRRRRUEEEEEEEEE");
return true;
}
}



}

14 years ago
g2d.drawString ("text4", (int)(18.5*POINTS_PER_CM), (int)(12.2*POINTS_PER_CM));

Instead of text4 your can use arrayobject.toString();
Which will give you [ array contains, array contains,....] result

Else extend a class from arraylist , and override toString method to get the desired output.

Thanks
14 years ago
Hi,

I don't know the direct way/ single step way,
But one way is through eclipse

Remove all the jars from the eclipse
It will start showing red lines for missing classes.
Add the missing package, and continue till there are not redlines in the file
Definitely , not the best option, but this can be the way

Thanks
14 years ago
I want to open a URL trough a java code with post menthod ,but I am getting errors .

If I copy past the same URL in the browser or try throuth the get method it works fine.


My code is

try{

String parameters= new String("http://myserver.hri.com/GetService/something.aspx?Mode=TEST&msgsEBT.ProcessComet&Action_Required=DELETE+ME%28S%29&Affected_Item=ABCD&Assignee=Analyst+Generic&Assignment_group=TESTGRP&Short_Description=Service+Deco+of+10445+++JuTest&Description=%0A%0A%0A+++++++++++++Additional+Description++++++++++++++++++++%0AC+L++Environment+%28s%29+++%3DTEST%2C+QA%2C+PROD.%0AName%09+++%3DTest%0ASceID%09%09+++%3D10445%0AEstimated++entitlements+%09+++%3D%0AService+usage+in+past+3+months%09+++%3DNO%0APrio rity=sadassad&Request_Type=General&Subcategory=XXXX");


URL url = new URL(parameters);

HttpURLConnection urlConn = (HttpURLConnection)url.openConnection();
urlConn.setRequestMethod("POST");

urlConn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
urlConn.setRequestProperty("Content-Length", parameters.length()+"" );
System.out.println("going to open document");
Document xmlRetMsg = new Document(urlConn.getInputStream());
Element root = xmlRetMsg.getRootElement();
System.out.println("got root element ");
String condition = root.getChildText("_condition");
if (condition == null || condition.equals("false")) {

System.out.println("Got _condition null or false with "+xmlRetMsg.getXMLString().toString());

}


}

} catch(Exception ee){
ee.printStackTrace();
}
}




After running the prog following is the O/P


java.net.SocketException: Connection reset
at java.net.SocketInputStream.read(SocketInputStream.java:168)
at java.io.BufferedInputStream.fill(BufferedInputStream.java:183)
at java.io.BufferedInputStream.read1(BufferedInputStream.java:222)
at java.io.BufferedInputStream.read(BufferedInputStream.java:277)
at sun.net.www.http.HttpClient.parseHTTPHeader(HttpClient.java:756)
at sun.net.www.http.HttpClient.parseHTTPHeader(HttpClient.java:844)
at sun.net.www.http.HttpClient.parseHTTP(HttpClient.java:711)
at sun.net.www.http.HttpClient.parseHTTP(HttpClient.java:721)
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:626)
at testclass.doit(testclass.java:53)
at testclass.main(testclass.java:21)
Hi ,


I want to develop a code which can take care of following senario

We want to develop a form which accepts and processes user request in background

Here is the use case


1)User fills the form information (JSP )
2)Hits on a submit on the form
3)On submition , we will call a servlet which will do validation of the form data and then the servlet will call a status jsp
4)The status jsp will show message , that request is submitted and then will make a call for processing. ( Processing takes about 2 mins)

The problem that I am facing is

Even if I include the process call at the very end of status jsp , still the status jsp appears after the process call is complete.

Basically what should be done so that method calls happens after the jsp is displayed?



Thanks
Hrishikesh
14 years ago
Hi ,

I have downloaded and extracted the tomcat zip folder ON HDD. Then created the Catalina env variable


C:\Documents and Settings\hrishik>echo %CATALINA_HOME%
C:\eclipse3.1\jakarta-tomcat-5.0.5\


Now when I try to start my tomcat ( Catalina.bat run )

I get following error

C:\Documents and Settings\hrishik>C:\eclipse3.1\jakarta-tomcat-5.0.5\bin\
a.bat run
Using CATALINA_BASE: C:\eclipse3.1\jakarta-tomcat-5.0.5\
Using CATALINA_HOME: C:\eclipse3.1\jakarta-tomcat-5.0.5\
Using CATALINA_TMPDIR: C:\eclipse3.1\jakarta-tomcat-5.0.5\\temp
Using JAVA_HOME: P:\dist\msjava\jdk\1.4.2_02
java.lang.ClassNotFoundException: org.apache.catalina.startup.Catalina
at org.apache.catalina.loader.StandardClassLoader.loadClass(Stand
sLoader.java:891)
at org.apache.catalina.loader.StandardClassLoader.loadClass(Stand
sLoader.java:756)
at org.apache.catalina.startup.Bootstrap.init(Bootstrap.java:215)
at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:375)



Please help me to solve this problem


Thanks
hrishig
14 years ago