|
st[1] is object of type Student, not a String. You should have toString() method within your Student class
public String toString()
{
return "Name: " + name + ", " + family + " ID:" + studentId + "
}
Than use simply use
System.out.println(st[1].toString());
It will start printing the student information.
|
|
|
|
|
Shivamkalra wrote: st[1] is object of type Student, not a String
Which wouldn't stop it from using the default toString() method which would print something.
|
|
|
|
|
perfect answer!
@ future3839
just a short note: your code looks really good, clean and well structured. One small point I noticed is the package declaration: package array; . It would be more appropriate to use a longer declaration like package au.future3839.school.arrays; . this would define your package clearly as your package, otherwise you could get into trouble when having a lucky hit on a predefined package.
regards
Torsten
I never finish anyth...
|
|
|
|
|
future3839 wrote: System.out.println(st[1]);
Presumably you are using the standard Sun/Oracle VM. If not then you need to specify what you are using.
Modify this line so it prints something such, for example.
System.out.println("student 1= " + st[1]);
There are two possibilities.
1. Your program still prints nothing. Thus you are not running the code you think you are.
2. It prints the text but not else. That suggests you have a toString() method in the class that prints nothing.
|
|
|
|
|
If I run your code I get the following output:
testing.BaseTest$Student@1ad77a7
However, If I take Shivamkalra's advice and add a ToString() method to the Student class such as:
public String toString()
{
return "Name: " + name + ", " + family + " ID:" + studentId + "
}
I get the following output:
Name: ZZZ, WWW ID:3800
I must get a clever new signature for 2011.
|
|
|
|
|
st[1] is a object,not primitive type.So it need a print method.
from china
|
|
|
|
|
Hello
I am a beginner and practicing; I installed Netbeans and glassfish v3. then I went to file/new project and chose JavaEE/Enterprise application.in Servlet and setting option I add Glassfish but the finish buttun still disable.
do I have to do some setting for glassfish? do you have any ideas?
thanks
|
|
|
|
|
|
Hi,
I am searching one function to convert PDU formate to String in java
help me
Regards
Ashish Lad
|
|
|
|
|
And what is PDU format?
I must get a clever new signature for 2011.
|
|
|
|
|
I know PDU just as a Protocol Data Unit[^]
is this what you're thinking about?
And please explain your problem some more.
regards
Torsten
I never finish anyth...
|
|
|
|
|
Hello All,
I have created a simple Web Service in Java, which has only one class containing 4 functions, Add, Subtract, Multiply and Divide. Now I want to publish this Web Service on Tomcat Server. I am able to do it on my Localhost through Eclipse.
Can please any one tell me how should I deploy this web service as a WAR on different server and how can I access this from another server/client. In short, where I can get the URL of the web service.
Any help in this regard is appreciated.
--Thanks
Sameer
|
|
|
|
|
|
Hello,
I need to know hot to use shift operators << and >> in Java with float and double types. I tried to use them but I got compile error. I needed it for serialization data e.g. sending over the streams.
|
|
|
|
|
I do not think that Java streams allow these operators, << and >> are shift operators which is why you get compile errors.
I must get a clever new signature for 2011.
|
|
|
|
|
Both Double and Float support the longValue() method which will return you a long primitive (if it's in the range of long). The other option for bit manipulation is to use the toHexString() method on Double or Float .
|
|
|
|
|
This may be a dumb question but what does bit shifting have to do with serialization? Why would you need to shift the bits in a double value in order to send it over a stream?
|
|
|
|
|
I think the OP is getting confused with the stream operators of C++.
I must get a clever new signature for 2011.
|
|
|
|
|
|
I'm assuming that you want to use the bit-representation of the floating point value with the shift operators to create a float from a byte-stream, and vice-versa
The java Float class (here[^]) contains functions:
floatToIntBits , floatToRawIntBits -- Convert from a float to an integer containing the float value's bit representation
intBitsToFloat : Converts an integer value (containing a float value's bit representation) to a Float variable.
So basically you can do something like:
byte[] data = ...;
int rdInt = data[0] | (data[1] << 8) | (data[2] << 16) | (data[3] << 24);
float rdFloat = Float.intBitsToFloat(rdInt);
... And do the opposite to convert back from float to bytes.
"It was when I found out I could make mistakes that I knew I was on to something."
-Ornette Coleman
"Philosophy is a study that lets us be unhappy more intelligently."
-Anon.
|
|
|
|
|
Hi,
I installed Netbeans 6.9 and try to work on Java. at first glance I faced 2 questions?
when you open new project you see Java and java EE. what is the problem between them? what the meaning of enterprise Application?
I would please if some one who has experience help me in this matter.
|
|
|
|
|
Try the Java home page for more information on the different versions.
I must get a clever new signature for 2011.
|
|
|
|
|
'at a glance' is the keyword: Java EE at a glance[^]
Java EE @ Wikipedia[^]
So a Java-Project - is a general Java Application of some kind (not further defined).
A Java EE Project is a more specified project with predefined libraries - short and really brief described. Java EE is the counterpart to Microsoft's .net. It's used for advanced projects.
regards
Torsten
I never finish anyth...
|
|
|
|
|
java ee refers to the java enterprise edition, it's a platform for web development.
java usually refers to java standard edition,suitable for develope the basic project like swing, gui.
from china
My QQ: 233357374
|
|
|
|
|
I have this code for to create file in directory.
public class Coba {
public static void main(String[] args)throws IOException {
Writer writer = null;
try{
String text = "apa kabar";
File f = new File("d:/azhar.txt");
writer = new BufferedWriter(new FileWriter(f));
writer.write(text);
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} finally {
try {
if (writer != null) {
writer.close();
}
} catch (IOException e) {
e.printStackTrace();
}
}
System.out.println("file has been created in directori");
}
}
i want to ask ? how to when i run code mentioned, file in directory open automatically..anyone to help me please ??
|
|
|
|