Java Queries Here..

chandru.in

In the zone
If you have worked with multiple inheritance in C++, you'd know about ambiguities caused by allowing multiple inheritance when more than one base class have members with same name.

As you suggested, this can be prevented by ensuring all methods are abstract (which is what an interface does). Abstract classes by definition are allowed to have concrete methods and instance fields. Determining whether multiple inheritance is allowed on not only based on the fact that a class has all abstract methods and has only non instance variables will add to the complexity of the language and create more confusion.
 

ambika

learnhardy
Can someone simply explain the different platforms .......editions of java ??
What are the career path with each of them ??
 

chandru.in

In the zone
Can someone simply explain the different platforms .......editions of java ??
What are the career path with each of them ??
Java Micro Edition - Smallest and meant for devices with limited processing power.
Java Standard Edition - The core language and APIs. Used for desktop apps mainly.
Java Enterprise Edition - The largest of the three. Built on top of Java SE and filled with more Enterprise APIs for things like EJBs, JMS, etc.

There are rich career opportunities in all three of them.
 

ambika

learnhardy
Java Micro Edition - Smallest and meant for devices with limited processing power.
Java Standard Edition - The core language and APIs. Used for desktop apps mainly.
Java Enterprise Edition - The largest of the three. Built on top of Java SE and filled with more Enterprise APIs for things like EJBs, JMS, etc.

There are rich career opportunities in all three of them.

U had leaved one JCP??..........i know rich opportunities .....but i want simply some details .
 

chandru.in

In the zone
U had leaved one JCP??..........i know rich opportunities .....but i want simply some details .
Oh yeah, I had left out Java card. It is the smallest Java platform. Even smaller than Java ME.

Note: JCP as mentioned by Desi, is not to be confused with Java Community Process.

You can be desktop/enterprise/Mobile application developer. An application server admin. Admin of several other Java based middleware like message queues.
 

ambika

learnhardy
Oh yeah, I had left out Java card. It is the smallest Java platform. Even smaller than Java ME.

Note: JCP as mentioned by Desi, is not to be confused with Java Community Process.

You can be desktop/enterprise/Mobile application developer. An application server admin. Admin of several other Java based middleware like message queues.

Its nice if u asign me a link for that ............that gives details.
 

karamvir2008

Right off the assembly line
Hello man....
i m new to java....I want to upload an image along with other data like...
username,password ,email etc.....but when i click submit image gets uploaded but all other parameters are null.....and if i remove the image uploading option from the form...everything works fine....
i searched the net and found that jsp could not handle multipart requests nd we require some libraries for that....
jakarta commons...was one of them....i m so confused....did not understand a bit...
could u pls pls help me...
 

chandru.in

In the zone
i searched the net and found that jsp could not handle multipart requests nd we require some libraries for that....
JSP and Servlet can definitely handle multi-part request. But the catch is that writing code for parsing and using multi-part requests is tedious that it is better to get the job done with a library. Commons FileUpload is one such API. Commons FileUpload as a dependency needs Commons IO. Once you have both in your web-app's classpath, here is a sample code for uploading files using Commons FileUpload.

Main JSP
Code:
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"*www.w3.org/TR/html4/loose.dtd">

<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>Upload Page</title>
    </head>
    <body>
        <form action="UploadServlet" method="post" enctype="multipart/form-data">
            User Name:
            <input name="username" type="text" />
            <br>
            File to Upload: <input name="uploadFile" type="file"/>
            <br>
            <input type="submit" value="Submit" />
        </form>
    </body>
</html>
Upload Handling Servlet
Code:
package demo;

public class UploadServlet extends HttpServlet {

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        response.setContentType("text/plain");
        PrintWriter out = response.getWriter();
        try {
            FileItemFactory factory = new DiskFileItemFactory();
            FileUpload upload = new FileUpload(factory);
            List<FileItem> items = upload.parseRequest(new ServletRequestContext(request));
            for (FileItem item : items)
                if (item.isFormField())
                    System.out.println(item.getFieldName() + " " + item.getString());
                else {
                    File uploadedFile = new File("/home/chandru/demo.png");
                    item.write(uploadedFile);
                }

            RequestDispatcher dispatcher = request.getRequestDispatcher("result.jsp");
            dispatcher.forward(request, response);
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            out.close();
        }
    }
}
Note: Import Statements removed to keep code short. Add a simple result.jsp to show upload results.
 

