Win a copy of Micro Frontends in Action this week in the Server-Side JavaScript and NodeJS forum!

Kunal Goel

Greenhorn
+ Follow
since Sep 08, 2002
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 Kunal Goel

I don�t think there are many changes to the presentation tier in Java EE 5. The most striking new additions like DI pattern, Annotations (new feature introduced in Tiger), cutting down of XML DDs, boilerplate code, POJO and POJI support for agile development etc. are targeted towards the business tier.

Here is a brief look at changes in Java EE 5:

Presentation tier: JSF
Business Tier: EJB 3.0 (Annotations support)
EIS tier: Java Persistence API (POJO based O/R mapping)
Design patterns: Dependency Injection (container injects dependencies like DataSource, EJB references etc.)

With Java EE 5 web application deployment descriptor is optional for simple web applications containing JSP pages and static files. If your web module does not contain any servlets, filter, or listener components then it does not need a deployment descriptor.
Hi Karthik,
Well, the thread really doesn't answer my question. What I was expecting was something very concrete, maybe in terms of figures and bar graphs (comparing Spring with Weblogic or Websphere for that matter).

Rgds,
Kunal
Spring is very new to the market and provides a new lease of life to framework development. The influence of Spring on the latest EJB specification is undeniable.
Well, a lot has been spoken and written about the Spring application framework.
Nobody can deny that Spring directly aims at Application Servers like IBM�s Websphere and BEA�s Weblogic. But, has anybody done a serious study of comparing the performance of Spring�s lightweight containers and these app servers.

So, are there any benchmark results available yet.

Rgds,
Kunal
SCJP
Hi Ben,
Thanks for that. In feature I'll take care of all that.
There a lot 2 learn here.

Regards,
Kunal Jaggi
SCJP
15 years ago
Hi Ben,
Thanks 4 ur post.
As far as my knowledge goes a Serializable object can be made persistent. It should implement the Serializable interface, which is a marker interface in the java.io package.

Could u plz. go through my code snippets and let me know that where exactly is the problem.

Regards,
Kunal Jaggi
SCJP
15 years ago
HI! Ben,
Thanks for the post.
I'm still struck. I have gone through the Code Snippet at the IBM Developer Works site. The only difference between my application and the code snippet on the IBM site is that I'm writing a byte of stream and the article discusses abt. writing a serializable object.

Anybody plz. help.

Regards,
Kunal Jaggi
SCJP
15 years ago
I�m trying to POST data to a Servlet from a Java application and read back the response generated by the servlet. The servlet does a quick database query and returns the response.

Following is my servlet code:
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.ServletException;
import javax.servlet.ServletConfig;

import java.sql.*;

public class HelloServlet extends HttpServlet {
private Connection con;
private Statement stmt;
private ResultSet rs;

public void init(){
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
con=DriverManager.getConnection("jdbc dbc:tunnel");
}catch(Exception e){
System.err.println("Error-->"+e);
}
}
public void destroy(){
if(con!=null)
try{
con.close();
}catch(SQLException e){System.err.println("Error-->"+e);}
}
public void init(ServletConfig c) throws ServletException {
super.init (c);
}
public void doGet( HttpServletRequest request,
HttpServletResponse response )
throws ServletException, IOException {
doPost(request, response);
}
public void doPost( HttpServletRequest request,
HttpServletResponse response )
throws ServletException, IOException {
response.setContentType("text/html");
PrintWriter out = response.getWriter();
out.println("<html>");
out.println("<body>");
out.println("<body bgcolor=\"white\">");
out.println("<h1>hello world servlet!</h1>");
String str=request.getParameter("param1");
out.println("The request parameter is --> "+str);
try{
stmt=con.createStatement();
rs=stmt.executeQuery("SELECT * FROM Employee");
while(rs.next()){
out.println(rs.getString(1));
}
}catch(SQLException e){
System.err.println("Error-->"+e);
}
out.println("</body>");
out.println("</html>");
}
}




Following is the Java application code:

import java.net.*;
import java.io.*;

public class HttpTunnel{
public static void main(String args[])throws Exception{
//connect
URL url = new URL("http://localhost/servlet/HelloServlet");

URLConnection conn = url.openConnection();
conn.setDoOutput(true);
conn.setUseCaches(false);



//Open output stream and send some data.
//OutputStream out = conn.getOutputStream();
//I am not going to send anything on "out," but you can fill this in.

ByteArrayOutputStream byteStream =new ByteArrayOutputStream(512);
PrintWriter out = new PrintWriter(byteStream, true);
String val1 = URLEncoder.encode("Sun Micro");
String data = "param1=" + val1;// +"¶m2=" + val2; // Note �&�
out.print(data); // Note print, not println
out.flush(); // Necessary since no println used

conn.setRequestProperty("Content-Length", String.valueOf(byteStream.size()));
conn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");

byteStream.writeTo(conn.getOutputStream());//send the real data

//out.flush();
//out.close();

//Open input stream and read the data back.
InputStream in = conn.getInputStream();
BufferedReader br=new BufferedReader(new InputStreamReader(in));
String str=br.readLine().trim();
while(str!=null){
System.out.println(str);
str=br.readLine().trim();
}
//Here you would read the data back.

br.close();

}
}


