PDA

View Full Version : Java Queries Here..


rajkumar_pb
04-08-2008, 05:29 PM
I face a lot of issues while i m running java when i started to learn it... And i think the same issues will still alive.. If anyone find such kinda issue then please post it here instead of creating a new thread..

Yes this thread is dedicatedto Java(if u like J2EE toooo....:D)

So please drop ur queries here...

rajkumar_pb
09-08-2008, 12:03 PM
No Java Queries..:!:...Thats so bad...
Instead of starting a new thread for ur java doubts plz try 2 post here.. This will help for newcomers to search their queries in one stop place...:D

Plasma_Snake
14-08-2008, 08:54 PM
Check this code out:

import java.io.*;

public class FileOps {
public static void main(String args[])
{
File file = new File(args[0]);
try
{
BufferedReader in = new BufferedReader(new FileReader(file));
String s;
s = in.readLine();
while(s!=null)
{
System.out.println("Read " + s);
s = in.readLine();
}
in.close();
}
catch(FileNotFoundException e1)
{
System.err.println("File Not Found" + file);
}
catch(IOException e2)
{
e2.printStackTrace();
}
}
}

Now I'm getting this error "Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 0
at FileOps.main(FileOps.java:13)
Java Result: 1
"
What's the solution? :confused:

amit_at_stg
14-08-2008, 09:57 PM
Just run the programme by giving the input file name at the command prompt. Syntax java classname inputfilename . Remember that input file should exist in same directory and should preferably be a text file.

chandru.in
14-08-2008, 10:40 PM
Just run the programme by giving the input file name at the command prompt. Syntax java classname inputfilename . Remember that input file should exist in same directory and should preferably be a text file.
Just a small note. The file need not exist in the same directory from which the program is executed. In that case, the complete path (absolute path) of the files should be specified.

Bandu
14-08-2008, 10:54 PM
+1 for the above 2 comments. I think you are not using the command prompt to run your java prog. Seems that you've configured some tool - like EditPlus or such. In that case, make sure that you chose the option that allows you to input parameters (just like command line parameters) to the program being run ("Prompt for Arguments" option in Editplus).

And yes, the file need not be in the same directory, but if the file or directory contains spaces, do enclose the entire path/name in double quotes.

- Bandu.

Plasma_Snake
14-08-2008, 11:06 PM
I'm using Netbeans 6.1 and JDK 1.6

Bandu
14-08-2008, 11:18 PM
I've never used Netbeans. Lookup for some help online for you to allow Netbeans to provide you a dialog for input parameters when you run FileOps.

chandru.in
14-08-2008, 11:22 PM
Right click on your project in the Projects window and select properties.

Then select "Run" from the left and in the Arguments field type the absolute path to the file. Now whenever you run that will be passed to the program.

aniket.awati
18-08-2008, 02:58 PM
I am trying to use keylistener in java. Please expalain this error....


import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class sudoku1 extends Frame implements ActionListener,KeyListener {
int i,j;
int x,y;
Button b;
Graphics g;
sudoku1(String s)
{
super(s);
setTitle("Sudoku");
setSize(1000,700);
addKeyListener(this);
b=new Button("New Game");
setLayout(new BorderLayout());
b.addActionListener(this);
add(b,BorderLayout.SOUTH);
addWindowListener(new WindowAdapter(){public void windowClosing(WindowEvent e){System.exit(0);}});
setVisible(true);
g=getGraphics();
}
/*public void control(KeyEvent e)
{
if(e.getKeyCode()==VK_ENTER)
JOptionPane.showMessageDialog(null,"right");
}*/
public void keyPressed(KeyEvent e)
{
if(e.getKeyCode()==VK_RIGHT)
JOptionPane.showMessageDialog(null,"right");
}
public void keyReleased(KeyEvent e){}
public void keyTyped(KeyEvent e){}
public void draw()
{
g.setColor(Color.BLUE);
x=500;
y=350;
i=j=0;
while(i<10) //platform of the game is printed on screen.
{
g.drawLine(x-270+60*i,y-270,x-270+60*i,y+270);
g.drawLine(x-270,y-270+60*i,x+270,y-270+60*i);
if(i==3||i==6)
{
g.drawLine(x-270+60*i+2,y-270,x-270+60*i+2,y+270);
g.drawLine(x-270,y-270+60*i+2,x+270,y-270+60*i+2);
}
i++;
}

}
public void actionPerformed(ActionEvent e)
{
if(e.getSource()==b)
draw();
}
public static void main(String[] args) {
// TODO code application logic here
sudoku1 m=new sudoku1("Sudoku");

}

}


error is:

can't find symbol
symbol : variable VK_RIGHT

