Am about to do a homework, and i need to store quite a lot of information (Dictionary) in a data structure of my choice. I heard people in my classroom saying hash-tables are the way to go. How come?
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?
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");
}
I am executing a stored procedure which has 2 cusors within the stored procedure.
The 1st cursor which is not return to the jdbc as a resultset is closed within the stored procedure.
The 2nd cursor which returns the resultset to the jdbc is not closed within the stored procedure.
Upon executing I encounter cursor is closed exception which is puzzling.
Since the ResultSet will close all underlying cursor upon invoking the close() method
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
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 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]
This code seems to work fine
class Rule<T>
{
public <T>Rule(T t)
{
}
public <T> void Foo(T t)
{
}
}
Does the method type parameter shadow the class type parameter?
Also when you create an object does it use the type parameter of the class?
example
Rule<String> r = new Rule<String>();
Does this normally apply to the type parameter of the class, in the situation where they do not conflict? I mean when only the class has a type parameter, not the constructor, or does this look for a type parameter in the constructor? If they do conflict how does this change?
SEE DISCUSSION BELOW
if I have a function call
x = <Type Parameter>method(); // this is a syntax error even inside the function or class ; I must place a this before it, why is this, and does everything still hold true. Why don't I need to prefix anything for the constructor call. Shouldn't Oracle fix this.
i'm having a problem loading an image from a package i created in the project that was set to contain images, i have to write the whole picture location in the computer instead of just the package that contains it. i've tried several things but nothing seams to work...
where is the command i use to load the image :
searchBar = ImageIO.read(new File("C:\\Users\\ASUS\\Documents\\NetBeansProjects\\Project\\src\\Images\\search.jpg"));
"Images" is a package in my project , this works, but when i try loading the image without the "C:\..." only with the "\Images..." it doesn't , so i have to change it every time i open this project in another computer.
hopefully one of u has the answer for me , thanks in advance for any answer :)
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.
Hi
I have a method that has a reference to a linked list and a int value. So, this method would count and return how often the value happens in the linked list. So, I decided to make a class,
public class ListNode{
public ListNode (int v, ListNode n) {value = v; next = n;)
public int value;
public ListNode next;
}
Then, the method would start with a
public static int findValue(ListNode x, int valueToCount){
// so would I do it like this?? I don't know how to find the value,
// like do I check it?
for (int i =0; i< x.length ;i++){
valueToCount += valueToCount;
}
So, I CHANGED this part, If I did this recursively, then I would have
public static int findValue(ListNode x, int valueToCount) {
if (x.next != null && x.value == valueToCount {
return 1 + findValue(x, valueToCount);}
else
return new findvalue(x, valueToCount);
SO, is the recursive part correct now?
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
This is a jFrame to connect to the database and this is in the button connect. My issue is in the passwordField NetBeans make me do a char[], but my .getConnection not let me insert the char[] ERROR: "no suitable method found for getConnection(String,String,char[])". So I will change to String right? So when I change and run the jFrame said access denied. when I start doing the System.out.println(l) " Give me the right answer" Like this: "Alex". But when I do the System.out.println(password) "Give me the Array spaces and not the value"
Like this: jdbc:mysql://localhost/home inventory root [C@5be5ab68 <--- Array space . What I doing wrong?
try {
Class.forName("org.gjt.mm.mysql.Driver"); //Load the driver
String host = "jdbc:mysql://"+tServerHost.getText()+"/"+tSchema.getText();
String uName = tUsername.getText();
char[] l = pPassword.getPassword();
System.out.println(l);
String password= l.toString();
System.out.println(host+uName+l);
con = DriverManager.getConnection(host, uName, password);
System.out.println(host+uName+password);
} catch (SQLException | ClassNotFoundException ex) {
JOptionPane.showMessageDialog(this, ex.getMessage());
}
}
the Method hasTwoTrueValues returns true if at least two values in an array of booleans are true. Provide the Big-Oh running time for all three implementations proposed.
// Version 1
public boolean has TwoTrueValues( boolean [ ] arr ) {
int count = 0;
for( int i = 0; i < arr. length; i++ )
if( arr[ i ] )
count++;
return count >= 2;
}
// Version 2
public boolean hasTwoTrueValues( boolean [ ] arr ) {
for( int i = 0; i < arr.length; i++ )
for( int j = i + 1; j < arr.length; j++ )
if( arr[ i ] && arr[ j ] )
return true;
}
// Version 3
public boolean hasTwoTrueValues( boolean [ ] arr ) {
for( int i = 0; i < arr.length; i++
if( arr[ i ] )
for( int j = i + 1; j < arr.length; j++ )
if( arr[ j ] )
return true;
return false;
}
For Version 1 I say the running time is O(n)
Version 2 I say O(n^2)
Version 3 I say O(n^2)
I am really new to this Big Oh Notation so if my answers are incorrect could you please explain and help.
I have a problem here that still cannot solve, the thing is I have this abstract class:
public abstract class AbstractBean<T> {
private Class<T> entityClass;
public AbstractBean(Class<T> entityClass) {
this.entityClass = entityClass;
}...
Now I have another class that inherits this abstract:
@Stateless
@LocalBean
public class BasicUserBean<T extends BasicUser> extends AbstractBean<T> {
private Class<T> user;
public BasicUserBean() {
super(user); // Error: cannot reference user before supertype contructor has been called.
}
My question is how can I make this to work?, I am trying to make the class BasicUserBean inheritable, so if I have class PersonBean which inherits BasicUserBean then I could set in the Generic the entity Person which also inherits the entity BasicUser. And it will end up being:
@Stateless
@LocalBean
public class PersonBean extends BasicUserBean<Person> {
public PersonBean() {
super(Person.class);
}
...
I just want to inherit the basic functionality from BasicUserBean to all descendants, so I do not have to repeat the same code among all descendants. Thanks!.
Please help me how to creat own custom layout, container, component, layout manager...
Example:
Containers and Layout Managers
Create a window frame.
Nest panels within a frame for better layout control.
Create and display buttons in a panel.
List two component attributes that are controlled by a layout manager.
Set the layout manager for a container.
Place components in a panel using BorderLayout, GridLayout, and FlowLayout.
Name one advantage of each of the layout managers.
Create panels with titles.
i was search on google but can't find any that match my requirement
Thanks for your help
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;
}
}
}
Hi, I have a string like this String str = "la$le\$li$lo".
I want to split it to get the following output "la","le\$li","lo". The \$ is a $ escaped so it should be left in the output.
But when I do str.split("[^\\\\]\\$") y get "l","le\$l","lo".
From what I get my regex is matching a$ and i$ and removing then. Any idea of how to get my characters back?
Thanks
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 have few small basic problems :
How to format :
int i = 456;
to give output :
""00000456"
? I've tried %08d but it's not working. Next thing is a problem with conversion and then formatting. I have side and height of triangle, let's say int's 4,7, and 7 is the height. From formula for field we know that F=1/2(a*h). So how to get F as float, with precision up to 10 places ?
float f = a*h;
works fine, but multiplying it by 0.5 gives error and by 1/2 returns 0.