Hi i encountered this problem whereby when i initialized my String[], there seems to be a null in the String[] before i do anything. How do i initialized the String[] to be completely empty,i.e. without the null at the start?
The output for the following code is:
nullABC
nullABC
nullABC
nullABC
nullABC
public static void main(String[] args){
String[] inputArr = new String[5];
for (int i = 0; i< inputArr.length; i++){
inputArr[i] += "ABC";
}
for (int i = 0; i< inputArr.length; i++){
System.out.println(inputArr[i]);
}
}
}
I have some of the code here. I am trying to use one class to reference another so I may obtain the first name of the person. I want the firstName in main class to work but IDE mentions the variable isn't found. Will replacing 'first' with 'firstName' work?
Main class:
public BasePlusCommissionEmployee( String first, String last,
String ssn, double sales, double rate, double salary) {
cE = new CommissionEmployee( first, last, ssn, sales, rate );
setBaseSalary( salary );
}
public void setFirstName(String firstName) {
// Trying to get this to work...
cE.setFirstName(first);
}
SubClass:
private String firstName;
public void setFirstName( String first )
{
firstName = first;
}
Table SUBCOURSE references COURSE
COURSE(id, name)
SUBCOURSE(id, course_id, name)
So, 1:M.
Hibernate generates for Course:
@OneToMany(fetch = FetchType.LAZY, mappedBy = "course", cascade = CascadeType.ALL)
public Set getSubCourses() {
return this.subCourses;
}
for Subcourse it generates
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "course_id", nullable = false)
public Course getCourse() {
return this.course;
}
Now the problem is that cascading does not work as expected.
I want to create a collection of SubCourse objects (Set), fill it and then
bind it to setSubCourses() of Course object.
Though, having ManyToOne thing in a Subcourses table, I need to manually
setCourse() before adding to collection on each object. If I do not do so,
an exception is raised.
What can you recommend me?
Is there a simple way to clear all fields of an instance from a an instance? I mean, I would like to remove all values assigned to the fields of an instance.
ADDED
From the main thread I start a window and another thread which controls state of the window (the last thread, for example, display certain panels for a certain period of time). I have a class which contains state of the window (on which stage the user is, which buttons he already clicked).
In the end, user may want to start the whole process from the beginning (it is a game). So, I decided. So, if everything is executed from the beginning, I would like to have all parameter to be clean (fresh, unassigned).
ADDED
The main thread, creates the new object which is executed in a new thread (and the old thread is finished). So, I cannot create a new object from the old thread. I just have a loop in the second thread.
Currently anybody can access the solr admin page by going to my_ip:8983/solr
I can't have it like that, so how can I make it prompt for password or something?
I have setup my servers apache2.conf file to prompt for password whenever my site is accessed by www.mydomain.com.
But when using another port, the "require password" wont show up.
Any ideas how to secure this?
Don't point me to the SolrSecurity wiki because it's simply too outdated. I have tried it without luck.
Thanks
I am trying to make an android app that makes connection with bluetooth device. It works fine but when I call BluetoothSocket.connect() and it is not able to connect to devise its blocking. The thread and does not throw any exception. So when I try to close application while connect() is running its not responding. How can I cancel it? Used BluetoothSocket.close() in ... but still its not working for me.
protected void simpleComm(Integer port) {
// The documents tell us to cancel the discovery process.
try {
Method m = mmDevice.getClass().getMethod("createRfcommSocket", new Class[] { int.class });
mmSocket = (BluetoothSocket) m.invoke(mmDevice, port);
mmSocket.connect(); // <== blocks untill is not connected
Log.d(TAG, " connection success===");
}catch(Exception e){
if (!abort) {
connectionFailed();
// Close the socket
try {
mmSocket.close();
// Start the service over to restart listening mode
BluetoothService.this.start();
} catch (IOException e2) {
Log.e(TAG,"unable to close() socket during connection failure", e2);
}
}
return;
}
}
public void cancel() {
try {
abort = true;
mmSocket.close();
} catch (IOException e) {
Log.e(TAG, "close() of connect socket failed", e);
}
}
I personally quite like instance initializers - I use them to assign default values to things such as collections so when writing constructors I don't have to remember to assign them the same default values each time. It seems quite elegant to me - avoids annoying NPE's popping up and avoids duplicate code. A private method doesn't seem as nice because a) it can't assign values to final fields, b) it could be run elsewhere in code and c) the method still needs to be explicitly called at the start of each constructor.
However, the flip side with others I have spoken to is that they're confusing, some people reading the code might not understand what they do or when they're called and thus they could cause more problems than they solve.
Are proper use of these initializers something to be encouraged or avoided? Or is it an "each to their own" case?
Hey I try to write a littel bash script. This should copy a dir and all files in it. Then it should search each file and dir in this copied dir for a String (e.g @ForTestingOnly) and then this save the line number. Then it should go on and count each { and } as soon as the number is equals it should save againg the line number. = it should delete all the lines between this 2 numbers.
I'm trying to make a script which searchs for all this annotations and then delete the method which is directly after this ano.
Thx for help...
It says I ended this statement wrong when if I input it into sql plus with just the addition of ; it works perfectly. What am I doing wrong?
Statement statement = connection.createStatement();
statement.executeUpdate("delete from aplbuk MODEL = '"+ textField_4.getText() + "'AND year = '" + textField_1.getText() + "' AND Litres = '" + textField_2.getText()
+ "' AND ENGINE_TYPE = '" + textField_3.getText() + "'");
statement.close();
Hey Guys
I want to set two different look and fields on one frame.
I have two different panels in that.
i want to set two different look and field for both.
Can I do that?
And if yes then how?
I have a question. What is wrong with regards to the below code:
ArrayList tempList2 = new ArrayList();
tempList2 = getXYZ(tempList1, tempList2);
//method getXYZ
getXYZ(ArrayList tempList1, ArrayList tempList2) {
//does some logic and adds objects into tempList2
return tempList2;
}
The code will get executed but it seems by passing tempList2 to the getXYZ method argument, it is doing object recycling.
My question is, Is recycling the tempList2 arraylist object correct?
I have a List with say size n, and i have to dynamically create n variables ie i want to dynamically create the variables depending upon the size of the list. How can i achieve this?
Say i have List as List year with n elements in it;
then i have to create the n Integer variables from the above list.
thanks.
hello everyone,
Can anyone please tell the way to find out the mac address of a system which is:
1. Shutdown
2. Power plugged in
3. Connected to Lan
4. Nic card ON.
Kindly post the solution as i urgently need it in my project...
thank you
Hello eveyone,
i using elastic in my script.
I have also jQuery Tabs (every will be get over AJAX and content a textarea) and a timer for Saving content all 3 minutes. So some JS code...
I have 2 parts on my site, left and right. On the right side i have 2 tabs (jQuery not AJAX) with each one textarea. And Left side between 5-10 Textareas each in Tab but they gonna be loaded only if Tab is activ (AJAX).
my Problem is:
If i paste a lot of text in a Textarea (1000 characters) the writing get slowed, not fluid, jerky.
It ist 100% the elastic problem, without elastic there no Problem while writing.
Have some one an idea for the solution of this Porblem? Is it Overload?
I am currently stuck with a homework assignment, question below;
Define a default constructor for Deck that initialises the deck field with an array of size 0.
Also define a constructor that takes an integer parameter and initialises the deck field with an array of that size. The constructor should also initialise every element with a new random MovieCard. The cards should be uniquely named.
so far my code is
public class Deck {
MovieCard[] deck = new MovieCard[] {};
public Deck() {
MovieCard deck[];
}
public Deck(int size) {
MovieCard deck = new MovieCard[];
}
}
Obviously this is incomplete by I can't find any references in my previous notes about referring a parameter into an array and setting this as the length.
Is ther any way to get data from other sites and display in our jsp pages dynamically.
http://www.dictionary30.com/meaning/Misty see this url
in that one block is like
Wikipedia Meaning and Definition on 'Misty'
In that block they are fetching the data from Wikipedia and displaying into dictionaly30.
Question:
How they are fetching wiki data to their site.?
I need to display data like that in my jsp page by fetching from other site.
i need to implement a project with visual intimacy between persons,can anyone recommends an algorithm for person's intimacy in phone contact?
intimacy attenuate over time(the intimacy attenuates automatically if you havnt click/dial it for a long time).
Assume in my address book:
Person Intimacy(0-100%)
A 40%
B 80%
C 10%
A's intimacy needs raise after i call A ,like this
Person Intimacy(0-100%)
A 42%
B 80%
C 10%
nothing happens after follow 5 days, A,B,C's intimacy need decline,like this
Person Intimacy(0-100%)
A 37%
B 78%
C 8%
thanks for everyone's answer
This seems like a simple request, but google is not my friend because "partition" scores a bunch of hits in database and filesystem space.
I need to enumerate all partitions of an array of N values (N is constant) into k sub-arrays. The sub-arrays are just that - a starting index and ending index. The overall order of the original array will be preserved.
For example, with N=4 and k=2:
[ | a b c d ] (0, 4)
[ a | b c d ] (1, 3)
[ a b | c d ] (2, 2)
[ a b c | d ] (3, 1)
[ a b c d | ] (4, 0)
I'm pretty sure this isn't an original problem (and no, it's not homework), but I'd like to do it for every k <= N, and it'd be great if the later passes (as k grows) took advantage of earlier results.
If you've got a link, please share.