if(e.getKeyCode()==VK_RIGHT

Bandu
18-08-2008, 03:03 PM
There's an error in the code. Use KeyEvent.VK_RIGHT instead of VK_RIGHT. Change your if condition as follows:

if(e.getKeyCode()==KeyEvent.VK_RIGHT)

aniket.awati
18-08-2008, 03:11 PM
thanks that solved it.

Plasma_Snake
18-08-2008, 04:23 PM
this not a programming query but a simple JAVA related query. My friends have been asked lot of times during Viva and Placement interview that, Why the symbol of Java is cup of Coffee? AFAIK and tell 'em cause Java is also a name for a type of coffee and is also synonymous to Coffee in some countries that's why its Java and earlier Javabeans(now Netbeans). If I'm wrong then please do correct me. http://s269.photobucket.com/albums/jj44/visio159/Unismilies/102.png

Bandu
18-08-2008, 04:52 PM
Me too thinks the same.

I've heard of a couple of theories:
(1) James Gosling thought of it while having a cup of coffee.
(2) They had earlier thought of the name (and possibly the symbol) Oak, but that had some copyright issues. They then hired a consultant who interviewed the team and came up with a list of names (Silk, Java, etc.). Java was chosen as it sounds refreshing.
(3) And this, to me seems the most reasonable answer to your question:

"The letters spell out the names of the three key developers: James Gosling, Arthur Van Hoff and Andy Bechtolsheim."

gary4gar
23-08-2008, 10:03 PM
any Good IDE for java?

Bandu
23-08-2008, 10:04 PM
Get IntelliJ IDEA if you / your company can affort it. Its the best one out there.
Eclipse is one of the freely available ones and is quite good too.

- Bandu.

Garbage
23-08-2008, 10:21 PM
any Good IDE for java?
NetBeans (http://www.netbeans.org/) - The only IDE you need !

mehulved
23-08-2008, 10:25 PM
geany

gary4gar
23-08-2008, 11:00 PM
geany
Oh yeah...i forgot that geany is not only for C/C++ but for java too, thanks for reminding me

NetBeans (http://www.netbeans.org/) - The only IDE you need !
Its good for large scale projects, else i am better off with Eclipse or geany

aniruddhc
26-08-2008, 08:18 PM
Well could you guys WAP in java to print the following pattern?? (Just give the base logic using the for loop)

*
**
***
****
***
**
*

the pattern is in the center with 1 star, next line two stars then next line 3 stars ..... 4 stars then decreasing to 1 star...

thanks

Bandu
26-08-2008, 08:28 PM
^^ I hope thats not a school assignment.

Anyways, the logic is pretty simple.
(1) Have an outer loop iterate thru 0 to 4. End it with System.out.println().
(2) Have an inner loop iterate through 0 till i and print a single *.

The above steps will give you the first part of the pattern. Reverse the logic to get the lower half.

- Bandu.
P.S. There are other ways to do this and there might be more simpler ways as well.

for(int i = 0; i < 4; i++, System.out.println())
for(int j = 0; j <= i; j++)
System.out.print("*");


Edit: The thread subscription email that I received has a different pattern. If it is the exact opposite of whats seen in the thread, then u'll have to slightly modify the loop structures:
for(int i = 0; i < 4; i++, System.out.println())
{
for(int j = 4; j > i; j--)
System.out.print(" ");
for(int k = 0; k <= i; k++)
System.out.print("*");
}

rajkumar_pb
27-08-2008, 10:56 AM
^^ I hope thats not a school assignment.

Anyways, the logic is pretty simple.
(1) Have an outer loop iterate thru 0 to 4. End it with System.out.println().
(2) Have an inner loop iterate through 0 till i and print a single *.

The above steps will give you the first part of the pattern. Reverse the logic to get the lower half.

- Bandu.
P.S. There are other ways to do this and there might be more simpler ways as well.

for(int i = 0; i < 4; i++, System.out.println())
for(int j = 0; j <= i; j++)
System.out.print("*");
Edit: The thread subscription email that I received has a different pattern. If it is the exact opposite of whats seen in the thread, then u'll have to slightly modify the loop structures:
for(int i = 0; i < 4; i++, System.out.println())
{
for(int j = 4; j > i; j--)
System.out.print(" ");
for(int k = 0; k <= i; k++)
System.out.print("*");
}

He just ask the logic, but u provide him the code.... :rolleyes:

Bandu
27-08-2008, 01:55 PM
He just ask the logic, but u provide him the code.... :rolleyes:
I kinda disappointed Aniruddh the last time with his Electronic showroom thing, and he's really at a very early stage of learning, so I thought it might help him better this way than exchaning multitude of PM's and emails for a trivial thing as this.

- Bandu.

aniruddhc
02-09-2008, 01:05 AM
Bandu I need to make the pattern in a diamond shape... The digit forum fsoftware doesnt allow me to post it in a diamond way

i think i need 6 loops, but i am not sure...

your logic unfortunately does not work...

Bandu
02-09-2008, 01:42 PM
@Aniruddh, post your required output enclosed in [ CODE] [/ CODE].

your logic unfortunately does not work...
http://i38.tinypic.com/33l2q81.jpg

Desi-Tek.com
06-09-2008, 11:22 AM
how to use java persistence api in core java?

chandru.in
06-09-2008, 01:08 PM
^^ See here.

http://en.wikibooks.org/wiki/Java_Persistence/Runtime#Java_Standard_Edition

Desi-Tek.com
06-09-2008, 04:10 PM
^^ See here.

http://en.wikibooks.org/wiki/Java_Persistence/Runtime#Java_Standard_Edition

that example is for ejb which require application server but i want to use jpa in core java application.

chandru.in
06-09-2008, 05:12 PM
See the section titled "Java Standard Edition".

It does work without Java EE server.

Desi-Tek.com
06-09-2008, 11:12 PM
but how to use it with core java? do u have any example?

chandru.in
06-09-2008, 11:14 PM
Core Java == Java SE.

I feel the code snippet there is good enough (if you have already worked with JPA in Java EE apps).

Desi-Tek.com
07-09-2008, 04:05 PM
i think i found the solution EntityManager can only be injected in ejb
http://saloon.javaranch.com/cgi-bin/ubb/ultimatebb.cgi?ubb=get_topic&f=78&t=003857

i'll try with spring

chandru.in
07-09-2008, 04:18 PM
As the URL I provided clearly says, it is not injected but rather should be created by code.
EntityManagerFactory factory = Persistence.createEntityManagerFactory("acme");
EntityManager entityManager = factory.createEntityManager();
...
entityManager.close();

Desi-Tek.com
07-09-2008, 08:35 PM
ah it worked thanks


package com.ocricket.entity;


import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;
import javax.persistence.Query;

import org.apache.log4j.Logger;

/**
*
*/
public class EntityManagerUtil {

private static final EntityManagerFactory emf;
private static final ThreadLocal<EntityManager> threadLocal;
Logger log = Logger.getLogger(EntityManagerUtil.class);


static {
emf = Persistence.createEntityManagerFactory("OCRICKETPU");
threadLocal = new ThreadLocal<EntityManager>();

}

public static EntityManager getEntityManager() {
EntityManager manager = threadLocal.get();
if (manager == null || !manager.isOpen()) {
manager = emf.createEntityManager();
threadLocal.set(manager);
}
return manager;
}

public static void closeEntityManager() {
EntityManager em = threadLocal.get();
threadLocal.set(null);
if (em != null) em.close();
}

public static void beginTransaction() {
getEntityManager().getTransaction().begin();
}

public static void commit() {
getEntityManager().getTransaction().commit();
}

public static void rollback() {
getEntityManager().getTransaction().rollback();
}

public static Query createQuery(String query) {
return getEntityManager().createQuery(query);
}



}




<?xml version="1.0" encoding="UTF-8"?>
<persistence xmlns="http://java.sun.com/xml/ns/persistence"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence
http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd"
version="1.0">

<persistence-unit name="OCRICKETPU"
transaction-type="RESOURCE_LOCAL">
<provider>org.hibernate.ejb.HibernatePersistence</provider>

<properties>
<property name="hibernate.connection.driver_class"
value="org.postgresql.Driver" />
<property name="hibernate.connection.url"
value="jdbc:postgresql://localhost:5432/ocricket" />
<property name="hibernate.connection.username"
value="postgres" />
<property name="hibernate.connection.password"
value="000000" />
<property name="databasePlatform"
value="org.hibernate.dialect.PostgreSQLDialect" />
<property name="hibernate.use_sql_comments" value="true" />
<property name="hibernate.hbm2ddl.auto" value="create" />


</properties>
</persistence-unit>

</persistence>

chandru.in
07-09-2008, 11:09 PM
You are welcome. :)

Java rocks!! :D

dashang
13-09-2008, 10:06 AM
I am looking for code to create login java program in which user enter pass if its correct run remaining program else terminate/ Help me guys. I am having problem with whowing '*' as display how to do it???

chandru.in
13-09-2008, 10:59 AM
You have not mentioned the type of app you are creating. So I'm suggesting for both desktop and web apps.

Desktop App:

Use the JPasswordField swing component.

Normal Web App:

Use <input type="password" />

JSF Web App:

Use <h:inputSecret />

dashang
13-09-2008, 01:16 PM
Hey chandru can you give of full code from importing classes till end. Just give me password match code that is code for " getting pass and matching it and showing stars in pass while writing(optional)

Desi-Tek.com
17-09-2008, 12:06 PM
do u want it for web application?

or desktop application?

chandru.in
17-09-2008, 01:10 PM
Hey chandru can you give of full code from importing classes till end. Just give me password match code that is code for " getting pass and matching it and showing stars in pass while writing(optional)
Going through the TLD docs and Java docs of the class and Tag I provided you should clarify everything for you.

T159
19-09-2008, 03:35 PM
just a simple query.

How do I send a swing application to end user which will require him to just double click and start it.

I have created a jar file but then I need a bat file to start it. Ok its fine but there also starts a command prompt in background which is a turn off for me.

GOT THE ANSWER :)

Use javaw instead of java

mastermunj
19-09-2008, 03:48 PM
try executing your jar file with following command:

start javaw -jar myapp.jar

Though, command prompt will appear for a second, then it will disappear..

Or you can create a shortcut to javaw.exe and give above parameters to it, this probably won't even show you the command prompt for a second also.. but i am not sure if this will really work.. You can try it out and let us all know about its result..

T159
19-09-2008, 03:50 PM
^^yup, thanks.

Btw is there any way to start the application by just clicking on jar file ?

mastermunj
19-09-2008, 03:59 PM
For that you can change the file type details in windows and make it open with javaw by default..

For more details see this (http://mindprod.com/jgloss/executablejar.html)

chandru.in
19-09-2008, 03:59 PM
For Windows

You can use this utility (http://launch4j.sourceforge.net/) to create an executable wrapper around your JAR.

For Linux

Unlike Windows, a simple shell script will do the trick for Linux as it won't open a terminal window unless user chooses to.

Just in case you'd like a platform independent splash screen for your desktop App you can add following line to your Jar's manifest.

Splashscreen-Image: <image_path_relative_to_JAR>

T159
19-09-2008, 04:13 PM
^^Hey,thanks
let me check it out, btw I have made the app in linux but the client and the company will use in windows.

ray|raven
19-09-2008, 04:25 PM
^ Or you could use the SplashScreen class , to display one.

More here : http://java.sun.com/docs/books/tutorial/uiswing/misc/splashscreen.html

T159
19-09-2008, 04:44 PM
^^its cool but for first iteration am wrapping it in exe (which is in priority 1 condition) and then for next iteration all graphical enhancements are slated to work upon.

One more thing:

I just logged in to XP and found that the jar created is an executable, that means I can run it by double clicking..lolz

Can someone explain me why does it working now on double clickin.

All I did yesterday was

jar cvmf manifest.stab appname.jar .

So is it wise to use it like this or make an exe too, which is a bit large in size compared to jar.

chandru.in
19-09-2008, 05:48 PM
^ Or you could use the SplashScreen class , to display one.

More here : http://java.sun.com/docs/books/tutorial/uiswing/misc/splashscreen.html

Splashscreen class cannot be used to create a splash screen as such. You can use it to manipulate the splash screen only if one already exists (either given in commandline or in JAR's manifest).



One more thing:

I just logged in to XP and found that the jar created is an executable, that means I can run it by double clicking..lolz

Can someone explain me why does it working now on double clickin.

All I did yesterday was



So is it wise to use it like this or make an exe too, which is a bit large in size compared to jar.

It always works upon double-click if the .jar files are associated with "java -jar" or "javaw -jar" commands. The Windows version of JRE installer does the association automatically. On Linux (I tried on Ubuntu), this is done if you install JRE from the repos.

Using the EXE wrapper allows for more customizations to blend with the Windows environment (like creating an icon for your app's executable). It also allows you to bundle a JRE so that your app will work even if the user does not have a JRE pre-installed and .jar associations performed. If you don't bundle JRE, it can also check whether right JRE version is installed and if not will automatically open the JRE download URL. Simple JAR association gives a very unfriendly message to user in such cases.

T159
19-09-2008, 05:58 PM
K so I will make exe just in case the system on which it is used is the most obsolete one to support anything :p

Thanks for all the info.

T159
25-09-2008, 07:28 PM
One more query guys !

How do I catch memory leaks in my program. Any thing to watch and correct it.

chandru.in
26-09-2008, 12:00 PM
Memory leaks in Java programs are very rare. It can happen only if you code very badly.

Using appropriate scoping for variables and adhering to basic OOP is all that is needed. The rest will be taken care of by GC. :)

parthbarot
26-09-2008, 06:44 PM
no mate... for memoery u have to be carful..i mean..u should take care of things which can cause leaks and heap explodes :).

and yah,many have asked abt best IDE for java... so i m suggesting u..

as a professional java prog., u can use Eclipse or IntelliJ Idea..but idea is paid on (abt $500 :D) and eclipse is open source.. so most of corporates are using eclipse.

REGARDS.

T159
26-09-2008, 07:01 PM
yeah i know GC does work automatically.

But any way to check the heap and stack for running program. I mean a graphical stat type view.

chandru.in
26-09-2008, 07:15 PM
Starting with Java 6 update 7, Visual VM is built right into JDK. It is a really good tool for monitoring your JVM instances. Visual VM can be downloaded separately for Any version of Java 6 from here (https://visualvm.dev.java.net/download.html).

Apache's JMeter (http://jakarta.apache.org/jmeter/) is a highly advanced monitoring tool too.

T159
26-09-2008, 07:26 PM
I'm on linux (Arch Linux). This is the output of java -version
java version "1.6.0_07"
Java(TM) SE Runtime Environment (build 1.6.0_07-b06)
Java HotSpot(TM) Client VM (build 10.0-b23, mixed mode, sharing)

So how do I start visual VM ?

chandru.in
26-09-2008, 07:44 PM
Just type visualvm on your terminal and rock on!

For further references, read https://visualvm.dev.java.net/gettingstarted.html

T159
26-09-2008, 08:15 PM
Thanks buddy, I owe you :D

But the exact command is jvisualvm.

Thanks you for all your help :)

http://i269.photobucket.com/albums/jj44/visio159/Screenshot-JavaVisualVM.png

chandru.in
26-09-2008, 08:22 PM
Oops! Missed the 'J'. :D

no mate... for memoery u have to be carful..i mean..u should take care of things which can cause leaks and heap explodes :).
If all references are well scoped and proper OO principles are followed, there is no need to worry about memory management (both stack and heap). If you still feel there can be need to worrying about memory, pls give me a sample program scenarios following proper OOP principles, which can lead to OutOfMemoryError.

parthbarot
27-09-2008, 10:34 AM
thats wht i meant yaar...that u have to take care of references and conections like resources.. which can create probs :)

regards.

Pathik
18-10-2008, 02:07 PM
Is there any API I can use to create apps that use Bluetooth on PCs? I am not talking of the Java ME JSR 82 API. I need something which I can use with a bluetooth dongle. Thanks.

rajkumar_pb
18-10-2008, 02:21 PM
Is there any API I can use to create apps that use Bluetooth on PCs? I am not talking of the Java ME JSR 82 API. I need something which I can use with a bluetooth dongle. Thanks.

AFAIK There is no such API to create apps for bluetooth except the J2ME API u mentioned.... (Correct me if i am wrong...)

chandru.in
18-10-2008, 02:38 PM
There are implementations of JSR-82 for Java SE. Have a look at bluecove project http://code.google.com/p/bluecove/

Note: bluecove does not pass the TCK for JSR-82 due to deficiencies in WIDCOMM stack. http://www.bluecove.org/tck/

If you are interested in commercial APIs, http://www.javabluetooth.com/development_kits.html

Plasma_Snake
01-11-2008, 10:27 PM
Does SUN provides detailed help files for JAVA like MSDN? Where? Please
I don't have detailed Java knowledge, just ur ordinary n00b but I want to try my hand at Game programming in Java and got e-book "Killer Java Game Programming" I'm just on its second chapter and my head is already cartwheeling and flipping. :-?
I want to know what tools I need exactly. I've following installed:


Netbeans 6.1 (full 219MB one)
Java3d-1_5_1
Java_ee_sdk-5_05
Jdk-6u7-windows-i586-p

What more do I need? I type just following lines and get the following error:
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.text.DecimalFormat;

import com.sun.j3d.utils.timer.J3DTimer;

In the last Import statement I get the following error "package com.sun.j3d.utils.timer does not exists"
This code I'm trying to compile and run is given as verified runnable as given and mentioned by author of the book. I'm just trying to code it again for the sake of my understanding. Please tell me whats wrong and help me please. :cry:

Bandu
01-11-2008, 10:36 PM
I am not sure how MSDN help looks like. I've this page bookmared for Java: http://java.sun.com/j2se/1.4.2/docs/api/ (http://java.sun.com/j2se/1.4.2/docs/api/)

As far as your installation goes, I think you have pretty much everything you need. For beginners, however, I still recommend starting out the harder way - using simple tools like Editplus and such so that you get a complete understanding of how things work in Java - classpaths, etc. Using IDEs (like Netbeans) make the whole thing transparent to the developer. It's important to get an understanding of such things. It would help if you start out with simpler programs before jumping into advanced topics like awt, swing, etc.

For the error, make sure that you have your classpath set correctly. You probably are missing a jar file or two in the classpath. I am not sure which, but should be some j3d.jar or some 3d.jar file. Try looking for such a file somewhere in your installations and if you find it, append its path to the CLASSPATH variable.

- Bandu.

chandru.in
02-11-2008, 12:26 AM
I'd echo Bandhu but with a link for more recent Java release ;) http://java.sun.com/javase/6/docs/api/

Regarding cartwheeling and flipping, that's what is bound to happen when you try to ride a Ducati at full throttle when you haven't yet learnt to balance a two-wheeler. :p

Put aside the book you have and get "Head First Java". Once you are crystal clear with the basics of Java programming, come back to your current book. Good luck with your adventures in Java.

Plasma_Snake
02-11-2008, 01:29 AM
Well if u see earlier posts in this thread, I've done Java in my college in 5th Semester and 3 times in my local NIIT center so basic topics like Array, Inheritence, Overloading and Overidding are clear to me but things like Swings and Threads are what that need more practice and I seriously need to learn Java I/O ops and classes 'cause I personally feel that without it Java learning is useless.

chandru.in
02-11-2008, 01:46 PM
I didn't mean to be rude with the ducati example. I'm sorry if you had felt so.

Multi-threading is an absolute must for any Java programming. JVM,s extraordinary concurrency capabilities is what makes it such a valuable platform on servers. Concurrency is also mandatory for game programming. So, I'd suggest that you focus on Threading and it subtleties before going into full-fledged game programming.

Plasma_Snake
02-11-2008, 02:27 PM
I wasn't offended at all, I was just giving my history with Java so as to let u know my level of Java understanding. I PMed the mods and look, the Thread now is Sticky :)
Now the question part, as mentioned by me in my earlier post I've Java 3D installer and installed it too. Now please tell me how can I use the packages and classes of this Java3D in my Netbeans or programs that I create i.e. incorporating it in Java SDK? :confused:
if I'm not wrong, the error that I was getting in one of my earlier posted problem was mainly because Netbeans wasn't able to find the mentioned package of Java 3D in its libraries or am I still missing the point? :-?

rajkumar_pb
03-11-2008, 11:40 AM
@Plasma_Snake:
Netbeans wasn't able to detect Java 3D.... And AFA Swing and related stuffs, go thru some books like Swing Cook books and etc to get good knowledge on it.... Swings are not so tough as Java basics and once you get good knowledge in basics then swings is nothing to learn, except the API... And I/O, better learn from Head first and try some online tutorial...
Best way is try some examples urself and if u have any doubt post it here...

T159
05-11-2008, 01:50 PM
here is one query;

Suppose I have scanned an image and want to know its lenght and breadth. Will it be possible to get the original length and breadth irrespective of the dpi at which its scanned.

I'm able to get the resolution of an image.

Guide me...if there is some way.

Desi-Tek.com
09-11-2008, 12:20 AM
youtube's comment system is now powered by java (servlet)!

http://in.youtube.com/comment_servlet?all_comments&v=GvctSMHHd7g&ytsession=p9A_Dz6f8kXK5uX7c4IxRXCHB9HQut1nIGY5pSuq gGeeKrFz1pYtma0JOAMlINEJELSf9R85VAbMqGZhLjBDGw-Jg8LGV1e2C3ZTLwiHnz5f7eHpk5aIrfFVkmJksyn4pw4ur6twt 4OoW7N8aRmBD58Ft-kefWBBDA3BsU4PJ7IrnfR5Jd-HXVRcOI_fnGg1GAXU8k0OCbr-I024_h6l0AL3TaaGGAFdED_egjgErjDuWe3e_-R89fqmuZ8a8-hn-wnsNIl-O5BqZT26bLzr1wCK2f4V76Z_dO7xfKe7BQQ

T159
09-11-2008, 12:23 AM
mfg, good to know !

Desi-Tek.com
13-11-2008, 11:07 PM
how to read value from custom annotation?
for example if i have cuustom annotation
@Permission(name="ADMIN")

how can i read the value admin during run timer?

Bandu
14-11-2008, 12:12 AM
^Thanks to you, I learnt something new in Java 1.5 today. But, unfortunately not enough to answer your question. You might want to look into com.sun.javadoc, JSR-269 (Pluggable Annotation Processing API), and the new 1.5 reflection API.

If you do find an answer, please post a small example and solution if possible.

chandru.in
14-11-2008, 10:01 AM
@Desi

If Permission is a custom annotation defined by you, set its retention policy to RUNTIME. Here is a complete sample code.

package demo;

import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;

@Retention(RetentionPolicy.RUNTIME)
public @interface Permission {
String name();
}


package demo;

public class Main {
public static void main(String[] args) {
Demo demo = new Demo();
Permission permission = demo.getClass().getAnnotation(Permission.class);
System.out.println(permission.name());
}
}

@Permission(name = "ADMIN")
class Demo {

}

Desi-Tek.com
14-11-2008, 10:45 PM
@ chandru.in thanks a lot that is a very useful example

Desi-Tek.com
16-11-2008, 06:27 PM
hi is it possible to separate model from jsf's managed bean? in struts 2 we use ModelDriven interface to achieve that.

Struts example

Model

/**
* User Model
**/
public class User {


private String username;
private String password;
private int age;
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
} Struts 2 acton




/**
* Action
**/
public class Login extends ActionSupport implements ModelDriven<User>{


private User user;

public User getModel() {

return user;
}

public User getUser() {
return user;
}

public void setUser(User user) {
this.user = user;
}

// Acton

public String login (){
return "outcome";

}


}

mapping

<package name="user" extends="struts-default">
<action name="login"
class="com.desitek.cricket.action.Login">
<result name="input">index.jsp</result>
<result name="success">index.jsp</result>
<result>index.jsp</result>
</action>
</package>

and jsp

<s:actionerror/> <s:actionmessage/>
<s:fielderror></s:fielderror>

<s:form action="login" theme="simple">
User Name
<s:textfield name="user.Username"></s:textfield>
Password: <s:textfield name="user.UserPassword"></s:textfield>
<s:submit value="login"></s:submit>
</s:form>

chandru.in
17-11-2008, 09:02 AM
The same can be done in JSF too. However, unlike Struts JSF doesn't make you implement any interface. I guess your mapping is out of sync with your code. So my example may not exactly reflect your requirements.

For JSF, this is how your Login class would look.
public class LoginAction {


private User user;

public User getModel() {

return user;
}

public User getUser() {
return user;
}

public void setUser(User user) {
this.user = user;
}

public String login (){
return "outcome";
}
}

Managed bean and Navigation rule

<managed-bean>
<managed-bean-name>login</managed-bean-name>
<managed-bean-class>com.desitek.cricket.action.LoginAction</managed-bean-class>
<managed-bean-scope>request</managed-bean-scope>
</managed-bean>

<navigation-rule>
<from-view-id>login.jsp</from-view-id>
<navigation-case>
<from-outcome>success</from-outcome>
<to-view-id>index.jsp</to-view-id>
</navigation-case>
<navigation-case>
<from-outcome>failure</from-outcome>
<to-view-id>login.jsp</to-view-id>
</navigation-case>
</navigation-rule>

Desi-Tek.com
17-11-2008, 02:52 PM
i tried that but it is giving this error when i submitted the form


javax.servlet.ServletException: /login.jsp(35,2) '#{user.user.username}' Target Unreachable, 'user' returned null
javax.faces.webapp.FacesServlet.service(FacesServl et.java:256)
root cause
org.apache.jasper.el.JspPropertyNotFoundException: /login.jsp(35,2) '#{user.user.username}' Target Unreachable, 'user' returned null
org.apache.jasper.el.JspValueExpression.getType(Js pValueExpression.java:61)
com.sun.faces.renderkit.html_basic.HtmlBasicInputR enderer.getConvertedValue(HtmlBasicInputRenderer.j ava:81)
javax.faces.component.UIInput.getConvertedValue(UI Input.java:934)
javax.faces.component.UIInput.validate(UIInput.jav a:860)
javax.faces.component.UIInput.executeValidate(UIIn put.java:1065)
javax.faces.component.UIInput.processValidators(UI Input.java:666)
javax.faces.component.UIForm.processValidators(UIF orm.java:229)
javax.faces.component.UIComponentBase.processValid ators(UIComponentBase.java:1030)
javax.faces.component.UIViewRoot.processValidators (UIViewRoot.java:662)
com.sun.faces.lifecycle.ProcessValidationsPhase.ex ecute(ProcessValidationsPhase.java:100)
com.sun.faces.lifecycle.LifecycleImpl.phase(Lifecy cleImpl.java:251)
com.sun.faces.lifecycle.LifecycleImpl.execute(Life cycleImpl.java:117)
javax.faces.webapp.FacesServlet.service(FacesServl et.java:244)

here is my model


package com.desitek.cricket.action;

/**
* Action
**/
public class User {


private String username;
private String password;
private String email;


public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
}


package com.desitek.cricket.action;

public class LoginAction {

private User user;

public User getUser() {
return user;
}

public void setUser(User user) {
this.user = user;
}

public String login() {
System.out.println(user.getUsername());
return "success";
}
}

login.jsp

<f:view>
This is my JSF JSP page. <br>
<h:form>
Username
<h:inputText value="#{user.user.username}"></h:inputText>
Password
<h:inputText value="#{user.user.password}"></h:inputText>
<h:commandButton action="#{user.login}" value="submit" ></h:commandButton>

</h:form>
</f:view>


<managed-bean>
<managed-bean-name>user</managed-bean-name>
<managed-bean-class>com.desitek.cricket.action.LoginAction</managed-bean-class>
<managed-bean-scope>request</managed-bean-scope>
</managed-bean>

<navigation-rule>
<from-view-id>login.jsp</from-view-id>
<navigation-case>
<from-outcome>success</from-outcome>
<to-view-id>index.jsp</to-view-id>
</navigation-case>
<navigation-case>
<from-outcome>failure</from-outcome>
<to-view-id>login.jsp</to-view-id>
</navigation-case>
</navigation-rule>

chandru.in
17-11-2008, 03:40 PM
Have you set the value of user within LoginAction class?

Desi-Tek.com
17-11-2008, 04:01 PM
finally i fixed the problem by creating new instance of user in properties

package com.desitek.cricket.action;

public class LoginAction {

private User user = new User();

public User getUser() {
return user;
}

public void setUser(User user) {
this.user = user;
}

public String login() {
System.out.println(user.getUsername());
return "success";
}
}

chandru.in
17-11-2008, 04:47 PM
Exactly that's what I meant. :)

Plasma_Snake
18-11-2008, 07:44 PM
OK, guys here r 2 very n00bish questions from me so answer 'em like Experts ;) :D
1.Can we create or instantiate Object of a class, in a class other than main? I mean is this possible?
class A { some code}
class B {some code A a = new A}
class C{
p s v main
{some code}
}
2. can we make a Static Array?
Hope u r able to understand the questions. :neutral:

Bandu
18-11-2008, 07:57 PM
1. Yes. Thats what most of the times classes are for - instantiation, unless they are private in some other package or have private constructors. You need to see topics regarding class visibility - public, default, package, etc.

2. Yes, you can. What made you think you cannot.

Example for #1:
http://img48.imageshack.us/img48/5640/plasmacr2.th.png (http://img48.imageshack.us/my.php?image=plasmacr2.png)http://img48.imageshack.us/images/thpix.gif (http://g.imageshack.us/thpix.php)

Example for #2:
http://img171.imageshack.us/img171/2609/plasmasnakewh0.th.png (http://img171.imageshack.us/my.php?image=plasmasnakewh0.png)http://img171.imageshack.us/images/thpix.gif (http://g.imageshack.us/thpix.php)

Plasma_Snake
19-11-2008, 02:34 AM
Thanx for the screenshots, cleared the doubt like Harpic cleans the $hit from the flush. :D
In the first example u've created the object of A in constructor of B. Is it the only way or it can be done another way also? :idea:

thewisecrab
19-11-2008, 02:38 AM
OK, this is really n00bish compared to your standards, but still:
can anyone explain the "while","do while" functions (ie.loop) with an example? e-books arent helping here :|

QwertyManiac
19-11-2008, 03:49 AM
Thanx for the screenshots, cleared the doubt like Harpic cleans the $hit from the flush. :D
In the first example u've created the object of A in constructor of B. Is it the only way or it can be done another way also? :idea:
An object can be created anywhere, anytime from a class as long as its scope allows it to be. Have you not learnt OO concepts at school yet?

Bandu
19-11-2008, 07:51 PM
In the first example u've created the object of A in constructor of B. Is it the only way or it can be done another way also? :idea:

I used the constructor for the example. You can create it anywhere. Constructor is just another method + something more, which isn't the topic at the moment, so I'll refrain from writing about constructors.

OK, this is really n00bish compared to your standards, but still:
can anyone explain the "while","do while" functions (ie.loop) with an example? e-books arent helping here :|


I won't call it n00bish. Can be quite confusing even for seasoned programmers.


http://img210.imageshack.us/img210/8887/twcrh5.th.png (http://img210.imageshack.us/my.php?image=twcrh5.png)http://img210.imageshack.us/images/thpix.gif (http://g.imageshack.us/thpix.php)


while(i < 2)
{
...
}

System.out.println("\nTesting the exit controlled loop\n");
int j = 0;
do
{
...
} while (j == 100);
}
}
while loop is also called as "entry controlled" loop. With this, the code statements within the loop body are executed only if the boolean condition evaluates to true and this evaluation is carried out before entering the loop. Thats why entry controlled. The boolean condition is evaluated first before entering the loop body. Example is the green one in the above snippet.

