Home » Java Technology

Java Intermediate

Casting Object[] into String[]Wed, 16 Jul 2008 17:43:00 GMT

My question starts with the toArray() method of the Collection - from this I get an Object[] back. However I know that each of the elements in the Collection is a String object, so I figured the obvious thing to do would be to cast it so:code:String[] strings = (String[]) collection.toArray();Wh...

Comments (17) | Promote | Bookmark

Is it possible to change default implementation of java built in classes!Wed, 16 Jul 2008 18:01:00 GMT

Hello Ranchers! I want to change the default implementation of some method which will be members of some built in class of java. Let's say length method of string class will return string insted of returning int. Now i find out the source of string class made the changes and compiles the sam...

Comments (7) | Promote | Bookmark

basic question: abt properties file & build xmlTue, 15 Jul 2008 20:30:00 GMT

Hi I have to create a folder (named XYZ) in a servlet but i need to pass on the name when I build the web app . I want to give the folder-name in a properties file, and replace the folder-name in the servlet when am building the app through build.xmlQuestion:What to do in build.xml ?What to do i...

Comments (6) | Promote | Bookmark

interfaceWed, 16 Jul 2008 17:51:00 GMT

hi everyone, There are many interfaces in jave. For example consider public interface RequestDispatcher. In this interface, there are 2 methods by name include() and forward(). We know that both the methods do some work when they are called. But seeing the interface, they look empty. Somewhere...

Comments (6) | Promote | Bookmark

Implementing a Interface at RuntimeWed, 16 Jul 2008 18:17:00 GMT

Is it Possible to Implement a Interface at Runtime?...Something Like this...Class interface = Class.forName("interface Name");public Class implementInterface(Class interface){blah... blah...retrun (Class)}Please do clarify my doubt....thanksVivek...

Comments (5) | Promote | Bookmark

threading issueWed, 16 Jul 2008 18:16:00 GMT

consider there is a program in which several threads are running.i want to modify the program in such a manner that when the main thread terminates all other threads have been terminated and i don't want to scan the file.Only i want to add some lines of code at the closing brace of main(like...

Comments (5) | Promote | Bookmark

Read in fileWed, 16 Jul 2008 17:02:00 GMT

Howdie:I have issues with this program:package Scores;import java.io.*;import java.util.*;import java.util.Scanner.*;public class Scores { public static void main(String[] args) throws Exception { int total=0; int count=0; // Create a File instance java.io.File file = new java.io.File("Scores.tx...

Comments (5) | Promote | Bookmark

in how many ways i can debug my webapplicationWed, 16 Jul 2008 17:53:00 GMT

actually i use system.out.println and log4j for debuggingis ther any other way to debug my webapplication?and what is the difference between System.out.println debug and log4j debug methods?please can any one tell me about this thanks in advance...

Comments (5) | Promote | Bookmark

How to return array of objects in main programWed, 16 Jul 2008 18:03:00 GMT

Hi All,Help me out to find a solution to the below program.1) I have declared an array called student [] in main program2)I initialised the array inside the function void modifyRef().I can print the values inside the function.I need to get the values returned in the main function.3)But the const...

Comments (5) | Promote | Bookmark

Sorting arrayList w/o Collections.sort()Wed, 16 Jul 2008 17:47:00 GMT

implemented a bubble sort and all is well[ January 06, 2004: Message edited by: Tony Fabeets ]...

Comments (4) | Promote | Bookmark

Non static inner classesWed, 16 Jul 2008 18:17:00 GMT

How does this code work?...Outer o = null;Outer.Inner = o.new Inner();...where Inner is a non static inner class of Outer.Any ideas?...

Comments (4) | Promote | Bookmark

Coponents required to run AntTue, 15 Jul 2008 20:28:00 GMT

Hi All,What all software are required to run the Ant build tool.An example in this regard would beappreciated...

Comments (4) | Promote | Bookmark

HashSet PerformanceWed, 16 Jul 2008 18:27:00 GMT

Is HashSet generally known to be the fastest collection available in J2SE?I've setup a HashSet without about 1000 different numbers in it which I am just using to do a comparison to see if the number is in the collection.This works pretty well, but is it going to slow down significantly as t...

Comments (3) | Promote | Bookmark

interface questionWed, 16 Jul 2008 18:15:00 GMT

code:interface Apple{int x=7;}class AppleClass implements Apple{ static int x; public static void main(String args[]) { System.out.println("x value"+x);}}answer is 0 ..what happens to interface variable x?...

Comments (3) | Promote | Bookmark

Read the records from the ArrayListThu, 17 Jul 2008 20:28:00 GMT

Hi Java masters,I'm facing some difficulties with a java quizz.Please give me some ideas.Quiz01 :The text file has three records like :JohnNO.123, HirLet Road,LL 234025-5-54551 5 0 2 7000PaulNO.23, Hello Road,LL 235025-5-54541 5 0 2 6000MaryNO.23, Mine Road,LL 23523-5-54541 5 0 2 9000Accordi...

Comments (2) | Promote | Bookmark

How would I I print a page of records.Wed, 16 Jul 2008 18:24:00 GMT