sankha

Right off the assembly line
Thank you all for all such quality information. If I were to code a website where the database resides in another server, so can you just help me out for the inter-connectivity?








_________________________________
secure file deletion
 

Plasma_Snake

Indidiot
Just another n00by question from me.
Is it possible to create a non-static class containing main like this:
public static class A
{
---code--
class B
{
void main(String Args[])
--code here--
}
}
If it is possible then program would be saved by which class's name, A or B ?
 

chandru.in

In the zone
Just another n00by question from me.
Is it possible to create a non-static class containing main like this:
public static class A
{
---code--
class B
{
void main(String Args[])
--code here--
}
}
If it is possible then program would be saved by which class's name, A or B ?
An outer class cannot be declared static. Inner classes can be. Here, B is an inner class.

Compiler will generate two class files in this case. A.class and A$B.class. But why didn't you pull out the compiler and try this?
 

Plasma_Snake

Indidiot
One word, EXAMS! Have opted for J2ME, so will have to brush up my Core Java so watch out for a lot more stupid questions from me. ;)
 

karamvir2008

Right off the assembly line
hello sir..
i have this jsp page ...which i want to use for image upload of a user...
i wannt to post the user no as id here along with the image file to another page where it will be saved in DB and on the server as well..

<%@ page language="java" import="java.sql.*,java.util.*,java.io.*" %>
<html>
<body bgcolor="#FFFFFF" leftmargin="0" rightmargin="0" marginheight="0" marginwidth="0">
<jsp:include page="header.jsp" flush="true" />
<%
String n = request.getParameter("id");
//out.println(n);
%>
<table align="center" border="0">
<form action="insertuserpic.jsp" method="post" enctype="multipart/form-data">
<tr><th>Select your picture :</th></tr>
<tr><td><input type="file" name="image"></td></tr>
<tr><td><input type="submit" name="submit" value="upload"></td></tr>
<input type="hidden" name="id" value="<%= n %>">
</form>
</table>
</body>
</html>

now insertuserpic.jsp is here:

<%@ page
import="java.sql.*,java.util.*,java.io.*" %>

<%

String n=request.getParameter("id");
out.println(n);

String contentType = request.getContentType();

out.println("Content type is :: " +contentType);
if ((contentType != null) && (contentType.indexOf("multipart/form-data") >= 0)) {
DataInputStream in = new DataInputStream(request.getInputStream());
int formDataLength = request.getContentLength();
out.println("content length is"+formDataLength+"\n");

byte dataBytes[] = new byte[formDataLength];
out.println("databytes :"+dataBytes+"\n");

int byteRead = 0;
int totalBytesRead = 0;
while (totalBytesRead < formDataLength) {
byteRead = in.read(dataBytes, totalBytesRead, formDataLength);
totalBytesRead += byteRead;
}

String file = new String(dataBytes);
out.println("file : "+file);
String saveFile = file.substring(file.indexOf("filename=\"") + 10);
saveFile = saveFile.substring(0, saveFile.indexOf("\n"));
saveFile = saveFile.substring(saveFile.lastIndexOf("\\") + 1,saveFile.indexOf("\""));

//out.print(dataBytes);

int lastIndex = contentType.lastIndexOf("=");
String boundary = contentType.substring(lastIndex + 1,contentType.length());
//out.println(boundary);
int pos;
pos = file.indexOf("filename=\"");

pos = file.indexOf("\n", pos) + 1;

pos = file.indexOf("\n", pos) + 1;

pos = file.indexOf("\n", pos) + 1;


int boundaryLocation = file.indexOf(boundary, pos) - 4;
int startPos = ((file.substring(0, pos)).getBytes()).length;
int endPos = ((file.substring(0, boundaryLocation)).getBytes()).length;

FileOutputStream fileOut = new FileOutputStream("C:/Program Files/Apache Software Foundation/Tomcat 5.5/webapps/project/userpics/" + saveFile);


//fileOut.write(dataBytes);
fileOut.write(dataBytes, startPos, (endPos - startPos));
fileOut.flush();
fileOut.close();

out.println("File saved as " +saveFile);

}

file gets uploaded all well...but m not able to get the ID ...it comes null..
i have downloaded the com.oreilly.servlet.multipart library..
but i dont know how to use it..
could anyone just provide the exact code to get the id as well as the image...
i found the above code also on net....
can anyone help please...
 
Top Bottom