do...while is also called as "exit controlled" loop. With this, the code statements are executed first. The control does enter the loop body and executes the statements within. At the end lies the boolean condition. Red one in the above code. If this condition evaluates to true, control loops back to the first statement in the loop body and so on... until the condition evaluates to false.

Its difficult to give an example... *searches_for_do_while_in_code* :)

Found...

I had a situation where I had to parse a line from a csv (comma separated values) file and process each part. Lets say, print each part of the token.

An example string: think,digit,rocks
Another example: digit

Both are valid csv examples. You can type in these lines in a file, save it as a .csv and open it in excel. It will work. Each token that is separated by a comma goes into a XL cell:

http://img513.imageshack.us/img513/4739/csvvn0.th.png (http://img513.imageshack.us/my.php?image=csvvn0.png)http://img513.imageshack.us/images/thpix.gif (http://g.imageshack.us/thpix.php)

Anyways, back to the example.

The solution would be - no matter if a comma exists or not, we have to process the input - irrespective of the boolean condition (of having a comma in the string).

Note: The italicized words above is the boolean condition, and the underlined words form the loop body.

http://img155.imageshack.us/img155/7893/twccsvparsefx9.th.png (http://img155.imageshack.us/my.php?image=twccsvparsefx9.png)http://img155.imageshack.us/images/thpix.gif (http://g.imageshack.us/thpix.php)
P.S. Refer Chandru's comment below. Do not use this as an example for CSV parsing. It's written to be an example for exit controlled loop. CSV parsing can be achieved more simply using Chandru's suggestion below.

