this and super are keywords isn't it, then how can we use them for passing arguments to constructors the same way as with a method??
In short how is it that these can show such distinct behaviours??
Hi.
I'm building a webapp that uses jboss-seam with jsf, facelets and rich faces, running on top of jboss AS 5.1.
I would like to add a portlet area where I could add my own portlets, but from what I got (reading forums and documentation) I need to be running a portlet container/portal (something like liferay or gatein). But I don't want to be running a portal. I just want some kind of control where I can embed a portlet (something like an iFrame).
Is this true or I got it wrong?
If I'm wrong, how can I add an area to my webapp where I can add a portlet?
Thanks
Best regards.
My problem is i have a class and in it there is a list of elements of another class.
public class Branch
{
private ArrayList<Player> players = new ArrayList<Player>();
String brName;
public Branch() {}
public void setBr(String brName){this.brName = brName;}
public String getBr(){return brName;}
public ArrayList<Player> getPlayers() { return players; }
public void setPlayers(ArrayList<Player> players) { this.players =new ArrayList<Player>(players); }
}
public class Player
{
private String name;
private String pos;
private Integer salary;
private Integer number;
public Player(String name, String pos, Integer salary, Integer number)
{
this.name = name;
this.pos = pos;
this.salary = salary;
this.number = number;
}
public Player(){}
public String getName() { return name; }
public String getPos() { return pos; }
public Integer getSalary() { return salary; }
public Integer getNumber() { return number; }
public void setName(String name) { this.name = name; }
public void setPos(String pos) { this.pos = pos; }
public void setSalary(Integer salary) { this.salary = salary; }
public void setNumber(Integer number) { this.number = number; }
}
My problem is to print the players of a Branch with their name,pos,salary,number.
For this i tried this simply :
String p1,p2;
int a1,a2;
p1 = input.readLine();
p2 = input.readLine();
a1 = Integer.parseInt(input.readLine());
a2 = Integer.parseInt(input.readLine());
players[0].setName(p1);
players[0].setPos(p2);
players[0].setSalary(a1);
players[0].setNumber(a2);
ptmp.add(players[0]);
myBranch[0].setPlayers(ptmp);
System.out.println(myBranch[0].brName + " " + myBranch[0].getPlayers());
I wrote this just to try how to display. I created an array of Players, and Branches so they already defined. The problem is getPlayers() doesn't give me any result. What is the way to do this?
I have a simple UDP server that creates a new thread for processing incoming data. While testing it by sending about 100 packets/second I notice that it's memory usage continues to increase. Is there any leak evident from my code below?
Here is the code for the server.
public class UDPServer
{
public static void main(String[] args)
{
UDPServer server = new UDPServer(15001);
server.start();
}
private int port;
public UDPServer(int port)
{
this.port = port;
}
public void start()
{
try
{
DatagramSocket ss = new DatagramSocket(this.port);
while(true)
{
byte[] data = new byte[1412];
DatagramPacket receivePacket = new DatagramPacket(data, data.length);
ss.receive(receivePacket);
new DataHandler(receivePacket.getData()).start();
}
}
catch (IOException e)
{
e.printStackTrace();
}
}
}
Here is the code for the new thread that processes the data. For now, the run() method doesn't do anything.
public class DataHandler extends Thread
{
private byte[] data;
public DataHandler(byte[] data)
{
this.data = data;
}
@Override
public void run()
{
System.out.println("run");
}
}
I have this code to print out all directories and files. I tried to use recursive method call in for loop. With enhanced for loop, the code prints out all the directories and files correctly. But with regular for loop, the code does not work. I am puzzled by the difference between regular and enhanced for loops.
public class FileCopy {
private File[] childFiles = null;
public static void main(String[] args) {
FileCopy fileCopy = new FileCopy();
File srcFile = new File("c:\\temp");
fileCopy.copyTree(srcFile);
}
public void copyTree(File file){
if(file.isDirectory()){
System.out.println(file + " is a directory. ");
childFiles = file.listFiles();
/*for(int j=0; j<childFiles.length; j++){
copyTree(childFiles[j]);
}
This part is not working*/
for(File a: childFiles){
copyTree(a);
}
return;
} else{
System.out.println(file + " is a file. ");
return;
}
}
}
I want to have a generic object that implements an interface.
I mean if i have a class A
Class A <E>{
E x;
}
I want to make sure that x will implement a particular interface(myInterface). In other words, that the type E implements an interface.
I am wanting to create a gihub repository that offers benchmarking code that
works for concurrent features available only in JDK 1.7 (Fork/Join) as well as for older ones found in JDK 1.6.
Offering both options is important for what I need.
Does anyone have a recommendation how should I structure the repository.
I was planning on having a repo called and under it:
jdk17
build
src
mycode ...
jdk16
build
src
mycode
Please suggest any alternatives, possibly use of Maven or other more practical approaches, if any.
I am making a program that lets a user input a chemical for example C9H11N02. When they enter that I want to split it up into pieces so I can have it like C9, H11, N, 02. When I have it like this I want to make changes to it so I can make it C10H12N203 and then put it back together. This is what I have done so far. using the regular expression I have used I can extract the integer value, but how would I go about get C10, H11 etc..?
System.out.println("Enter Data");
Scanner k = new Scanner( System.in );
String input = k.nextLine();
String reg = "\\s\\s\\s";
String [] data;
data = input.split( reg );
int m = Integer.parseInt( data[0] );
int n = Integer.parseInt( data[1] );
I seem to have two options on how to implement arrays, and I want to know which I should go with:
Use the ARRAY data type and (from what I understand) effectively serialize data objects into the database (which in my case are just wrapped primitive types; don't know of another way to make this work).
Use a separate table and map with foreign keys for each array item.
If you have experience with this (especially with H2), which would you recommend?
I have a string;
String allIn = "(50 > 100) AND (85< 100)";
Now I need to evaluate if the conditions inside are TRUE or FALSE, how can I do it?
In real the string will be a value from a field in my DB, where I will substitute different values and they will form a string as shown above.
Runtime.getRuntime().exec("C:\mysql\bin\mysqldump -u root -pmypassword Databasename -r C:/backup.sql");
I am using this code to create back up from my sql. but It creates the empty file in the path.Because it is waiting in the command prompt to get the password. How can i give password to it
Using command prompt directly when i press enter after typing, it asks password.After giving password,It creates the backup.Give me any solution for this
Thanks in advance
I'm trying to match the username with a regex. Please don't suggest a split.
USERNAME=geo
Here's my code:
String input = "USERNAME=geo";
Pattern pat = Pattern.compile("USERNAME=(\\w+)");
Matcher mat = pat.matcher(input);
if(mat.find()) {
System.out.println(mat.group());
}
why doesn't it find geo in the group? I noticed that if I use the .group(1), it finds the username. However the group method contains USERNAME=geo. Why?
Hi i am trying to match a string against a pattern
this is the possible string
signal CS, NS, dl: stateType := writeOrRead0;
signal CS, pS : stateType := writeOrRead0;
signal dS : stateType := writeOrRead0;
i am only concerned with the pattern as far as the first colon.
but the number of signals define can be more than one it could be three or four even
this is the regular expression i have
^signal\\s*(\\w+),*\\s*(\\w+)\\s*:
it will pick up the second two signal but and for the second one it picks up CS and pS and but the d and S in the next signal when i use
matcher.group()
come up seperately
Can anyone give me an expression that will pick up all signal names whether there is one two three or more?
I have data from a database loaded into a JTable through a custom table model. I want to have a column (should be the first column) which simply shows the display row number (i.e. it is not tied to any data (or sorting) but is simply the row number on the screen starting at 1). These "column headers" should be grayed out like the row headers.
Any idea how to do this?
Thanks
I came across this weird (in my opinion) behavior today. Take this simple Test class:
public class Test {
public static void main(String[] args) {
Test t = new Test();
t.run();
}
private void run() {
List<Object> list = new ArrayList<Object>();
list.add(new Object());
list.add(new Object());
method(list);
}
public void method(Object o) {
System.out.println("Object");
}
public void method(List<Object> o) {
System.out.println("List of Objects");
}
}
It behaves the way you expect, printing "List of Objects". But if you change the following three lines:
List<String> list = new ArrayList<String>();
list.add("");
list.add("");
you will get "Object" instead.
I tried this a few other ways and got the same result. Is this a bug or is it a normal behavior? And if it is normal, can someone explain why?
Thanks.
I'm maintaining this Swing app that has a "print" option. Users need to be kept from interacting in any way with the underlying file system, but the print dialog offers "print to file" as one printer, and that of course allows selecting a directory and file from the file system.
Is there a painless way to override/modify the print dialog to hide the "to file" printer from this dialog? I understand the API will let me do this piecemeal but I'd rather not have to re-create most of the dialog GUI and functionality to do this.
Hi,
I need to find out how many even values are contained in a binary tree.
this is my code.
private int countEven(BSTNode root){
if ((root == null)|| (root.value%2==1))
return 0;
return 1+ countEven(root.left) + countEven(root.right);
}
this i just coded as i do not have a way to test this out. I'm not able to test it out at the moment but need an answer so badly.
any help is deeply appreciated.
I have the following scenario :
public class A {
private int x = 5;
public void print()
{
System.out.println(x);
}
}
public class B extends A {
private int x = 10;
/*public void print()
{
System.out.println(x);
}*/
public static void main(String[] args) {
B b = new B();
b.print();
}
}
On executing the code, the output is : 5.
How to access the child class(B's) variable(x) via the parent class method?
Could this be done without overriding the print() method (i.e. uncommenting it in B)?
[This is important because on overriding we will have to rewrite the whole code for the print() method again]
Say I have the following:
Class myclass
{
public string stra ="", strb = ""
myclass(String a, String b){stra=a;strb=b}
}
//then in the app I want to do:
myclass myclassinst1 = new myclass("blah","xxxx");
myclass myclassinst2 = new myclass("blah2","yyyy");
myclass myclassinst3 = new myclass("blah3","zzzz");
list <myclass> mylist = new ArrayList<myclass>();
mylist.add(myclassinst1 );
mylist.add(myclassinst2 );
mylist.add(myclassinst3 );
//How would I then convert that to a String[] Array of all the stra elements without using a loop.
//eg:
String[] strarr_a = mylist.toarray(myclass.stra);
String[] strarr_b = mylist.toarray(myclass.strb);
//instead of having to do
String[] strarr_a = new String[mylist.size()];
String[] strarr_b = new String[mylist.size()];
for (int i=0;i<mylist.size();i++)
{
strarr_a[i] = mylist.get(i).stra;
strarr_b[i] = mylist.get(i).strb;
}
Can anyone help me find where the execption is? I can't seem to find the problem..
public void fieldChanged(Field f, int context){
//if the submit button is clicked
try{
stopTime = System.currentTimeMillis();
timeTaken = stopTime - startTime;
timeInSecs = ((timeTaken/1000));
speed = 45/timeInSecs;
Dialog.alert("Speed of Delivery: " + speed + "mph");
}
catch(ArithmeticException e){
Dialog.alert("error " + speed);
e.printStackTrace();
}
}
startTime variable is a global variable..
Coming from other web frameworks, I'm used to being able to map parts of a URL to method parameters. I know that web.xml provides a way to map an entire URL to a Servlet but is there a way to get more features out of this, such as mapping pieces of the URL to method parameters?
Hello,
I'm not able to understand the following multi-dimensional code. Could someone please clarify me?
int[][] myJaggedArr = new int [][]
{
new int[] {1,3,5,7,9},
new int[] {0,2,4,6},
new int[] {11,22}
};
May I know how it is different from the following code?
int[][] myArr = new int [][] {
{1,3,5,7,9},
{0,2,4,6},
{11,22} };
I am having a problem figuring how to check a string for the same characters in a row then count that same character in a row then printing it out then giving the location of the last occorance of that character count then printing it out then moving to the next character in the string that is different then the previous character and the program is case sensitive.
So the input could be: aaaaAAAbbbddccc
How would I compress this string to: a4A3b3d2c3 ? and then decompress it?
I am using LinkedList and retrieving an Iterator object by using list.iterator(). After that, I am checking it.hasNext(), real issue is while checking it.hasNext(), sometimes it returns false. I need help why this is happening, though I have elements in the list.
Some code:
public synchronized void check(Object obj) throws Exception {
Iterator itr = list.iterator();
while(itr.hasNext()) { //This Line I get false.. though i have list size is 1
Item p = (Item)itr.next();
if(p.getId() == null) {continue;}
if(p.getId().getElemntId() == obj.getId() || obj.getId() == 0 ) {
p.setResponse(obj);
notifyAll();
return;
}
}
Log.Error("validate failed obj.getId="+obj.getId()+" **list.size="+list.size()*This shows 1*);
throw new Exception("InvalidData");
}