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);
}
}...
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...
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...
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...
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)?
...
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...
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...
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.
...
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...
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...
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...
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?
...
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...
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.
...
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 ?
...
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...
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.
...
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...
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' ?
...
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...