java

The use of ":" and "." in a call to java with classpath declaration.

This is a scjp mock exam question. Suppose I have the following two files: package pkg; public class Kit { public String glueIt (String a, String b) {return a+b;} } import pkg.*; class UseKit { public static void main(String[]args) { String s = new Kit().glueIt(args[1],args[2]); System.out.println(s); } }...

Exception in thread "main" : java.lang.error

Hello, I've just created a project on Eclipse and imported some source files (existing project). But I can't compile it ! Ok, the project has got several source files, so I wanted to compile only the Main.java file (with eclipse not in the command line, in the command line it worked!) but all what I get is this error : http://www.scre...

scjp mock exam question about classpath

Given the default classpath: /foo And this directory structure: foo | test | xcom |--A.class |--B.java And these two files: package xcom; public class A { } package xcom; public class B extends A { } Which allows B.java to compile? (Choose all that apply.) A. Set the current directory to xcom then invoke jav...

keeping track of multiple related input boxes using spring mvc

we have a list of domain objects needing to be edited on an html page. For example, the command & domain objects: class MyCommand { List<Person> persons; } class Person { String fname; String lname; } Then, the HTML I expect to have the Spring MVC tag libraries generate is like this: <form> <input name="persons[0].fn...

volatile boolean

If I have a volatile boolean (let's call it valid), is the following piece of code thread-safe in Java? if (valid) return; valid = true; Or, do I need to synchronize since valid is set to true only if it's false (hence set of valid depends on its current value)? ...

Java perspective is not visible in eclipse

I installed eclipse on a new unubtu install, via the package manager. I have Galileo. I copied my home directory from an older machine, and tried to open that workspace. Now I dont see any java perspective. (Possibly, all the info above is not relevant, but I just wanted to add any possible info, as this a clean install of Eclipse via p...

Read a csv data file and reutrn one specific StudentID marks for all their modules in Java

Hi, at the moment I have this: import java.util.*; import java.io.*; import java.io.BufferedReader; import java.io.FileReader; public class StudentID { public static void main(String[] args)throws Exception{ System.out.println ("Please enter StudentID: "); BufferedReader reader = new BufferedReader (new FileReader("CW2_data.c...

how do I specify a transparent background colour on a draw2d Figure?

I'm writing an eclipse plugin, and I'm layering some simple figures (i.e. view elements) together to create diagrams. A simple component looks like this The drum icon on the right is part of a tiny widget drawer. And the incomplete line underneath it is trying to represent multiplicity, but it's being blocked by the widget drawer. ...

Understanding synchronized

Given this code: public class Messager implements Runnable { public static void main(String[] args) { new Thread(new Messager("Wallace")).start(); new Thread(new Messager("Gromit")).start(); } private String name; public Messager(String name) { this.name...

Java memory allocation limit

I have a loop that spawns a lot of threads. These threads contains, among other things, 2 (massive) StringBuilder objects. These threads then run and do their thing. However, I noticed that after a certain amount of threads, I get strange crashes. I know this is because of these StringBuilder, because when I reduce their initial capacit...

Creating Java UML Automatically in NetBeans 6.7

I have three packages in NetBeans 6.7 that i want to generate a UML Class diagram automatically for. I have created the new Model by reverse engineering my project, but when i highlight all three packages under the 'Model' heading and select 'Create diagram from selected elements' i just end up with 3 green boxes. I can create separate d...

Understanding join()

Suppose a thread A is running. I have another thread, B, who's not. B has been started, is on runnable state. What happens if I call: B.join()? Will it suspend the execution of A or will it wait for A's run() method to complete? ...

Javamail problem: cannot send mails through SMTP after checking mails with POP3

So, my problem is the following: I have a mail client that I wrote in Java and I cannot send mails through SMTP after I check my mails with POP3. The exception I caught says that the transport protocol = null. The code is working fine, because I have no issue before POP3 connection. I am sure I close that connection and they are all pr...

Get subprocess id in Java

I'm creating subprocesses in this way: String command = new String("some_program"); Process p = Runtime.getRuntime().exec(command); How I can get that subprocess id? P.S. I'm working on Linux. ...

Using CFBooleanRef through JNA

I'm using JNA to call Carbon APIs. The particular API call that I want to call takes a CFBooleanRef as a parameter. The values, kCFBooleanTrue and kCFBooleanFalse, are declared as direct extern references in the header files. How can I get references to those two values on the Java side, so that I can pass the values to the API call ? ...

java.rmi.UnmarshalException: unable to pull client classes by server

Hi, I have an RMI client/server set-up on two machines that works fine in a simple situation when the server doesn't require a client-side defned class. However, when I need to use a class defined on the client side I am unable to have the server unmarshall those classes. I suspect this is an issue with my java.rmi.server.codebase prop...

Script to convert log4j.properties to log4j.xml

I need to use custom filters, so I need to convert some long log4j.properties files to log4j.xml. Is anyone aware of a tool to do this, or willing to contribute one they have used? Searching has thus far turned up no such tool. ...

Understanding wait()

I created this silly program to play with wait() public class WaitTest { public static void main(String [] args) { System.out.print("1 "); synchronized(args){ System.out.print("2 "); try { args.wait(); args.notifyAll(); } catch(InterruptedException e){ System.out.pri...

Has-A relationship applies to inherited members?

Given the code: class Car{ Engine engine; } class SportCar extends Car{ SportChair chair; } Is it valid to say that 'SportCar "has-a" Engine and a SportChair'? Or the only valid affirmations are: 'SportCar "has-a" SportChair' and 'Car "has-a" Engine' ? ...

Constructor (Java)

Hi, I wonder if it's a big error (in small one class Java program) when I define variable in a class level rather that using the constructor? Can we do that? The method body will be the same in both cases. Many thanks! eg. public class test{ static int column1 = 0; static int column2 = 1; public static void main(S...