chandru.in
19-11-2008, 09:08 PM
[OFF TOPIC]

That CSV line can parsed easily using String.split(",") method.

thewisecrab
19-11-2008, 09:13 PM
I won't call it n00bish. Can be quite confusing even for seasoned programmer......................is the boolean condition, and the underlined words form the loop body.

http://img155.imageshack.us/images/thpix.gif (http://g.imageshack.us/thpix.php)
Thanks man. Really great explanation (although it took some time to understand use of words such as "boolean" etc. as they are not used commonly [I know what boolean means :p] )
In the end, problem solved :)
You'll here more simple questions from me in future :D

Plasma_Snake
19-11-2008, 09:15 PM
I was just comparing C# with JAVA and few of these questions just popped up in my mind so asked. :)
@QwertyM
If u r questioning my programming knowledge then I can tell u this that I've done Java 4 times in past 1 year but still ain't fully clear to me as possibilities are limitless in these Purely OOP languages. This thread is for asking questions, isn't it?

Bandu
19-11-2008, 09:20 PM
[OFF TOPIC]

That CSV line can parsed easily using String.split(",") method.

Yes, I know that. Good that you mentioned so that anyone coming to this thread does not take it as an example for csv parsing (infact I've edited my original post to mention this). But in my case, that was a legacy code. Moreover, I just modded it and simplified it to serve as an example here. The actual code has lots of other things that a String.split would not have served anyways.

chandru.in
19-11-2008, 09:38 PM
Yes, I know that. Good that you mentioned so that anyone coming to this thread does not take it as an example for csv parsing (infact I've edited my original post to mention this). But in my case, that was a legacy code. Moreover, I just modded it and simplified it to serve as an example here. The actual code has lots of other things that a String.split would not have served anyways.
I never meant to undermine your reply. :)

Bandu
19-11-2008, 09:43 PM
^^ Nopes. I did not say so either. What made you think that way? In fact, I appreciate you bringing it up.

chandru.in
19-11-2008, 09:46 PM
^^ Nopes. I did not say so either. What made you think that way? In fact, I appreciate you bringing it up.
Chill never mind. Let's stick to our cup of Java. :D

QwertyManiac
20-11-2008, 05:14 PM
@QwertyM
If u r questioning my programming knowledge then I can tell u this that I've done Java 4 times in past 1 year but still ain't fully clear to me as possibilities are limitless in these Purely OOP languages. This thread is for asking questions, isn't it?
No, its just that the doubt was too trivial. Why would I wanna doubt your programming knowledge? :\

Plasma_Snake
20-11-2008, 05:27 PM
Anyhoo, I would like to tell all of u guys that, as I'm also doing a 3 year GNIIT from my local NIIT center, besides my B.Tech in I.T, I had the option to choose an elective subject there and options were PL/SQL, ASP.NET(SOAP,WES 3.0) and J2ME. Guess what I chose??? ;) :D Classes for it will begin early next year so till then I've to get good in my Core JAVA. That I'll do by myself and with ur help and support but for J2ME, they'll give books too but can u guys recommend some good ones which are of Engineering student's level, not n00bish like NIIT's?

Desi-Tek.com
20-11-2008, 09:25 PM
niit is a worst place to learn java their gniit course sucks most of the java related course in gniit is outdated.

Plasma_Snake
20-11-2008, 09:52 PM
^^ Hey I'm just in for the certifications, I don't even read their books, only for passing their exams, for Core I've followed, Java 2 Complete Reference by Herbert Schildt, so now askin' one for J2ME

quad_master
21-11-2008, 02:43 PM
i need some basic concept how to implement https in java...do u have any reference/tutorial/links...i wanna understand it...:D
no code please...!!!

Desi-Tek.com
21-11-2008, 09:30 PM
i need some basic concept how to implement https in java...do u have any reference/tutorial/links...i wanna understand it...:D
no code please...!!!
thats dependent on server not java

quad_master
25-11-2008, 01:03 PM
thats dependent on server not java

i agree! but what is the process so that server starts accept https connection??

im using tomcat...plz help...

QwertyManiac
25-11-2008, 04:06 PM
Tomcat 4 - Guide to using SSL (For https connections) (http://tomcat.apache.org/tomcat-4.0-doc/ssl-howto.html)

sganesh
30-11-2008, 11:44 AM
hi Guys,
I ve one SCJP question,pl gimme answer with explanation.
Thanks in Advance....
----------------------------------------------

public class ThreadStarter extends Thread
{
private int x= 2;
public static void main(String args[]) throws Exception
{
new ThreadStarter().makeItSo();
}
public void ThreadStarter(){
x=5;
start();
}
public void makeItSo() throws Exception {
join();
x=x- 1;
System.out.println("answer:"+x);
}
public void run() {
x*=2;
}
}
--------------------------------------------------------

chandru.in
30-11-2008, 12:08 PM
Output: Execute the code.

Hint: ThreadStarter() is an instance method.

sganesh
30-11-2008, 02:43 PM
hi ,
The output of above question is 1..
I dont know how it come,,Anyone pl explain!

chandru.in
30-11-2008, 02:46 PM
As I hinted, ThreadStarter() is a method and not a constructor. Hence the default constructor which leaves x untouched is invoked. And later makeItSo() you are decrementing it and hence the output 1.

sganesh
30-11-2008, 03:52 PM
Thanks a lot..
i got it!!

Plasma_Snake
30-11-2008, 04:14 PM
I didn't, care to illustrate a bit more.

chandru.in
30-11-2008, 04:19 PM
Constructors in Java should not have any return type (not even void). The moment a return type is specified, it turns into a normal method and hence not invoked during instantiation.

gary4gar
30-11-2008, 04:35 PM
I am Reading Java Series on "Core Java" by Sun MicroSystems Press. It is written by Cay S.Horstmann & Gary Cornell. Although the book is really Good and explains each aspect of java API & associated libraries.

But wonder why they are so much against C/C++:|

anyways, the Book is good read for *programmers* looking to switch to Java. as anyone learning to code first time should skip this. don't believe me check out the first HelloWorld programs given in chapter 1:p

chandru.in
30-11-2008, 05:30 PM
But wonder why they are so much against C/C++:|
Because those are the languages whose shortcomings, Java was meant to solve. Today C/C++ and Java rule entirely different territories.
as anyone learning to code first time should skip this. don't believe me check out the first HelloWorld programs given in chapter 1:p
I have never read that book. Can you post the code for us to view?

gary4gar
30-11-2008, 11:11 PM
public Welcome {
public static void main(String args[]) {

String[] greeting = new String[3];
greeting[0] = "Welcome to Core Java";
greeting[1] = "by Cay Horstmann";
greeting[3] = "and Gary Cornell";

for(int i = 0; i < greeting.length; i++)
System.out.println(greeting[i]);
}

}



this is a first program given in the book. the authors call Welcome program extremely simple.

Indeed its simple for programmers but for newbies its a steep learning curve, they have use concepts of arrays,loops etc right into the first program;)

chandru.in
30-11-2008, 11:13 PM
public Welcome {public static void main(String args[]) {String[] greeting = new String[3]; this is a first program given in the book. the authors call Welcome program extremely simple.
Please check whether you typed in properly. I really don't think it would be this crappy. :confused:

gary4gar
30-11-2008, 11:14 PM
Please check whether you typed in properly. I really don't think it would be this crappy. :confused:
Boss, i was typing it.
I guess you are too fast:p

chandru.in
30-11-2008, 11:16 PM
Boss, i was typing it.
I guess you are too fast:p
Submitted while typing?? :p

Anyway just kidding carry on.

gary4gar
30-11-2008, 11:18 PM
Submitted while typing?? :p

Anyway just kidding carry on.
yaar, i was clicking on preview post button.
By mistake clicked on "POST reply" button:|

chandru.in
30-11-2008, 11:18 PM
public Welcome {
public static void main(String args[]) {

String[] greeting = new String[3];
greeting[0] = "Welcome to Core Java";
greeting[1] = "by Cay Horstmann";
greeting[3] = "and Gary Cornell";

for(int i = 0; i < greeting.length; i++)
System.out.println(greeting[i]);
}

}

this is a first program given in the book. the authors call Welcome program extremely simple.
Note: You missed "class" in the first line.

Ha ha ha. ROFLMAO. Thank God they did not introduce design patterns too in the same program. That's why I so love Head First series.

ravidawar
04-12-2008, 03:15 PM
i want to write a java program in which i need to call the command prompt and then run commands like ren , copy over files in a directory inside a for loop.can anyone suggest me how to do that.i tried with process and runtime but not able to achieve what i want.

chandru.in
04-12-2008, 06:54 PM
If such basic file operations are what you want to perform, have a look at the methods of the File (http://java.sun.com/javase/6/docs/api/java/io/File.html) class.

ren, dir etc are internal commands and hence Runtime.exec() will not work for them. For other external commands, Runtime.exec() will work fine.

ravidawar
05-12-2008, 08:34 PM
actually i have a folder in which i have around 100 files with name file.001, file.002 and so on.. so i need to write a java program to convert the file names to file001.rar,file002.rar and so on..thats why i need to run the commands..any other option to do that??
one thing i can do is to use a fileinputreader to read the file and then make a copy of that with a different name (all running under a for loop) but that would be a layman way of doing this thing.

Bandu
05-12-2008, 08:47 PM
^Is it only a one time rename that you have to do? If thats the case, you can do it using the ren command like option, or create a batch file to automate things. I don't see a need to write a program for such a trivial activity - unless you are looking for something that is platform independent, etc.

But, as Chandru suggested above, I don't think you will be able to do it.

If you are looking for a command based solution, then do try the following:


ren file.??? file.???.rar
That does not exactly give you the desired result, but is something you can use and enhance further to get rid of that extra dot. Heres what I did:

http://i37.tinypic.com/2cz7gw0.jpg

Edit: Looking at the set of .nnn files that you have and your intended purpose to rename them as rar, I am guessing that you would like to extract the contents from a multispan rar archive. If that is the case, you need not bother about renaming and stuff, just right click and say extract here, or rename a single file from .001 to .r01 and try to extract using this file. You may also try forcefully opening one of the files in winrar and then using the Extract option.

chandru.in
05-12-2008, 10:32 PM
actually i have a folder in which i have around 100 files with name file.001, file.002 and so on.. so i need to write a java program to convert the file names to file001.rar,file002.rar and so on..thats why i need to run the commands..any other option to do that??
one thing i can do is to use a fileinputreader to read the file and then make a copy of that with a different name (all running under a for loop) but that would be a layman way of doing this thing.

If Bandhu's reply doesn't apply to you, read ahead.

Copying file by file is not only lay man way, it is also highly inefficient. If that is exactly the pattern for re-naming, you can try the code below.

package demo;

import java.io.File;

public class Main {

public static void main(String[] args) {
File directory = new File("/home/chandru/temp");

for (int i = 1; i <= 2; i++) {
String numberString = String.format("%03d", i);

File originalFile = new File(directory, "file." + numberString);
File targetFile = new File(directory, "file" + numberString
+ ".rar");

originalFile.renameTo(targetFile);
}

System.out.println("Rename complete.");
}
}

Change the paths, loop condition and filename patterns as needed.

ravidawar
06-12-2008, 03:48 PM
Awsome Chandru , thanx a lot.
@Bandu if i do it by the ren command then i will have to do it 100 times.is there any way to run loop in a bat file ?

Bandu
06-12-2008, 07:04 PM
^Ravi. You don't need a loop. I've used wildcard thingy. If you notice, with one command, I renamed both my files and the same will work for any number of files.

Plasma_Snake
06-12-2008, 08:04 PM
Well for a change lets have this too ;) :D
Q. What is the difference between an Abstract class and Interface?
A. Terms are different ... Nothing more

Q. What is JFC ?
A. Jilebi, Fanta & Coffee

Q. Explain 2 tier and 3 -tier Architecture ?
A. Two wheelers like scooters will have 2 tyres and autorickshaws will have 3 tyres.

Q. I want to store more than 10 objects in a remote server ? Which methodology will follow ?
A. Send it through courier.

Q. Can I modify an object in CORBA ?
A. As you wish , I do not have any objections.

Q. How to communicate 2 threads each other ?
A. Non living things can't communicate.

Q. What is meant by flickering ?
A. Closing and opening of eyes.

Q. Explain RMI Architecture?
A. I am a computer professional not an architect student.

Q. What is the use of Servlets ?
A. In hotels, they can replace servers.

Q. What is the difference between Process and Threads ?
A. Threads are small ropes. Make a rope from threads is an example for process.

Q. When is update method called ?
A. Who is update method?

Q. What is JAR file ?
A. File that can be kept inside a jar.

Q. What is JINI ?
A. A ghost which was Aladdin's friend.

Q. How will you call an Applet from a Java Script?
A. I will give invitation.

Q. How you can know about drivers and database information ?
A. I will go and inquire in the bus dep to.

Q. What is serialization ?
A. Arranging one after the other from left to right.

Q. What is bean ? Where it can be used ?
A. A kind of vegetable. In kitchens for cooking they can be used.

Q. Write down how will you create a binary Tree ?
A. When we sow a binary seed , a binary tree will grow.

Q. What is the exact difference between Unicast and Multicast object ?
A. If in a society, if there is only one caste, then it is Unicast, else it is multicast

T159
06-12-2008, 08:54 PM
lol

thewisecrab
06-12-2008, 11:52 PM
@Plasma Snake
LOL :D
Great one liners :lol:

Quiz_Master
07-12-2008, 01:40 AM
LOLOL Plasma Snake... Even after reading 1st few, I was thinking of REAL answers.
Though its a bit different of what is popular among us BCA students.

Q. What is serialization ?
A. Something Ekta Kapoor does.

Q. What is bean ? Where it can be used ?
A. Mr. Bean is a funnu show! It can be used to mock Sharma Sir . (Sharma sir in my college, he looks like Mr. Bean :P )

Q. When is update method called ?
A. Raat 12 baje baad. Local Calls free :p

There is more..like that related to VB, SQL and C++ :P


Its a "Forward as Email to all teachers" material. :p (and I already Fwd it :D )

Plasma_Snake
07-12-2008, 03:42 AM
I'm glad everybody likes it. BTW don't go spamming with this ;) :D Otherwise will have to issue a RPC via RMI to stop it all :D

Desi-Tek.com
12-12-2008, 01:55 PM
can any body suggest any good book on JMS java messaging services

chandru.in
12-12-2008, 04:08 PM
Sun's tutorial. http://java.sun.com/javaee/5/docs/tutorial/doc/bncdq.html

nitish_mythology
30-12-2008, 05:49 PM
Here is my query.......


/* A sample class to clear basic concepts of inheritance....
@Author Nitish Upreti
*/

class parent
{
protected char var;
protected int var2;

public void setMe()
{
var='p';
var2=11;
}

}


class child extends parent
{

protected char var;
protected int vars;

public void setMe()
{
var='c';
vars=22;
}

}

public class god
{

private int x; //An inst var

public static void main(String args[])
{

//Trying to use the instant var in a static 'main' method

// x=12 GENERATES ERROR!! PROOVED!!


//parent p=new parent();
//child c=new child();


parent p2=new child();

//p.setMe();
//c.setMe();
p2.setMe();

//System.out.println(p.var);
//System.out.println(c.var);
System.out.println(p2.var);

}
}



The output is a blank line.... why?????????
It should either be 'p' or 'c' !!

chandru.in
30-12-2008, 07:38 PM
While inheriting and providing same name/signature for members in sub-class, methods are overriden, but variables are not.

Now when you invoke setMe() on p2, it invokes child object's setMe() (methods are overridden) thus setting child's var. When you print you are printing parents var (variables are not overridden) which is not yet set.

nitish_mythology
30-12-2008, 08:07 PM
So the output is supposed to be the default value of character i.e '/u0000' right?? is it a blank???

chandru.in
30-12-2008, 08:21 PM
Yes that is the default value. However, how it is displayed upon execution depends on the terminal and platform on which program executes.

nitish_mythology
31-12-2008, 09:53 AM
Hmm...
I am on Vector Linux! :)

Another Ques
what do we get from interfaces??? we could simply create an abstract class with all abstract methods n' all attributes public static and final...

That will be equivalent to creating an interface!!

chandru.in
31-12-2008, 10:06 AM
A class can implement multiple interfaces, but cannot extend multiple classes (even if abstract).

nitish_mythology
31-12-2008, 10:35 AM
I am aware of this fact...
I read tht interfaces save u from Deadly diamond of death..hows that??
U could have used multiple inheritance(if it was allowed) n used purely abstract classes...
WHy did java designers go 4 interfaces??

chandru.in
31-12-2008, 10:50 PM
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
02-01-2009, 08:23 AM
Can someone simply explain the different platforms .......editions of java ??
What are the career path with each of them ??

chandru.in
02-01-2009, 09:10 AM
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.

Desi-Tek.com
02-01-2009, 05:31 PM
there is another one JCP java card plateform
http://java.sun.com/javacard/

used in set top box, mobile as sim, smart card etc

ambika
02-01-2009, 07:25 PM
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
02-01-2009, 07:55 PM
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
02-01-2009, 08:17 PM
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.

chandru.in
02-01-2009, 09:10 PM
http://java.sun.com/developer/onlineTraining/

ambika
02-01-2009, 09:20 PM
http://java.sun.com/developer/onlineTraining/

Thanks , can u also assign me jdk to just start java programming .

chandru.in
02-01-2009, 11:20 PM
Thanks , can u also assign me jdk to just start java programming .
Why don't you try a search engine for this?

karamvir2008
04-01-2009, 09:18 PM
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
05-01-2009, 12:18 AM
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 (http://commons.apache.org/fileupload/) is one such API. Commons FileUpload as a dependency needs Commons IO (http://commons.apache.org/io/). Once you have both in your web-app's classpath, here is a sample code for uploading files using Commons FileUpload.

Main JSP
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://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
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
09-01-2009, 12:26 PM
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 (http://www.terminatedata.com)

Plasma_Snake
09-01-2009, 08:53 PM
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
10-01-2009, 12:00 AM
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
10-01-2009, 02:11 AM
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. ;)

T159
10-01-2009, 05:32 AM
lol