| Converting a string to an integer |
|
 |
Index ‹ java-programmer
|
- Previous
- 1
- Working with JFrameI Have The Following code to measure how far the mouse has move I can get it
to work for JApplet But not for JFrame how can I get it to work for JFrame?
import java.applet.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class Odometer extends JApplet implements MouseMotionListener,
ActionListener
{
private int td=0;
private int last_x=0;
private int last_y=0;
private Graphics g;
private JPanel extra=new JPanel();
private JButton btn=new JButton("Reset");
private JLabel lbl=new JLabel("");
private JTextField txt=new JTextField(10);
private Container c = getContentPane();
public void init()
{
btn.addActionListener(this);
extra.add(btn);
extra.add(txt);
extra.add(lbl);
c.add(extra);
this.addMouseMotionListener(this);
}
public void mouseMoved(MouseEvent e)
{
double ld=0;
String str;
int x;
int y;
x=e.getX();
y=e.getY();
ld=Math.sqrt((Math.pow(x-last_x,2))+(Math.pow(y-last_y,2)));
str=Double.toString(ld);
td=td+Double.valueOf(str).intValue();
txt.setText(Integer.toString(td));
last_x=x;
last_y=y;
}
public void actionPerformed(ActionEvent e)
{
if(e.getSource()==btn)
{
td=0;
txt.setText(Integer.toString(td));
}
}
public void mouseDragged(MouseEvent e){}
}
- 2
- InputStream is abstract, but...System has a static data member called in which is an InputStream object,
and has a non-abstract read() method - but the read() method of InputStream
is abstract.
Is the answer something to do with it being native code?
- 2
- jsp:include and servletshello,
I have the following problem:
I would like to evacuate the logic from my jsp files in servlets. servlets
provide database contents prepared in HTML tables, the jsp files are
supposed to offer the graphic structure of the intranet application.
how does the path detail have to look?
thats my current include command:
<%@ include file="/proj/mdswpu/classes/ShowList" flush="true" %>
the whole thing is located in the directory webapps/Root/weave INF/classes.
do the path details cause problems or is it due to the servlet? is it no
matter whether doPost or doGet method is used?
the servlet delivers HTML via printwriter.
thank you for the help in advance ....
- 4
- set vm-parameter when converting to jar?!Hello,
I have an application in jbuilder and want to make it into jar file.
my application as an vm-parameter and appearently when i make this jar file
the settings are not set in the jar. how can i do this (in jbuilder)?
thank you very much!!!
Stefan
- 4
- Hibernate: @SecondaryTable causes ORA-00918I have to tables 'first' and 'second':
CREATE TABLE first (
first_id int IDENTITY NOT NULL,
first_value INT NOT NULL,
PRIMARY KEY (first_id)
)
CREATE TABLE second (
second_id int IDENTITY NOT NULL,
first_id int NOT NULL,
second_value INT NOT NULL,
PRIMARY KEY (second_id)
)
I want to join these two tables into one entity using @SecondaryTable.
The columns that are used for joining are named the same in both
tables ('first_id'). Hibernate creates a query like this:
SELECT f_.first_value as first_value_,
s_.secondValue as second_value_
FROM first f_,
second s_
WHERE f_.first_id=s_.first_id(+)
and first_id=?
In the last line Hibernate "forgets" to add a qualifier to 'first_id',
so I get an "ORA-00918: column ambiguously defined" error.
Any ideas?
Thanks,
Ralpe
- 6
- T-SQL print statement ...Hi all,
I have a java app that connects to Sybase using jConnect 6.05
and calls a stored procedure using the CallableInterface.
Any print statement within the stored procedure becomes a
SQLException on the java side???? e.g.
com.sybase.jdbc3.jdbc.SybSQLWarning: Beginning REORG REBUILD
of ...
why if it is a SQLWarning is being thrown as a SQLException?
how can I disable this (very stupid) Sybase behaviour?
- is there anything like "set showoutput off" or disable output session
parameter? or even a jConnect parameter to disable SQLException on
SQLWarning occurrences or whatever?
- Removing the print statements out of my procedure is not enough as
I call some other internal Sybase procedures that also seem to be
printing crap out.
Many thanks in advance,
Best Regards,
Giovanni
- 6
- help my first java programThis is my first attempt at java
here it is
public class Welcome {
public static void main(String[] args){
System.out.println("Welcome to java");
}
}
however when i compile it i get this error
C:\Java>javac Test.java
Test.java:3: package system does not exist
system.out.println("This is a test");
^
1 error
what am i doing wrong
- 7
- How to load a resource from an external jarIf a jar file exists in the classpath, how can I load a resource from
that external jar? Is it different from
"this.getClass().getClassLoader().getResource"?
Thanks in advance!
- 7
- Export HTML table inside JSP to Excel using JavaWhen I generate this table inside this JSP page, it will offer a
button for user to click if he/she decides to export the HTML table
into an Excel sheet (which get displayed directly back in the
browser), then user can save his/her this Excel spreadsheet into his/
her local file system.
Can someone help me on how I can convert this HTML table to Excel
using XSLT? Sample code would really help also, if there's any URL to
refer me to.
Is it a good idea to generate the Excel file (as temporary file which
to be sent back to browser later if user click the button) at the same
time when the HTML table get generated? Then remove this temporary
Excel file later.
Any comments? Thanks,
Jimmy
- 9
- ports/116082: java/linux-sun-jdk16 jconsole is unable toSynopsis: java/linux-sun-jdk16 jconsole is unable to connect to a local process
Responsible-Changed-From-To: freebsd-ports-bugs->java
Responsible-Changed-By: edwin
Responsible-Changed-When: Tue Sep 4 14:20:07 UTC 2007
Responsible-Changed-Why:
Over to maintainer
http://www.freebsd.org/cgi/query-pr.cgi?pr=116082
_______________________________________________
email***@***.com mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-java
To unsubscribe, send any mail to "email***@***.com"
- 9
- Ask the Experts Session on Project GlassFish -- Week of Nov. 14Project GlassFish is Sun's Open Source Application Server, as well as
the implementation of Java EE 5. It's also part of a larger effort by
Sun to release major portions of Sun's code into Open Source for use by
the community. The code for Project GlassFish goes into building Sun's
Application Server PE 9, and the Reference Implementation of Java EE 5.
In this Ask the Experts session, you'll have the opportunity to ask
questions about Project GlassFish, and get answers from Project
GlassFish Manager, Jim Driscoll, and Project GlassFish Community Leads,
Carla Mott, and Amy Roh.
You can post questions about Project GlassFish on the Ask the Experts
page (http://java.sun.com/developer/community/askxprt/index.html)
starting November 14. The session runs through November 18.
- 9
- objects (newbie)I learnt to program in the top down procedural system (assembly). Knowing
when to create a new function was easy. If you kept repeating the same task
then you needed to put it in a subroutine. But I'm a bit confused by all
these classes in Java. What criteria should I use to decide to create a new
class instead of just add a method to my existing class. I can see me
writting code thats basically one big class with lots of methods. I know I
should break it up into smaller classes but cant tell what criteria to use.
Can anyone recommend a book or url for an object orientated approach to
programming?
Thanks in advance
- 12
- Encrypting Java Code
I provide a Web service that is mostly JSP with a few java classes
thrown in. I want to give my customers the ability to down load a
subset of the service's functionality (JSPs) to run offline.
How can I encript the code so that it cannot be reversed engineered?
If it encripted, is there a performance hit?
Thanks
- 14
- mouse button 2 is always meta-modified?I have a program in which I wanted to allow the user
to use either Alt or Meta to indicate the same
modification of a mouse click. When I look at what's
returned by getModifiersEx(), I am surprised to
discover that an unmodified Button2 event produces a
value of 256, which also happens to be the value of
MouseEvent.META_DOWN_MASK. The result is that a plain
Button2 event looks like a Meta-modified one. This
cannot be right; and there is no analogous problem
with Button1, which produces 0 for an unmodified
event. In fact, if I hold down any combination of
Shift, Control, and Alt when clicking Button2, then the
256 bit is _not_ set but the appropriate combination
of others is set. I am on a PC and I do not actually
have a Meta key; but I wanted folks who do have one to
be able to use it in preference to Alt. What's going
on here? Is there a solution to this problem? (In
the meantime, I have just removed my Meta-modifier
option so that I can successfully detect that a Button2
event is unmodified.)
I am using SDK 1.4 under Windows 98.
Regards,
David V.
- 16
- ArrayList Marshalling Question....Hi All,
We are trying to invoke EJB methods on simple stateless session beans
from an Applet running remotely. One of our methods needs to return
an ArrayList of Serializable objects.
We have encoutered the following error: (please see end of post for
stack trace).
Some research has yielded the fact that even though the ArrayList
class in Java implements serializable, the Object[] member is not
serializable, even though the objects that we are putting into the
array are serializable.
Because our applet is REMOTE, we are using RMI-IIOP to access our
Beans which are on iPlanet 6.5.
The beans function properly for all base types and for simple
serilizable objects, but sadly, an ArrayList isn't one of them.
Has anyone else encountered this problem? Suggestions or alternatives
to using the ArrayList class would be appreciated as well.
Thanks in advance...
Omer/John.
--StackTrace--
java.io.IOException: Can't skip sender's custom marshaled class:
RMI:java.util.ArrayList:F655154F32815380:7881D21D99C7619D
at com.sun.corba.se.internal.io.IIOPInputStream.throwExceptionType(Native
Method)
at com.sun.corba.se.internal.io.IIOPInputStream.simpleSkipObject(IIOPInputStream.java:330)
at com.sun.corba.se.internal.io.ValueHandlerImpl.readValueInternal(ValueHandlerImpl.java:235)
at com.sun.corba.se.internal.io.ValueHandlerImpl.readValue(ValueHandlerImpl.java:207)
at com.sun.corba.se.internal.iiop.CDRInputStream.read_value(CDRInputStream.java:1059)
at j2eeguide.converter._Converter_Stub.trouble(_Converter_Stub.java:383)
at j2eeguide.converter.ConverterClient.main(Unknown Source)
Caught an unexpected exception!
java.rmi.MarshalException: CORBA MARSHAL 0 No; nested exception is:
org.omg.CORBA.MARSHAL: Unable to read value from underlying
bridge : Can
't skip sender's custom marshaled class:
RMI:java.util.ArrayList:F655154F3281538
0:7881D21D99C7619D minor code: 0 completed: No
org.omg.CORBA.MARSHAL: Unable to read value from underlying bridge :
Can't skip
sender's custom marshaled class:
RMI:java.util.ArrayList:F655154F32815380:7881D2
1D99C7619D minor code: 0 completed: No
at com.sun.corba.se.internal.iiop.CDRInputStream.read_value(CDRInputStre
am.java:1065)
at j2eeguide.converter._Converter_Stub.trouble(_Converter_Stub.java:383)
at j2eeguide.converter.ConverterClient.main(Unknown Source)
|
| Author |
Message |
jt

|
Posted: 2007-3-25 11:04:00 |
Top |
java-programmer, Converting a string to an integer
<Question>
Why does the NumberFormatException get thrown when the String argument
is not empty?
</Question>
<Background>
I was reading the Sun Tutorial and happened across the section on integers:
http://java.sun.com/docs/books/tutorial/java/nutsandbolts/datatypes.html
I saw the bit on octal and hex representations and thought that I might
be able to take a string containing..oh say "O23" and use the
Integer.parseInt method to convert it to an integer. After all, the
tutorial does say
The prefix 0 indicates octal, whereas 0x indicates hexadecimal.
int decVal = 26; // The number 26, in decimal
int octVal = 032; // The number 26, in octal
int hexVal = 0x1a; // The number 26, in hexadecimal
Here's my code:
package just_playing_around;
public class WillThisWork {
public static void main(String [] args) {
String s = "O23";
int x = Integer.parseInt(s.trim());
System.out.println("s as a string is " + s);
System.out.println("s as an integer is " + x);
}
}
And here's the error I get when I run it
Exception in thread "main" java.lang.NumberFormatException: For input
string: "O23"
at java.lang.NumberFormatException.forInputString(Unknown Source)
at java.lang.Integer.parseInt(Unknown Source)
at java.lang.Integer.parseInt(Unknown Source)
at just_playing_around.WillThisWork.main(WillThisWork.java:6)
</Background>
<Research>
1) I did a google search on cljp and found the following post
http://groups.google.ca/group/comp.lang.java.programmer/browse_thread/thread/bc297073502432fa/d7610d111ecc7ceb?lnk=st&q=java.lang.Integer.parseInt(Unknown+Source)&rnum=7&hl=en#d7610d111ecc7ceb
If you will notice Patricia's post
I think this is the critical data. It claims that there was an
Integer.parseInt call on line 72 with the empty string as input.
Does that make sense?
Patricia
2) I tried to eliminate the probable causes of the "empty string" in
the following sequence
2a) I removed the parseInt and print for x from my code.
package just_playing_around;
public class WillThisWork {
public static void main(String [] args) {
String s = "O23";
// int x = Integer.parseInt(s.trim());
System.out.println("s as a string is " + s);
// System.out.println("s as an integer is " + x);
}
}
s as a string is O23
2b) In the same program, I did the trim and assigned the value to a new
string so that I could see what the result of the string was without
disturbing the original. I also added a comparison to see if indeed
both strings were the same.
package just_playing_around;
public class WillThisWork {
public static void main(String [] args) {
String s = "O23";
String y = s.trim();
System.out.println("s as a string is " + s);
System.out.println("y as a string is " + y);
if (s.equals(y))
{
System.out.println("They are the same");
}
else
{
System.out.println("They are different");
}
}
}
s as a string is O23
y as a string is O23
They are the same
<Research>
<Theory>
Either the runtime error I am getting is misleading (see Research.1> or
the runtime error is pointing me to something else, something more
insidious.
</Theory>
<Followup>
Where am I going wrong? Did I mis-read something somewhere or is what I
am trying to do just not do-able using the tools I have available to me
right now?
</Followup>
Thanks for your help
|
| |
|
| |
 |
ram

|
Posted: 2007-3-25 11:11:00 |
Top |
java-programmer >> Converting a string to an integer
jt <email***@***.com> writes:
>O23
This starts with the letter 籓?
>032
This starts with the digit ??
|
| |
|
| |
 |
jt

|
Posted: 2007-3-25 11:14:00 |
Top |
java-programmer >> Converting a string to an integer
Stefan Ram wrote:
> jt <email***@***.com> writes:
>> O23
>
> This starts with the letter 籓?
>
>> 032
>
> This starts with the digit ??
>
Yes I know that. My code shows:
String s = "O23";
which is the letter O... O23 is the octal number. 023 (number 0) would
simply be 23.
|
| |
|
| |
 |
ram

|
Posted: 2007-3-25 11:26:00 |
Top |
java-programmer >> Converting a string to an integer
jt <email***@***.com> writes:
>which is the letter O... O23 is the octal number. 023 (number 0) would
>simply be 23.
In source code, ?23?is an octal numeral. The method
http://download.java.net/jdk7/docs/api/java/lang/Integer.html#parseInt(java.lang.String)
only parses decimal numerals, Try
http://download.java.net/jdk7/docs/api/java/lang/Integer.html#decode(java.lang.String)
with ?23?
|
| |
|
| |
 |
jt

|
Posted: 2007-3-25 11:29:00 |
Top |
java-programmer >> Converting a string to an integer
Stefan Ram wrote:
> jt <email***@***.com> writes:
>> which is the letter O... O23 is the octal number. 023 (number 0) would
>> simply be 23.
>
> In source code, ?23?is an octal numeral. The method
>
> http://download.java.net/jdk7/docs/api/java/lang/Integer.html#parseInt(java.lang.String)
>
> only parses decimal numerals, Try
>
> http://download.java.net/jdk7/docs/api/java/lang/Integer.html#decode(java.lang.String)
>
> with ?23?
>
Ahh... now I understand. So why did the program even compile in the
first place? I'm using Eclipse 3.2 and jdk 1.6
Is this one of those cases where Java doesn't pay attention to what you
are trying to do until you try to run the code?
|
| |
|
| |
 |
jt

|
Posted: 2007-3-25 11:36:00 |
Top |
java-programmer >> Converting a string to an integer
Stefan Ram wrote:
> jt <email***@***.com> writes:
>> which is the letter O... O23 is the octal number. 023 (number 0) would
>> simply be 23.
>
> In source code, ?23?is an octal numeral. The method
>
> http://download.java.net/jdk7/docs/api/java/lang/Integer.html#parseInt(java.lang.String)
>
> only parses decimal numerals, Try
>
> http://download.java.net/jdk7/docs/api/java/lang/Integer.html#decode(java.lang.String)
>
> with ?23?
>
I can't find the decode method in the API for jdk1.6 Is a new feature
added to jdk7?
|
| |
|
| |
 |
Andrew Thompson

|
Posted: 2007-3-25 11:57:00 |
Top |
java-programmer >> Converting a string to an integer
On Mar 25, 1:36 pm, jt <email***@***.com> wrote:
> Stefan Ram wrote:
...
> >http://download.java.net/jdk7/docs/api/java/lang/Integer.html#decode(...)
...
> I can't find the decode method in the API for jdk1.6 Is a new feature
> added to jdk7?
No, AFAIU it was introduced in 1.0.
Here it is in the *1.5* docs ..
<http://java.sun.com/j2se/1.5.0/docs/api/java/lang/
Integer.html#decode(java.lang.String)>
I would have put a link to an even earlier
version of the JavaDocs, but I don't know
of any URL's for the earlier JDocs.
Andrew T.
|
| |
|
| |
 |
starf

|
Posted: 2007-3-25 12:15:00 |
Top |
java-programmer >> Converting a string to an integer
On 3鏈?5鏃? 涓婂崍11鏃?9鍒? jt <email***@***.com> wrote:
> Stefan Ram wrote:
> > jt <email***@***.com> writes:
> >> which is the letter O... O23 is the octal number. 聽023 (number 0) would
> >> simply be 23.
>
> > 聽 In source code, 禄023芦 is an octal numeral. The method
>
> >http://download.java.net/jdk7/docs/api/java/lang/Integer.html#parseIn...)
>
> > 聽 only parses decimal numerals, Try
>
> >http://download.java.net/jdk7/docs/api/java/lang/Integer.html#decode(...)
>
> > 聽 with 禄023芦.
>
> Ahh... now I understand. 聽So why did the program even compile in the
> first place? 聽I'm using Eclipse 3.2 and jdk 1.6
> Is this one of those cases where Java doesn't pay attention to what you
> are trying to do until you try to run the code?
just like 1/0 can not be realized. this error should be caught in the
runtime.
|
| |
|
| |
 |
jt

|
Posted: 2007-3-25 12:26:00 |
Top |
java-programmer >> Converting a string to an integer
Andrew Thompson wrote:
> On Mar 25, 1:36 pm, jt <email***@***.com> wrote:
>> Stefan Ram wrote:
> ...
>>> http://download.java.net/jdk7/docs/api/java/lang/Integer.html#decode(...)
> ...
>> I can't find the decode method in the API for jdk1.6 Is a new feature
>> added to jdk7?
>
> No, AFAIU it was introduced in 1.0.
>
> Here it is in the *1.5* docs ..
> <http://java.sun.com/j2se/1.5.0/docs/api/java/lang/
> Integer.html#decode(java.lang.String)>
> I would have put a link to an even earlier
> version of the JavaDocs, but I don't know
> of any URL's for the earlier JDocs.
>
> Andrew T.
>
Shoot... it's an Integer not an int. Sorry Andrew.
|
| |
|
| |
 |
Andrew Thompson

|
Posted: 2007-3-25 12:35:00 |
Top |
java-programmer >> Converting a string to an integer
On Mar 25, 2:25 pm, jt <email***@***.com> wrote:
> Andrew Thompson wrote:
> > On Mar 25, 1:36 pm, jt <email***@***.com> wrote:
> >> Stefan Ram wrote:
> > ...
> >>>http://download.java.net/jdk7/docs/api/java/lang/Integer.html#decode(...)
> > ...
> >> I can't find the decode method in the API for jdk1.6 Is a new feature
> >> added to jdk7?
>
> > No, AFAIU it was introduced in 1.0.
...
> Shoot... it's an Integer not an int. Sorry Andrew.
No need for apologies, but could I ask that
you refrain from 'full-quoting' in future?
Note that in my reply, I trimmed most of my
earlier text (which was no longer relevant)
as well as my 'signature' at the bottom of
my first post (if people are that interested
in 'who said what', they can read it in the
lines like 'Bob wrote:'/'Stefan wrote:'..).
This helps reduce the bandwidth that others
reading the group (who may not even be following
this thread) have to get in order to read
the group. It is a courtesy to spare them
the unnecessary bytes.
(And, preemptively, an assurance of 'will do'
is far preferable to any form of apology.)
Andrew T.
|
| |
|
| |
 |
printdude1968@gmail.com

|
Posted: 2007-3-25 13:24:00 |
Top |
java-programmer >> Converting a string to an integer
On Mar 25, 1:34 am, "Andrew Thompson" <email***@***.com> wrote:
will do
|
| |
|
| |
 |
jt

|
Posted: 2007-3-26 8:42:00 |
Top |
java-programmer >> Converting a string to an integer
Andrew Thompson wrote: a bunch of stuff that I have committed to memory
Hi Andrew,
I finally figured out what I did wrong.
When I read the java docs, I didn't see the connection
http://download.java.net/jdk7/docs/api/java/lang/Integer.html#decode(java.lang.String)
The sequence of characters following an optional sign and/or radix
specifier ("0x", "0X", "#", or leading zero) is parsed as by the
Integer.parseInt method with the indicated radix (10, 16, or 8). This
sequence of characters must represent a positive value or a
NumberFormatException will be thrown. The result is negated if first
character of the specified String is the minus sign. No whitespace
characters are permitted in the String.
"leading zero" is the way that octal is represented. I was assuming
that it was a O (capital letter O) rather than a 0 zero.
If I had been reading more closely, I would have seen the paragraph above it
Decodes a String into an Integer. Accepts decimal, hexadecimal, and
octal numbers given by the following grammar:
DecodableString:
Signopt DecimalNumeral
Signopt 0x HexDigits
Signopt 0X HexDigits
Signopt # HexDigits
Signopt 0 OctalDigits
Sign:
-
+
which should have given me the hint that I needed.
Anyway... thanks for the help. My conversion program
<SSCCE>
public class WillThisWork {
public static void main(String [] args) {
String s = "023";
String y = s.trim();
Integer x = java.lang.Integer.decode(y);
System.out.println("s as a string is " + s);
System.out.println("y as a string is " + y);
if (s.equals(y))
{
System.out.println("They are the same");
}
else
{
System.out.println("They are different");
}
System.out.println("Now see what x is " + x);
}
}
</SSCCE>
Is now working the way I expected it to.
s as a string is 023
y as a string is 023
They are the same
Now see what x is 19
I know that this is probably a silly question, but if I import
java.lang.Integer.* why do I still have to fully qualify decode()? Is
it because it's a static method and MUST be fully qualified?
Note: I'm not far enough in the Java Tutorial to answer this question
so that's the only reason I'm asking you...
|
| |
|
| |
 |
Jeff Higgins

|
Posted: 2007-3-26 9:18:00 |
Top |
java-programmer >> Converting a string to an integer
jt wrote:
import static java.lang.Integer.*;
> public class WillThisWork {
> public static void main(String [] args) {
> String s = "023";
> String y = s.trim();
> Integer x = java.lang.Integer.decode(y);
Integer x = decode(y);
> System.out.println("s as a string is " + s);
> System.out.println("y as a string is " + y);
> if (s.equals(y))
> {
> System.out.println("They are the same");
> }
> else
> {
> System.out.println("They are different");
> }
> System.out.println("Now see what x is " + x);
> }
> }
>
> I know that this is probably a silly question, but if I import
> java.lang.Integer.* why do I still have to fully qualify decode()? Is it
> because it's a static method and MUST be fully qualified?
> Note: I'm not far enough in the Java Tutorial to answer this question so
> that's the only reason I'm asking you...
http://www.cafeaulait.org/course/week4/31.html
http://java.sun.com/j2se/1.5.0/docs/guide/language/static-import.html
>
|
| |
|
| |
 |
Andrew Thompson

|
Posted: 2007-3-26 9:46:00 |
Top |
java-programmer >> Converting a string to an integer
On Mar 26, 10:41 am, jt <email***@***.com> wrote:
> Andrew Thompson wrote: a bunch of stuff that I have committed to memory
Wow! I may ask you to repeat it back to me at
some later date, because to be honest, I would
have to reread the thread before I could recall
what I said!
( I Hope I did not use any swear words ;)
..
> ...No whitespace
> characters are permitted in the String.
Uh-huh. I saw something in your code further
down that made me wonder if you had correctly
interpreted what a 'white space character' is.. *
> "leading zero" is the way that octal is represented. I was assuming
> that it was a O (capital letter O) rather than a 0 zero.
Damn, I wish I was using a font that showed
a difference, those O/0 look identical on this
box/config.
> <SSCCE>
> public class WillThisWork {
> public static void main(String [] args) {
> String s = "023";
* the '0' will not be considered a 'white space char.',
the things that would be considered white space might
be summed up as..
<sscce>
import javax.swing.*;
class ShowWhiteSpace {
public static void main(String[] args) {
// sure I've forgotten some..
String untrimmed = "\t 01234Hi! \n\n ";
String trimmed = untrimmed.trim();
JTextArea ta = new JTextArea(
"untrimmed: \t'" + untrimmed + "'\n" +
"trimmed: \t'" + trimmed + "'"
);
JOptionPane.showMessageDialog(null, ta);
}
}
</sscce>
...
> I know that this is probably a silly question, but if I import
> java.lang.Integer.*
Assuming you meant..
import java.lang.Integer.*;
..that is a compilable, but invalid, statement.
The ones that would have the right effect are either ..
import java.lang.Integer;
..or..
import java.lang.*;
The '*' character can import into the namespace,
all classes within a particular package, as done
in the second statement.
The first statement is preferable* though, as
it is an explicit import for the one required
class, and is better documented as a result.
Importing the class (using either form) will
automatically make *all* it's methods available.
* I usually use package imports in SSCCE's,
for the sake of brevity, but it should not
generally be done in 'real' or production
code.
HTH
Andrew T.
|
| |
|
| |
 |
jt

|
Posted: 2007-3-27 21:10:00 |
Top |
java-programmer >> Converting a string to an integer
Andrew Thompson wrote:
> On Mar 26, 10:41 am, jt <email***@***.com> wrote:
>> Andrew Thompson wrote: a bunch of stuff that I have committed to memory
>
> Wow! I may ask you to repeat it back to me at
> some later date, because to be honest, I would
> have to reread the thread before I could recall
> what I said!
> ( I Hope I did not use any swear words ;)
>
No, AFAIU it was introduced in 1.0.
Here it is in the *1.5* docs ..
<http://java.sun.com/j2se/1.5.0/docs/api/java/lang/
Integer.html#decode(java.lang.String)>
I would have put a link to an even earlier
version of the JavaDocs, but I don't know
of any URL's for the earlier JDocs.
Andrew T.
|
| |
|
| |
 |
Oliver Wong

|
Posted: 2007-3-28 4:45:00 |
Top |
java-programmer >> Converting a string to an integer
"jt" <email***@***.com> wrote in message
news:p0mNh.14842$email***@***.com...
> Stefan Ram wrote:
>> jt <email***@***.com> writes:
>>> which is the letter O... O23 is the octal number. 023 (number 0)
>>> would simply be 23.
>>
>> In source code, ?23?is an octal numeral. The method
>>
>> http://download.java.net/jdk7/docs/api/java/lang/Integer.html#parseInt(java.lang.String)
>>
>> only parses decimal numerals, Try
>>
>> http://download.java.net/jdk7/docs/api/java/lang/Integer.html#decode(java.lang.String)
>>
>> with ?23?
>>
> Ahh... now I understand. So why did the program even compile in the
> first place? I'm using Eclipse 3.2 and jdk 1.6
> Is this one of those cases where Java doesn't pay attention to what you
> are trying to do until you try to run the code?
It's more like a case of Java not actually executing methods until you
actually run them. The method java.lang.Integer.parseInt(java.lang.String)
has a certain behaviour. Specifically, if you pass it the string "023", it
will return 23, and if you pass the string "O23", it will throw a
NumberFormatException. But the method does these things when the method
actually runs, not when you compile it.
This is similar to the concept that System.out.println("Hello world!")
will print out "Hello world!" to your console when that method actually
runs, and not when you compile the program.
- Oliver
|
| |
|
| |
 |
| |
 |
Index ‹ java-programmer |
- Next
- 1
- java LookAndFeelHi,
What is the easiest way to change the default font that is used
throughout your application. My client has complained that the font is
too small. Eveything I use is the default LookAndFeel and I don't want
to have to play around too much. Is there a simple way to just change
the font size so that JLabel, JTextField etc. will use the larger font
by default?
Thanks,
Lionel.
- 2
- Secure PackagesIs it possible to make packages with non-class files (say, a folder,
or Stuffit archive) that are accessible only to a class file within
the package? Could it be set up so that even a UNIX root user wouldn't
be able to access the files? Would it be necessary to encrypt the
files (and use a Java class to decrypt them) and if so, how? Sorry for
my inexperience here. I'm really kind a beginner at Java programming,
but I need some of these functions for the program I'm writing so...
*shrug* Thanks in advance for any help!
- 3
- Printing of stored documentsHi, I want to print serveral documents (pdfs, jpegs, rtfs) which are
stored as blobs in a database. A webpage presents the information
about all the related documents and now I want to print them at once
(at the moment, the user picks up every document and print it). Who
knows, how to do this comfortably?
Best regards
Peter
- 4
- Media types available in MIDP2.0Hi. I'm writing a MIDP2.0/CLDC1.1 app, and i'm trying to work out if
which devices support playback of mp3 files from java.
Does anyone know if there is any way of enumerating the available media
types (e.g. 'audio/x-wav') available on a device?
Or failing that, whats the MIME type for an mp3? And has anyone got
MIDP to play mp3.
Cheers!
Boris
- 5
- Free java source code"Jacob" <email***@***.com> wrote in message news:email***@***.com...
> Initial set of utility source code is
> released (LGPL) at http://geosoft.no/software
>
> Feedback is appreciated.
>
> Thanks.
Never use GNU licenses. They are all viral and
contaminate whatever they touch. Very similar
to the "Bog of Eternal Stench". Look at the
other open source licenses for a better alternative.
- 6
- How is your Health? Barter needed <>08>---?
http://www.youtube.com/watch?v=2tr_nqvCzqo
Thank you
http://mail.google.com/mail/?ui=2&ik=fe78bf8dd7&view=lg&msg=11a06c31608f8d28
- 7
- java error in apache tomcatguys,
I am getting an java error when i run a java app in tomcat. here it is
what I get in the browser
-----------------------
type Exception report
message
description The server encountered an internal error () that prevented
it from fulfilling this request.
exception
javax.servlet.ServletException: Servlet execution threw an exception
com.unanet.servlet.GzipFilter.doFilter(GzipFilter.java:39)
com.unanet.servlet.AccessLogFilter.doFilter(AccessLogFilter.java:43)
root cause
java.lang.NoClassDefFoundError
com.unanet.servlet.Unanet.validateDatabaseVersion(Unanet.java:833)
com.unanet.servlet.Unanet.validateDatabaseVersion(Unanet.java:777)
com.unanet.servlet.ActionServlet.doService(ActionServlet.java:64)
com.unanet.servlet.ActionServlet.doGet(ActionServlet.java:31)
javax.servlet.http.HttpServlet.service(HttpServlet.java:689)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
com.unanet.servlet.GzipFilter.doFilter(GzipFilter.java:39)
com.unanet.servlet.AccessLogFilter.doFilter(AccessLogFilter.java:43)
-------------------------------
can some one please help.
RTR
- 8
- Fatal error: mutex is on listHello all,
I received this fatal error using jdk build
1.5.0-p1-root_12_may_2005_13_14 with -current from Mon May 23 10:32:18
EEST 2005:
Fatal error 'mutex is on list' at line 540 in file
/usr/src/lib/libpthread/thread/thr_mutex.c (errno = 0)
Here is a backtrace:
(gdb) bt
#0 0x280b0bf7 in pthread_testcancel () from /usr/lib/libpthread.so.1
#1 0x280a03ff in sigaction () from /usr/lib/libpthread.so.1
#2 0x2809969d in pthread_kill () from /usr/lib/libpthread.so.1
#3 0x28098fdf in raise () from /usr/lib/libpthread.so.1
#4 0x28198eda in abort () from /lib/libc.so.6
#5 0x280b2781 in pthread_testcancel () from /usr/lib/libpthread.so.1
#6 0x280a431b in _pthread_mutex_trylock () from /usr/lib/libpthread.so.1
#7 0x280a582a in pthread_mutex_lock () from /usr/lib/libpthread.so.1
#8 0x28532ca6 in OSThread::pd_initialize () from
/usr/local/jdk1.5.0/jre/lib/i386/client/libjvm.so
#9 0x28532a4d in OSThread::OSThread () from
/usr/local/jdk1.5.0/jre/lib/i386/client/libjvm.so
#10 0x2853438e in os::create_thread () from
/usr/local/jdk1.5.0/jre/lib/i386/client/libjvm.so
#11 0x28594666 in JavaThread::JavaThread () from
/usr/local/jdk1.5.0/jre/lib/i386/client/libjvm.so
#12 0x2848b0e6 in JVM_StartThread () from
/usr/local/jdk1.5.0/jre/lib/i386/client/libjvm.so
#13 0x2b121c09 in ?? ()
Please contact me if you need more details.
Thanks,
Dan
- 9
- AppletContextHi,
I'm a bit of a newbie to java so any help would be gratefully appreciated.
I have a java applet which displays a graph depending on whther there a
more nodes in the hierarchy
you can navigate the graph to you get to a leaf node (no more nodes).
If I click on a leaf node it is supposed to pass a product Id to a php
script in another frame.
I understand the showDocument method of AppletContext will do this with the
following parameters . .
showDocument(node.url, TARGET)
where TARGET = framename.
But I'm not really sure about the URL parameter.
If it is all the same webpage why is this necessary ?
What should I put in here ? my website address ?
definitely not clear on this.
- 10
- public class1) Why a public class whould be stored in a file have the same name as
that of class? Is there any reason for doing this?
ex -- Test.java
- 11
- passing a Factory to a method to create a generic instanceTom Anderson wrote:
> I'm thinking there would be a defined constructor signature that would
> be used (as implied in my code). There wouldn't be any need to choose
> between options.
How many guest are allowed one room? Two? Three? Four? Five?
public class Room
{
public Room( String guest1, String guest2 ) {}
public Room( String guest1, String guest2, String guest2 ) {}
public Room( String guest1, String guest2, String guest2, String
guest2 ) {}
public Room( String guest1, String guest2, String guest2, String
guest2, String guest2 ) {}
}
Now what if you the hotel very suddenly has to put six or seven in one
room for a large convention? And you've got several subclasses of Room?
And what if next week they want to put 8 in one room?
POJO is good, but any design paradigm can be taken too far. Mutable
objects with getters and setters have their place too, and are very
practical most of the time.
One thing you might want consider:
public ImmutableRoomView
{
public ImmutableRoomView( Room r ) {}
}
Now we have a POJO object that uses our bean as builder.
> As an aside, does the introduction of generics, and the way they're used
> by Class, mean that something along the lines of a constructor interface
> would be useful? Before generics, even if had been was a way to require
> that all implementations of an interface declared a specified
> constructor, there was no way to make use of it - you call a constructor
> using an explicit type literal, where polymorphism doesn't come into
> play, or via reflection, where there's no type safety anyway. Can we use
I'm not sure. There's no run time type for generics or parameterized
types, so I'm not sure how you'd detect the generic information.
>> Then a series of getters and setters will configure the class. While
>> there's other ways to do this (Serializable, for example), assuming
>> setters seems the easiest way of reading a class from a arbitrary
>> format. You just assume each data item has a corresponding setter, a
>> simple 1-to-1 mapping.
>
> Hang on, i thought you were configuring the class through
> AssignmentLoadable.load? This sounds like you've gone reflective.
Good point. assignmentLoad() would have access to the class's private
fields. I'm used to thinking about beans and Swing objects.
> I know that in correct use, you'll go straight from instantiation to
> initialisation, so the period of Room-that-is-not-a-room is vanishingly
> small, and no danger can occur. The problem arises when the use is
> incorrect, and uninitialised Rooms can escape to unwitting code. In our
> discussion of operator overloading, you said "I like to design things
> that can't fail" - where failure is completely impossible by design.
> That's what i'm trying to get at here.
See the builder example above, and Lew's point about using builder
objects and throwing errors.
If possible, an object should be constructed in a legal state. If not,
you'll have to check for errors at runtime. As long as this is
encapsulated in the class, it's still safe.
public void addGuest( String name ) {
if( number == 0 || floor == 0 || beds ==0 ) {
throw new RuntimeException( "You blew it pal." );
}
// ..
Now you can't add a guest to an uninitialized room.
- 12
- ANT MultipleChoiceInputRequestI have a target that checks if backup directories exist and if so, it
asks the user for input. I'd like to minimize the amount of typing the
user has to do and present the user with a list of choices that they
can just enter the number of the option they want.
Using the default inputhandler works fine, but it's not very elegant.
I've read (very little) about
org.apache.tools.ant.input.MultipleChoiceInputRequest, but I can't
find anything on the Internet or in the manual. I'd like to see how
this works, as I may need to use this elsewhere. Anyone ever tried it?
I'm using Ant 1.5.1 on Windows 2000.
Jon
email***@***.com
--- Begin sample code ---
<target name="restore">
... Code to check for backup goes here ...
<input
message="Please select the backup directory to restore:
backup, backup1, backup2 "
validargs="backup,backup1,backup2"
addproperty="do.backup"
/>
<antcall target="restore-backup" />
</target>
<target name="restore-backup" >
... Code to restore do.backup goes here ...
</target>
--- End sample code ---
- 13
- CMP without entity beans ?Hi everyone,
I will soon be working on a EJB 2.1 legacy application (running on
JBoss), so i've started studying "JBoss at work, a practial guide".
In this book, the CMP chapter uses Hibernate ((using .HAR archives)
instead of Entity Beans. As far as I understand, this feature is
specific to JBoss, maybe because Entity Beans are implemented with
Hibernate.
I have the 2 following questions :
- Is the same behavior possible on other application servers ? (ie :
CMP with Hibernate instead of Entity Beans ?)
- Let's say I want to use another persistence strategy (ex : Ibatis or
straight JDBC), can I still use CMP ?
Thanks for helping !
- 14
- more than 1.6GB ramHi
I am new to this group.
I run a java program on windows 2000 and
it currently uses about 1.6GB of ram, but it
cant go past that - i.e the machine has 4GB
and I want to utilise it all, but my mx setting wont
go beyong the 1.6GB
Any one had any simialr issues
Does any know if tiger resolves this?
I currently use 1.4
Regards
SP
- 15
|
|
|