And this is the output that I get:
<html>
<body>
<body bgcolor="white">
<h1>hello world servlet!</h1>
The request parameter is --> Sun Micro
Scott
Michel
</body>
</html>
Exception in thread "main" java.lang.NullPointerException
at HttpTunnel.main(HttpTunnel.java:40)

Can somebody point out that what is causing the exceprion?

Regards,
Kunal Jaggi
15 years ago
Thanks Lasse and Jeanne, it was something very obvious that I missed.
On 24th Dec. 2002 I passed SCJP2 with a decent score of 89%. What are the job prospects after doing SCWCD here in India? I have just completed by B.IT from IGNOU. Why would one chose SCWCD(web
development) instead of Sun Certified Developer (software development). How much time does it take to prepare for SCWCD, I don’t have any prior knowledge of Servlets/JSP?
(1)
Please have a look at the following code snippet :
1: int i = 45678;
2: int j = ~i;
3:
4: System.out.println(j);
Select 1 correct answer:
A. Compilation error at line 2.
B. Prints 45677.
C. Prints -45677.
D. Prints -45679.

Is there any shortcut method to get at the answer ?
(2)
write(0x01234567) is called on an instance of OutputStream, what will be written to the destination of the stream.
Ans given is the byte 0x67 but how? I kno that only lower order 8 bits are written to the underlying sink.
Q 1
-----
public class MyRunner implemenrs Runnable{
int x=5;
public void run(){
this.x=10;
}
public static void main(String args[]){
MyRunner r=new MyRunner();
new Thread(r).start();
System.out.println(r.x)
}
}
Ans given : Output can't be determined
But in my openion the output should be 5, bcos after calling the start()
method the call returns to the parent thread. The start() is just to register
the Thread with the Thread Scheduler.
Q 2
-------
public class CloneTest{
public static void main(String args[])
{
int ia[][]={{1,2},null};
int ja[][]=(int[][])ia.clone();
System.out.print((ia==ja)+" ");
System.out.println(ia[0]==ja[0] && ia[1]==ja[1]);
}
}
Object class method
protected Object clone()throws CloneNotSupportedException
I don't understand, why is this compiling........
java.lang.CloneNotSuppertedException extends Exception
this makes it checked exception, checked exceptions must be either caught or
declared by the method in its header (throws clause).
Following is a quote from Khalid’s book :
“A subclass in another package can only access protected members in the
superclass via reference of its own type or a subtype.”
I have not understood this. The only thing I know about the protected access
specifier is that, members marked as protected are accessible even outside
the package, but only to subclasses, provided the class is accessible. Can anybody please explain this with the help of an example.
Please have a look at the following code snippets
(1)
int i= 22;
byte b=i;// compile time error, narrowing conversion, requires an
explicit cast //(byte) OK !!
(2)
final int i=22;
byte b=i;// compilation successful, bcos value of i is determinable
at compile time
// OK !!
(3)
final double d=7.9;
float f=d;//compilation error – same as 1
//hmmmmm…. still thinking
But look, d is final, if it works with integral data types then why it does
not work with floationg pt. data types.
This is for the first time that I am posting a query.
Following are two questions that I had come across in a mock exam, I don’t recollect the location of the exam.
Question 1
The programmer can signify through a reference that an object is no longer needed - True/False
My Answer
I think this statement is both true and false.
True part
If you want to tell the system that you done with the object, all you have to do is to remove all references to it like this:
myObj=null;
False part
I think the answer is false since an object can have more than one reference. Hence, one reference cannot always determine the fate of an object.
Question 2
Which is true about threads?
a. If suspended cannot be restarted
b. Stop running,if another thread with higher priority is getting runnable.
c. Stop running, if the thread starts another thread with the same priority.
d. Stop running, if the thread creates another thread.
e. If interrupted, stop running.
f. If dead cannot be restarted.
The answer given is b,c,e,f.
What about option (a), calling resume() (although depreciated) on a suspended thread wil put the same in Runnable state. Here if I am not mistaken “restarted” is not a call to start() method, but the Thread in Running state.
I am also quite keen to be a part of a SCJP group. I am putting up at Gurgaon, daily up and down is no problem for me.
My contact no.'s are
91-6563017
91-8952139
Address
C/O LT. COL. N.C. Jaggi
A 35/13 (F.F)
DLF Phase 1
GGN-122001
kunaljaggi@yahoo.com
[ October 12, 2002: Message edited by: Kunal Jaggi ]
[ October 12, 2002: Message edited by: Kunal Jaggi ]