Hi-I have a requirement to print a record (data like : name, address etc) once the record is updated. I would have to write the code to get the printer name and path in the network from a properties file and then print the record using the same. Is there anyway I can do this using java.Please he...

Comments (2) | Promote | Bookmark

Declaring a variable from another classWed, 16 Jul 2008 18:17:00 GMT

I have two classes. The first has 4 arrays I would like to use in the other class. What is the syntax for doing this I keep getting a nullpointer exception. The one class is called Final and the other is Project.for(int i = 0; i< Final.arr.length; i++){ g.setColor(Color.BLUE); g.drawOval((int...

Comments (2) | Promote | Bookmark

Assertion programWed, 16 Jul 2008 17:39:00 GMT

can anyone tell me how the following program works ..?public class TernaryAssertion{public static void assertBounds(int low,int high,int value){assert (value > low ? value < high : false) : ( value < high ? "too low" :"too high");}public static void main(String[]args){assertBounds(100,2...

Comments (2) | Promote | Bookmark

Looping over a collection of values in Ant?Tue, 15 Jul 2008 18:26:00 GMT

I have a series of Amazon EC2 instances I wish to hold the addresses for in my build.xml file. For a particular target I would like to loop through all of these addresses and issue a command to the server. I can do it for one at a time; but I'm not sure how to create the equivalent of a Coll...

Comments (2) | Promote | Bookmark

Automatic Test generation for JavaWed, 16 Jul 2008 17:02:00 GMT

Hi all, Say i have a huge applicaiton. The problem is as follows :-1) unfortunately there is no unit test cases ie junit written.2) Now if some part of the project is changed. developer gonna check the whole application to know if everything it working and none is broken.3) So i was wondering if...

Comments (1) | Promote | Bookmark

Book for AntTue, 15 Jul 2008 20:25:00 GMT

Hi all,Can anybody offer a good book for Ant with examples of building and deploying Web and J2EE Applications?Thanks...

Comments (1) | Promote | Bookmark

close the application completely(urgent)Wed, 16 Jul 2008 18:05:00 GMT

My problem is I have two classes, one to receive a message continuously i.e. while(true) loop, whenever that socket(port) is contacted.I run the sending file in a nother window. I run a single bathc file to do so. source:[run.bat]--- javaw send javaw receive---The send program places a system...

Comments (1) | Promote | Bookmark

log4j listener with antTue, 15 Jul 2008 20:24:00 GMT

Just started learning log4j.I wanted to create log4j listener for my build file, hence started with the small one.code:<project name="Logger" default="main"><target name="main"> <echo> Echo task</echo></target></project>is the build file.I have log4j.propertie...

Comments (1) | Promote | Bookmark

Date validationsWed, 16 Jul 2008 18:26:00 GMT

hi, can anybdy help me how can i do date validations.im wrking with JDBC and im inserting a query into date field but its giving me errors.regardsmurali...

Comments (1) | Promote | Bookmark

Just a basic question!Wed, 16 Jul 2008 17:40:00 GMT

Hey all, I really have a basic question which can be best described as shown below:- public class SomeClass{ public SomeClass(){ int x =20; } public static void main(String[] args){ SomeClass y = new SomeClass(); System.out.println(y.x); } this will give me compile error right. Is it because th...

Comments (1) | Promote | Bookmark

inhertance question / interface /abstract classThu, 17 Jul 2008 20:25:00 GMT

I am trying to model a quiz. I create a Quiz object. There are 4 different types of Quiz. Each quiz needs to calculate results...therefore each of the 4 Quiz objects should have a calculate() method. Because each has to have this method, I thought I would create either an abstract class or inter...

Comments (1) | Promote | Bookmark

Maven Command Line argumentsTue, 15 Jul 2008 20:24:00 GMT

Is it possible to pass in command line arguments to Maven?In my build process, I call my goal overnightBuild which performs the entire process. I want to change the process that you can pass in an argument that specifies which branch the build is to be run off. So is it possible to pass in somet...

Comments (1) | Promote | Bookmark

Help With Ant/XDoclet ErrorTue, 15 Jul 2008 20:28:00 GMT

I'm trying to use Ant and XDoclet, and I get the following error:[ejbdoclet] javadoc: Cannot find doclet class xdoclet.DocletTask$DocletMain[ejbdoclet] 1 errorejbdoclet] BUILD FAILED: file :/code/Java/money/build.xml:43: Javadoc returned 1I have the xdoclet.jar in my project classpath. The...

Comments (1) | Promote | Bookmark

URL connection does not detect when online/offlineWed, 16 Jul 2008 18:09:00 GMT

Hi,I'm having a strange error with the URL class. I have written some code to poll a certain URL every second...thereby verifying if the Internet connection is functional. The code is shown below.If I have a working Internet connection and run the code, it says the connection is working. If...

Comments (0) | Promote | Bookmark

Architectural AdviceWed, 16 Jul 2008 17:56:00 GMT

NOTICE: This post is for entertainment, relaxation purposes only. It's a post about how to design a new feature to a MUD.This isn't a bug, nor am I asking for urgent help, just thought I'd ask some more experienced Java developers if this makes sense. I'll try to make this as log...

Comments (0) | Promote | Bookmark