| Why Java's math expression (power) is so inconvenient and error prone? |
|
 |
Index ‹ java-programmer
|
- Previous
- 1
- HTTPConnection - verbose error messagesI have a java application that polls an asp page for the purpose of
inserting to a data base. I am interested in seeing verbose (ie
unfriendly HTTP error messages) when there is an internal server error
(code 500). Below is the code snippet that makes the application's web
connection and captures the response messages.
String user = "";
//String user = "Someone";
try{//create url object
urlWithQueryString =
"http://www.someaddress.com/lpt/lpt_login.asp?User=" + user +
"&FName=Alonzo&LName=Garbonzo&timeStamp=20060110_1106";
System.err.println("urlWithQueryString ln 35: " +
urlWithQueryString);
url = new URL(urlWithQueryString);
}catch(MalformedURLException mURLE){
System.err.println( "MalformedURLException thrown in WriteToWebDB: ln
41 " + mURLE.getMessage() );
System.err.println("");
return NetworkStatus.NETWORK_CONNECTION_PROBLEM;
}
try{//open connection. Write data succeeds or fails here
connection = (HttpURLConnection)url.openConnection();
inputStream = connection.getInputStream();
connection.setInstanceFollowRedirects(true);
}catch(IOException iOE1){
try{
System.err.println( "IOException caught in WriteToWebDB: ln 52");
System.err.println("Connection response code ln 53: " +
connection.getResponseCode());
System.err.println("Connection message ln 54: " +
connection.getResponseMessage());
System.err.println("Exception message ln 55: " + iOE1.getMessage());
}catch(IOException iOE){System.err.println("IOException caught ln 56"
+ iOE.getMessage());}
return NetworkStatus.NETWORK_CONNECTION_PROBLEM;
}
********************************************
Below are three examples of server output - the first two have
defective connection strings to force server error and one is a good
connection string that inserts to the data base. Note that defective
string passed from the application returns an error message without
much information while the defective string passed from a browser
returns a verbose and detailed error message. Can anyone help in
discovering a way to recover verbose detailed error messages in the
java application? Any help is greatly appreciated.
Guy Sussman
********************************************
Web server output to application connection when String user = ""
urlWithQueryString ln 35:
http://www.guysussman.com/lpt/lpt_login.asp?User=&FName=Alonzo&LName=Garbonzo&timeStamp=20060110_1106
IOException caught in WriteToWebDB: ln 52
Connection response code ln 53: 500
Connection message ln 54: Internal Server Error
Exception message ln 55: Server returned HTTP response code: 500 for
URL:
http://www.guysussman.com/lpt/lpt_login.asp?User=&FName=Alonzo&LName=Garbonzo&timeStamp=20060110_1106
********************************************
Web server output to browser connection when String user = ""
Microsoft OLE DB Provider for ODBC Drivers error '80004005'
[Microsoft][ODBC Microsoft Access Driver] Field 'tbl_test.Usr' cannot
be a zero-length string.
/lpt/lpt_login.asp, line 25
********************************************
Web server output to application connection when String user =
"Someone"
urlWithQueryString ln 35:
http://www.guysussman.com/lpt/lpt_login.asp?User=Someone&FName=Alonzo&LName=Garbonzo&timeStamp=20060110_1106
Http connection status (WriteToWebDB ln.69): OK ResponseCode = 200
********************************************
- 1
- Add pps or flash or dat to java app.Do any one knows how 2 add pps or flash or video to java application?If
u know plz sent me a sample sourse code to my mail with needed
libraries.
<email***@***.com>
- 1
- CachedRowSet and double column typesHi, there,
I have a CachedRowSet obtained from Sun's CachedRowSetImpl and I'm
trying to use it with a MySql database. I have a table test that has
the basic column types. If I use a plain double column type and I have
to update a row with the double field having the fraction part
something like 1/3 (i.e. 0.3333....), then the acceptChanges fails with
the error
javax.sql.rowset.spi.SyncProviderException: 1 conflicts while
synchronizing
If I have a double(12,2) column type or the like (i.e. I limit the
precision) or if I have a fixed fraction part (something like 0.5,
let's say), then acceptChanges works fine.
I havent logged the sqls generated by the acceptChanges of the
CachedRowSetImpl, but I remember encountering something similar on some
different software components and what was happening in that case (and
I suppose it's happen in this case too) is that the sqls generated were
trying to find the original row using all the fields in the row and not
only the primary key, as it should be the case, i.e. there was
something like :
update test set f1=x1, f2=x2, f3=x3 where f1=y1 and f2=y2 and f3=y3
Now, since there's that "unlimited" number of digits after the decimal
point, it wouldnt have found the original record (maybe because there
was a different number of digits used to represent the same number on
the MySql server and on the MySql client).
My question - is there a way to tell CachedRowSet how the row
identification should be done (to say what goes into the "where"
clause)? Eventually is there a smarter, free implementation of
CachedRowSet ?
Thanks, Don
PS. See used code and table data bellow.
---------------------------------
package dbtools;
import com.sun.rowset.CachedRowSetImpl;
import javax.sql.rowset.CachedRowSet;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import java.util.*;
import java.sql.*;
public class CacheRecSet {
Connection connection = null;
Random rand = new Random();
private Log log = LogFactory.getLog(this.getClass());
/** Creates a new instance of CacheRecSet */
public CacheRecSet() {
}
protected void setUp() {
if (connection != null) {
return;
}
/*
// MySql through OBDC
String uri =
"jdbc:odbc:mysqlodbcdbstorage;UID=tintin;PWD=tintin";
log.info("Initializing connection from '" + uri + "'");
try {
// Load the JDBC-ODBC bridge driver
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
} catch (ClassNotFoundException e) {
log.error("Opening connection",e);
return;
}
try {
connection = DriverManager.getConnection(uri);
log.info(" Loaded connection from '" + uri + "'");
} catch (Exception e) {
log.error("ERROR Opening connection");
return;
}
*/
// MySql direct
String uri =
"jdbc:mysql://localhost:3306/dbstorage?user=tintin&password=tintin";
log.info("Initializing connection from '" + uri + "'");
try {
// Load the driver
Class.forName("org.gjt.mm.mysql.Driver");
} catch (ClassNotFoundException e) {
log.error("Opening connection", e);
}
// add support for connection pooling
// Class.forName("org.apache.commons.dbcp.PoolingDriver");
try {
connection = DriverManager.getConnection(uri);
log.info(" Loaded connection from '" + uri + "'");
} catch (Exception e) {
log.error("Opening connection",e);
}
/*
// PostgreSql direct
String uri =
"jdbc:postgresql://localhost:5432/dbstorage?user=tintin&password=tintin";
log.info("Initializing connection from '" + uri + "'");
try {
// Load the driver
Class.forName("org.postgresql.Driver");
} catch (ClassNotFoundException e) {
log.error("Opening connection", e);
}
try {
connection = DriverManager.getConnection(uri);
log.info(" Loaded connection from '" + uri + "'");
} catch (Exception e) {
log.error("Opening connection", e);
}
*/
}
protected void tearDown() {
if (connection != null) {
try {
connection.close();
} catch (Exception e) {
log.error("Closing connection");
}
}
connection = null;
}
public void testMulti() {
if (connection == null) {
log.error("testMulti - null connection");
}
log.info("testMulti");
CachedRowSet crset;
try {
java.sql.Statement stmt = connection.createStatement();
ResultSet rs = stmt.executeQuery("SELECT * FROM test where
RecId = 1"); // for postgresql it doesnt work like this
//ResultSet rs = stmt.executeQuery("SELECT * FROM test
where "RecId" = 1"); // for postgresql it works like this
crset = new CachedRowSetImpl();
crset.populate(rs);
log.info("SIZE = "+crset.size());
if (crset.size() > 0) {
crset.first();
double fract = (double)1 / 3;
//fract = fract/3;
double dbl = (rand.nextInt(50)*1000) + fract;
java.util.Date dt = new java.util.Date();
java.sql.Date dt2 = new java.sql.Date(dt.getTime());
crset.updateInt("Married", 0); // int field (wanted as
bool...)
crset.updateString("Name", "coco"); // varchar field
crset.updateDouble("Salary", dbl); // double fld
crset.updateDate("DtCreate", dt2); // date field
String comments = "a test "+dt.toString() + " ===> " +
rand.nextInt(50);
crset.updateString("Comments", comments); // blob field
crset.updateInt("Age", rand.nextInt(50)); // int field
//int [] keys = {1};
//crset.setKeyColumns(keys);
//crset.setTableName("test"); // when dealing
PostGreSql, needed to be added as it seems...
crset.updateRow();
crset.acceptChanges(connection);
}
rs.close();
} catch (Exception e) {
log.error("testMulti",e);
return;
}
log.info("...OK");
}
public static void main(String args[]) {
CacheRecSet instance = new CacheRecSet();
instance.setUp();
instance.testMulti();
instance.tearDown();
}
}
-----------------------------------
CREATE DATABASE IF NOT EXISTS dbstorage;
USE dbstorage;
DROP TABLE IF EXISTS `test`;
CREATE TABLE `test` (
`RecID` int(10) unsigned NOT NULL auto_increment,
`Married` int(11) default NULL,
`Name` varchar(200) default NULL,
`Salary` double(10,2) default NULL,
`DtCreate` date default NULL,
`Comments` text,
`Age` int(10) unsigned default NULL,
PRIMARY KEY (`RecID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
/*!40000 ALTER TABLE `test` DISABLE KEYS */;
INSERT INTO `test`
(`RecID`,`Married`,`Name`,`Salary`,`DtCreate`,`Comments`,`Age`) VALUES
(1,0,'coco',15000.33,'2006-12-24','a test Sun Dec 24 00:20:09 EST 2006
===> 25',22),
(2,1,'0',NULL,NULL,NULL,NULL),
(3,NULL,'silviu',NULL,NULL,NULL,12);
/*!40000 ALTER TABLE `test` ENABLE KEYS */;
- 2
- Known problem with JComboBox?Hi,
just wondering if this is a known problem:
I have to set JComboBox.setLightWeightPopupEnabled(false) due to the
constellation of my framework.
Now the scrollbar of the combo won't be updated as long as the box is
entirely displayed within my JFrame. As soon as part of it is out of the
window the scrollbar will work.
What's that all about? Is there a "semi lightweight mode" or something like
that?
Thanks.
Ren?
- 2
- IE7 BetaI can not get JAVA to run in IE7 Beta. Actually, it didn't run under IE6
either. I've exhausted my limited knowledge already. Any advice? Links?
- 3
- Problem about generics and class arrayCan somebody explains why the last line of code doesn't compile ?
public class TestClassArray {
private static class A {
}
private static class B extends A {
}
Class[] rawClasses = { B.class }; // warning
Class<?>[] wildcardsClasses = { B.class };
// error : Cannot create a generic array of Class<? extends
TestClassArray.A>
Class<? extends A>[] upperBoundClasses = { B.class };
}
- 7
- reading \n from a fileI am reading from a file and storing in String.
I need to separate a word so that part of it goes to next line
abc\nxyd
I am moving this text to button.setText() and this should
appear on the button as
abc
xyz
for that I am putting newline escape there.
it is not working. I have tried putting unicode string in
place of \n that also is not working.
how to do it?
-Rawat
- 8
- Mars CoordinatesDoes anyone know how to convert (x,y) position of the mouse on a map
of Mars to the coordinates of Mars. I know there's a class in java
that is called Coordinate but i don't know how it works.
- 8
- 11
- Which IDE?Hello
I am a newbe to Java and to programming.
I am looking for an IDE which I can:
Download free from the net
Have a good documentation and tutorials
Be able to get sum help on the compiler itself on this group (or any other
newsgroup)
----
Elisha Dvir
052-3738817
- 11
- 12
- Preparing a StringHello
I am preparing xpath queries for xml parsing.
To make each xpath query i have to add variables and join more Strings.
I was wondering if there is any way i can create java string same as
SqlPrepareStatement
somthing like
String p = "my name is ?"
public void foo("joe"){
//add name in string p so that
//p = "my name is joe"
}
any help
thanks
Pinto
- 12
- Variable scope access questionHi,
I am not sure my question is valid or not. It is the following:
public class MyClass {
public void doA() {
int num = 10;
doB();
//Now, num value has been changed
}
public void doB() {
//I need to access and change the value num inside doA. But I don't
know how to do it.
}
}
Is this possible? Thank you for your help.
- 12
- JAXB & Excel 2003I downloaded Microsoft Office 2003 Reference Schemas from:
http://www.microsoft.com/downloads/details.aspx?familyid=fe118952-3547-420a-a412-00a2662442d9&displaylang=en
Then I tried to use JAXB on them, specifically excel.xsd and
excelss.xsd. The first one passes OK, but doesn't contain Worksheet
element, which is the root element for Excel 2003 documents saved as
XML. The other schema, excelss.xsd, contains the definition of this
element, but doesn't pass through JAXB. The output of:
xjc -p generated excelss.xsd
is:
-------------------- cut here ---------------
parsing a schema...
[ERROR] Property "Name" is already defined.
line 219 of file:/C:/xls/office.xsd
[ERROR] The following location is relevant to the above error
line 204 of file:/C:/xls/office.xsd
[ERROR] Property "Namespaceuri" is already defined.
line 214 of file:/C:/xls/office.xsd
[ERROR] The following location is relevant to the above error
line 199 of file:/C:/xls/office.xsd
[ERROR] Property "Url" is already defined.
line 224 of file:/C:/xls/office.xsd
[ERROR] The following location is relevant to the above error
line 209 of file:/C:/xls/office.xsd
[ERROR] Property "FullColumns" is already defined.
line 590 of file:/C:/xls/excelss.xsd
[ERROR] The following location is relevant to the above error
line 5042 of file:/C:/xls/excel.xsd
[ERROR] Property "FullRows" is already defined.
line 595 of file:/C:/xls/excelss.xsd
[ERROR] The following location is relevant to the above error
line 5047 of file:/C:/xls/excel.xsd
[ERROR] Property "DefaultColumnWidth" is already defined.
line 555 of file:/C:/xls/excelss.xsd
[ERROR] The following location is relevant to the above error
line 5057 of file:/C:/xls/excel.xsd
[ERROR] Property "DefaultRowHeight" is already defined.
line 560 of file:/C:/xls/excelss.xsd
[ERROR] The following location is relevant to the above error
line 5052 of file:/C:/xls/excel.xsd
[ERROR] Property "Fill" is already defined.
line 374 of file:/C:/xls/office.xsd
[ERROR] The following location is relevant to the above error
line 405 of file:/C:/xls/office.xsd
[ERROR] Property "Colors" is already defined.
line 422 of file:/C:/xls/office.xsd
[ERROR] The following location is relevant to the above error
line 429 of file:/C:/xls/office.xsd
[ERROR] Property "Path" is already defined.
line 597 of file:/C:/xls/vml.xsd
[ERROR] The following location is relevant to the above error
line 616 of file:/C:/xls/vml.xsd
[ERROR] Property "Opacity2" is already defined.
line 288 of file:/C:/xls/vml.xsd
[ERROR] The following location is relevant to the above error
line 316 of file:/C:/xls/vml.xsd
[ERROR] Property "Title" is already defined.
line 292 of file:/C:/xls/vml.xsd
[ERROR] The following location is relevant to the above error
line 314 of file:/C:/xls/vml.xsd
[ERROR] Property "Path" is already defined.
line 745 of file:/C:/xls/vml.xsd
[ERROR] The following location is relevant to the above error
line 771 of file:/C:/xls/vml.xsd
[ERROR] Property "Path" is already defined.
line 531 of file:/C:/xls/vml.xsd
[ERROR] The following location is relevant to the above error
line 551 of file:/C:/xls/vml.xsd
[ERROR] Property "Wrapcoords" is already defined.
line 44 of file:/C:/xls/vml.xsd
[ERROR] The following location is relevant to the above error
line 46 of file:/C:/xls/vml.xsd
[ERROR] Property "Path" is already defined.
line 647 of file:/C:/xls/vml.xsd
[ERROR] The following location is relevant to the above error
line 663 of file:/C:/xls/vml.xsd
[ERROR] Property "Spid" is already defined.
line 664 of file:/C:/xls/vml.xsd
[ERROR] The following location is relevant to the above error
line 666 of file:/C:/xls/vml.xsd
[ERROR] Property "Path" is already defined.
line 681 of file:/C:/xls/vml.xsd
[ERROR] The following location is relevant to the above error
line 701 of file:/C:/xls/vml.xsd
[ERROR] Property "Path" is already defined.
line 623 of file:/C:/xls/vml.xsd
[ERROR] The following location is relevant to the above error
line 640 of file:/C:/xls/vml.xsd
[ERROR] Property "Path" is already defined.
line 569 of file:/C:/xls/vml.xsd
[ERROR] The following location is relevant to the above error
line 590 of file:/C:/xls/vml.xsd
[ERROR] Property "Fill" is already defined.
line 198 of file:/C:/xls/vml.xsd
[ERROR] The following location is relevant to the above error
line 207 of file:/C:/xls/vml.xsd
[ERROR] Property "Path" is already defined.
line 711 of file:/C:/xls/vml.xsd
[ERROR] The following location is relevant to the above error
line 729 of file:/C:/xls/vml.xsd
Failed to parse a schema.
-------------------- cut here ---------------
Any ideas?
- 13
- need Java book for a C# / C C++ proficient programmer?hi,
I've never cared for Java before but now i feel like learning it. I'm
an MCP and a pretty experienced programmer. Also, i plan to take the
SCJP and maybe the SCMAD exams.
Is there a java book out that is for a programmer?? I already have a
copy of Hebert S. java reference, that would be my last option. Also,
i would want the books to somewhat cover the exams I plan to do.
Thanks so much
Gideon
|
| Author |
Message |
Shawn

|
Posted: 2006-10-31 3:02:00 |
Top |
java-programmer, Why Java's math expression (power) is so inconvenient and error prone?
Hi,
My program need a lot of calculation of power. In many programming
languages,
2**3 = 8; //or
2^3 = 8;
The syntax is clean and easy. But in Java,
Math.pow(2, 3) = 8; //It is so long, and complicated and error prone
Again, in many languages,
EXP(1) = 2.7 //e value
But in Java,
Math.pow(Math.E, 1) = 2.7 //You see, so complicated
Normally, in one calculation, 2**3 or EXP(3.5) is only part of
expression, like "a + b**3 + EXP(-a)". In Java, it will be very long and
error prone!
|
| |
|
| |
 |
Shawn

|
Posted: 2006-10-31 3:03:00 |
Top |
java-programmer >> Why Java's math expression (power) is so inconvenient and error prone?
Hi,
My program need a lot of calculation of power. In many programming
languages,
2**3 = 8;
The syntax is clean and easy. But in Java,
Math.pow(2, 3) = 8; //It is so long, and complicated and error prone
Again, in many languages,
EXP(1) = 2.7 //e value
But in Java,
Math.pow(Math.E, 1) = 2.7 //You see, so complicated
Normally, in one calculation, 2**3 or EXP(3.5) is only part of
expression, like "a + b**3 + EXP(-a)". In Java, it will be very long and
error prone!
|
| |
|
| |
 |
Mark Thornton

|
Posted: 2006-10-31 3:43:00 |
Top |
java-programmer >> Why Java's math expression (power) is so inconvenient and error prone?
Shawn wrote:
> Hi,
>
> My program need a lot of calculation of power. In many programming
> languages,
>
> 2**3 = 8; //or
> 2^3 = 8;
That may be short but your example illustrates the problem: lack of a
universal standard symbol (in ascii). Of course 2^3 already means
something else in Java.
>
> The syntax is clean and easy. But in Java,
>
> Math.pow(2, 3) = 8; //It is so long, and complicated and error prone
It may be longer but not error prone. You can eliminate the repeated use
of Math with static import:
import static java.lang.Math.*
then
pow(2,3)
>
> Again, in many languages,
>
> EXP(1) = 2.7 //e value
>
> But in Java,
>
> Math.pow(Math.E, 1) = 2.7 //You see, so complicated
Math.exp(1)
or with a static import, just
exp(1)
Mark Thornton
|
| |
|
| |
 |
Lionel

|
Posted: 2006-10-31 5:27:00 |
Top |
java-programmer >> Why Java's math expression (power) is so inconvenient and error prone?
Shawn wrote:
> Hi,
>
> My program need a lot of calculation of power. In many programming
> languages,
>
> 2**3 = 8;
>
> The syntax is clean and easy. But in Java,
>
> Math.pow(2, 3) = 8; //It is so long, and complicated and error prone
>
> Again, in many languages,
>
> EXP(1) = 2.7 //e value
>
> But in Java,
>
> Math.pow(Math.E, 1) = 2.7 //You see, so complicated
>
> Normally, in one calculation, 2**3 or EXP(3.5) is only part of
> expression, like "a + b**3 + EXP(-a)". In Java, it will be very long and
> error prone!
Error prone? All the above answers look correct. Can you tell us how it
is error prone?
It looks like you have come from C and are expecting non-object-oriented
code. Simple, get over it.
If it is so inconvenient then why don't you write a wrapper around the
Math class to make things a little easier. For example:
public class MathFunctions {
public static double exp(double someVal) {
return Math.pow(Math.E, someVal);
}
}
Now all you have to do is call MathFunctions.exp(1);
You can shorten the class name if you want.
If that is still too difficult I suggestion you learn about the
advantages of an Object-Oriented programming language.
Lionel.
|
| |
|
| |
 |
Shawn

|
Posted: 2006-10-31 5:50:00 |
Top |
java-programmer >> Why Java's math expression (power) is so inconvenient and error prone?
I appreciate Mark Thornton's reply:
import static java.lang.Math.*;
Then pow(2,3) or exp(1) is ready for service. Obviously, I didn't know
this trick.
In comparison, a wrapper class is a waste at all.
|
| |
|
| |
 |
Lionel

|
Posted: 2006-10-31 5:53:00 |
Top |
java-programmer >> Why Java's math expression (power) is so inconvenient and error prone?
Shawn wrote:
>
>
> I appreciate Mark Thornton's reply:
>
> import static java.lang.Math.*;
>
> Then pow(2,3) or exp(1) is ready for service. Obviously, I didn't know
> this trick.
>
> In comparison, a wrapper class is a waste at all.
So if there is an exp method then why were you using pow in the first
place. Please read the documentation in future.
|
| |
|
| |
 |
Arne Vajh鴍

|
Posted: 2006-10-31 9:47:00 |
Top |
java-programmer >> Why Java's math expression (power) is so inconvenient and error prone?
Lionel wrote:
>> My program need a lot of calculation of power. In many programming
>> languages,
>>
>> 2**3 = 8;
>>
>> The syntax is clean and easy. But in Java,
>>
>> Math.pow(2, 3) = 8; //It is so long, and complicated and error prone
>>
>> Again, in many languages,
>>
>> EXP(1) = 2.7 //e value
>>
>> But in Java,
>>
>> Math.pow(Math.E, 1) = 2.7 //You see, so complicated
> Error prone? All the above answers look correct. Can you tell us how it
> is error prone?
I agree with that.
> It looks like you have come from C and are expecting non-object-oriented
> code. Simple, get over it.
Actually C is very similar to Java. C does not have an
exponentation operator like Fortran and VB.
> If that is still too difficult I suggestion you learn about the
> advantages of an Object-Oriented programming language.
Hm.
I would not consider the Math static methods so fantastic
object oriented ...
Arne
|
| |
|
| |
 |
pkriens

|
Posted: 2006-10-31 19:45:00 |
Top |
java-programmer >> Why Java's math expression (power) is so inconvenient and error prone?
Shawn, you have no idea how right you are ... Unfortunately, there are
many domains where Java is very unsuitable, just think of how silly it
is that you need to do s1.equals(s2) instead of s1 = s2. Any idea how
much you need to compare strings in a business app? Or the fact that
you can not switch on a String or other object type for some mysterious
rationale?
Lets face it, Java is not a very elegant language. They had objects, so
everything had to become a class, well almost. For some weird
optimization reason we have /primitive types/ and they shout you right
in the face at the most inconventient times. Operator overloading was
killed (which would have allowed you to do 2^3) because it was abused
heavily in C++.
I think that part of the problem is that languages are designed by
language experts. Notice how their first goal usually is to become
self-hosting. Obviously constructions that are needed to write parsers
tend to overwhelm the minds of the language designers. SQL, XML,
business logic, engineering problems, mathematics, are not really in
the forefront of their minds I think.
Interestingly, a key figure in the Java Language Specification is
creating a new language (while working for Sun!) for exactly your
mentioned reason: the unreadability of Java for domain specific
languages, where math is their focus, they want to replace Fortran. Guy
Steele gave a very interesting talk about fortress on the OOPSLA 2006
last week in Portland (domain specific languages seem to becoming big
anyway).
http://research.sun.com/projects/plrg/
Interestingly, they have operator overloading. They argue (justly imho)
that operator overloading was a problem in C++ because there were so
few operators to choose from in ASCII. However, today we have Unicode
allowing us to use symbols with well defined meanings: 鈭? 鈭? 鈭?
鈯?鈮? 鈭? etc. These symbols are a lot easier to read for domain
experts than "all we have is method calls". And if people want to abuse
it ... hey it is their life and job. Any decent programmer will use
overloading operators to stay within the intended meaning.
Though a language is syntactic sugar, it is imho important. The closer
the language is to the domain, the easier it is to understand what it
does in your domain. An extreme form of non-domain specific languages
is XML when used for humans. Reading an ant script or XSLT program is
horrendously hard because the expressions are so far removed from what
you are doing. Not only is this error prone, it is also harder to write
and read.
For example, just think of the sillyness that we have thousands if not
millions of programmers writing business applications that involve
transactions, data sources, databases, and many small data entities.
Java is very unsuitable for those applications because it does not
natively support any of those things, they must all be implemented as
classes. They all have to be encoded as method calls. This wastes many
man years everyday and uncounted cost due to increased errors and hard
to understand code. Did you ever try to discuss a domain problem with
your customer together with the Java code?
Also on the OOPSLA 2006 was a presentation of Intentions. They had as
example system that had 400 pages of requirements and domain knowledge
for a 20.000 page system. Why do we need to expand this 50x? Their
solution was to create a domain specific language that could reduce the
expansion to around 2000 pages.
Java missed a surprising number of important concepts, and the lanugage
designers have no excuse because most of the near fatal misses were
available in Smalltalk (functions and blocks as objects [closures],
operator overloading, abstracted primitive integers, well designed
collections, etc. It is interesting though to see how many Smalltalkers
nowaday are working in Java and JCP moving the language forward!).
However, the Java language was close to C++ and corrected some of the
glaring mistakes of C++, add a couple of hundred million advertising
campaign and you have an explanation why Java became popular.
Don't get me wrong, I make a living in Java code and it is definitely
less error prone than C++. It clearly was an improvement. I do not want
to leave Java because the amount of libraries is awesome, and some are
actually decent! However, I hope that the industry will support more
languages that are more domain oriented. It would be nice if these
languages could be build on the Java library and VM so we can use the
languages without a great cost during runtime. I definetely see a trend
here. My only fear is that computer science students have lost the
ability to write parsers because XML is so convenient for the
programmer and who cares about the customer ... :-)
Kind regards,
Peter Kriens
Shawn wrote:
> Hi,
>
> My program need a lot of calculation of power. In many programming
> languages,
>
> 2**3 = 8; //or
> 2^3 = 8;
>
> The syntax is clean and easy. But in Java,
>
> Math.pow(2, 3) = 8; //It is so long, and complicated and error prone
>
> Again, in many languages,
>
> EXP(1) = 2.7 //e value
>
> But in Java,
>
> Math.pow(Math.E, 1) = 2.7 //You see, so complicated
>
> Normally, in one calculation, 2**3 or EXP(3.5) is only part of
> expression, like "a + b**3 + EXP(-a)". In Java, it will be very long and
> error prone!
|
| |
|
| |
 |
Ingo Menger

|
Posted: 2006-10-31 20:19:00 |
Top |
java-programmer >> Why Java's math expression (power) is so inconvenient and error prone?
Lionel wrote:
> If that is still too difficult I suggestion you learn about the
> advantages of an Object-Oriented programming language.
One of them is to have no operator overloading? Come on. This has
nothing to do with OO or not OO.
BTW, do you write
new StringBuffer().append("foo").append(i).toString()
instead of
"foo" + i
?
|
| |
|
| |
 |
Mark Thornton

|
Posted: 2006-11-1 4:43:00 |
Top |
java-programmer >> Why Java's math expression (power) is so inconvenient and error prone?
pkriens wrote:
> Shawn, you have no idea how right you are ... Unfortunately, there are
> many domains where Java is very unsuitable, just think of how silly it
> is that you need to do s1.equals(s2) instead of s1 = s2. Any idea how
> much you need to compare strings in a business app?
This might be a reasonable argument if only there weren't so many ways
to compare strings. The usual default comparison (selected by computer
scientists) is also frequently the wrong choice in business applications.
>
> Lets face it, Java is not a very elegant language. They had objects, so
> everything had to become a class, well almost. For some weird
> optimization reason we have /primitive types/ and they shout you right
> in the face at the most inconventient times. Operator overloading was
> killed (which would have allowed you to do 2^3) because it was abused
> heavily in C++.
Except that the C inheritance meant that the ^ operator was already in
use for numeric types and thus not available for exponentiation.
> Interestingly, a key figure in the Java Language Specification is
> creating a new language (while working for Sun!) for exactly your
> mentioned reason: the unreadability of Java for domain specific
> languages, where math is their focus, they want to replace Fortran.
I don't consider Fortran to be all that readable either; we are just
used to it.
> Interestingly, they have operator overloading. They argue (justly imho)
> that operator overloading was a problem in C++ because there were so
> few operators to choose from in ASCII. However, today we have Unicode
> allowing us to use symbols with well defined meanings: 鈭? 鈭? 鈭?
> 鈯?鈮? 鈭? etc. These symbols are a lot easier to read for domain
> experts than "all we have is method calls".
Those operators only have well defined meanings in mathematics. One of
the problems with overloading in C++ was its use for all sorts of non
mathematical purposes. This problem started right at the beginning with
the example set by overloading << for output. Unicode would have allowed
a more appropriate symbol, but it would still be a new coinage for that
symbol, not an existing well defined meaning.
> it ... hey it is their life and job. Any decent programmer will use
> overloading operators to stay within the intended meaning.
Essentially mathematics is the only domain where operators have a well
defined meaning of long standing (centuries). However very few languages
are written just for mathematicians. So it is all but inevitable that
any language which permits significant operator overloading will find it
being extensively used for purposes where the relationship of the
operator to action is not immediately obvious or "within the intended
meaning".
>
> However, the Java language was close to C++ and corrected some of the
> glaring mistakes of C++, add a couple of hundred million advertising
> campaign and you have an explanation why Java became popular.
And that massive set of standard libraries.
Mark Thornton
|
| |
|
| |
 |
RedGrittyBrick

|
Posted: 2006-11-1 4:58:00 |
Top |
java-programmer >> Why Java's math expression (power) is so inconvenient and error prone?
pkriens wrote:
> However, today we have
> Unicode allowing us to use symbols with well defined meanings: 鈭? 鈭?
> 鈭? 鈯?鈮? 鈭? etc. These symbols are a lot easier to read for domain
> experts than "all we have is method calls".
You're not reinventing this are you?
http://tinyurl.com/y59nkm
;-)
|
| |
|
| |
 |
QXJuZSBWYWpow7hq

|
Posted: 2006-11-1 10:14:00 |
Top |
java-programmer >> Why Java's math expression (power) is so inconvenient and error prone?
pkriens wrote:
> Shawn, you have no idea how right you are ... Unfortunately, there are
> many domains where Java is very unsuitable, just think of how silly it
> is that you need to do s1.equals(s2) instead of s1 = s2. Any idea how
> much you need to compare strings in a business app?
And ?
.equals and == has different semantics in Java.
It is not that difficult to learn.
And when you are beyond beginner level, then the typing process
is insignificant in the development so number of keystrokes does not
matter.
> Or the fact that
> you can not switch on a String or other object type for some mysterious
> rationale?
That is not something unique for Java. It is rather common in
languages.
> I think that part of the problem is that languages are designed by
> language experts. Notice how their first goal usually is to become
> self-hosting. Obviously constructions that are needed to write parsers
> tend to overwhelm the minds of the language designers. SQL, XML,
> business logic, engineering problems, mathematics, are not really in
> the forefront of their minds I think.
I think you are rigth on that one.
Languages are a backyard of computer science academia.
> Though a language is syntactic sugar, it is imho important. The closer
> the language is to the domain, the easier it is to understand what it
> does in your domain. An extreme form of non-domain specific languages
> is XML when used for humans. Reading an ant script or XSLT program is
> horrendously hard because the expressions are so far removed from what
> you are doing. Not only is this error prone, it is also harder to write
> and read.
The strictness and easy validation of XML makes it very non error prone.
But it can be hard to read. Especially with a lot of namespace stuff.
> For example, just think of the sillyness that we have thousands if not
> millions of programmers writing business applications that involve
> transactions, data sources, databases, and many small data entities.
> Java is very unsuitable for those applications because it does not
> natively support any of those things, they must all be implemented as
> classes. They all have to be encoded as method calls. This wastes many
> man years everyday and uncounted cost due to increased errors and hard
> to understand code. Did you ever try to discuss a domain problem with
> your customer together with the Java code?
I am not aware og any mainstream languages that has support for those.
> Java missed a surprising number of important concepts, and the lanugage
> designers have no excuse because most of the near fatal misses were
> available in Smalltalk (functions and blocks as objects [closures],
> operator overloading, abstracted primitive integers, well designed
> collections, etc. It is interesting though to see how many Smalltalkers
> nowaday are working in Java and JCP moving the language forward!).
Scary considering how well SmallTalk did commercially.
Arne
|
| |
|
| |
 |
Luc The Perverse

|
Posted: 2006-11-1 11:43:00 |
Top |
java-programmer >> Why Java's math expression (power) is so inconvenient and error prone?
"Arne Vajh鴍" <email***@***.com> wrote in message
news:454802e3$0$49209$email***@***.com...
>> For example, just think of the sillyness that we have thousands if not
>> millions of programmers writing business applications that involve
>> transactions, data sources, databases, and many small data entities.
>> Java is very unsuitable for those applications because it does not
>> natively support any of those things, they must all be implemented as
>> classes. They all have to be encoded as method calls. This wastes many
>> man years everyday and uncounted cost due to increased errors and hard
>> to understand code. Did you ever try to discuss a domain problem with
>> your customer together with the Java code?
>
> I am not aware og any mainstream languages that has support for those.
Didn't Cobol?
:)
|
| |
|
| |
 |
pkriens

|
Posted: 2006-11-1 18:14:00 |
Top |
java-programmer >> Why Java's math expression (power) is so inconvenient and error prone?
It is easy to get lost in details with these discussions and start
comparing language features. I am not promoting to go to Smalltalk. I
only want to make clear that Java is just not very expressive because
it has only a few crufty constructs making programs overly verbose (or
crufty as I call it). XML is the extreme form of this where you have to
wrestle through the cruft to see the relevant content, but Java is
often not much better.
Cruft makes programs hard to read and understand and that is bad imho.
It is easy to stab at the lack of adoption for Smalltalk. Theirs is a
sad story of too early, lack of focus, and too much out of mainstream.
However, I do not think anybody that has looked at the language can
look at Java with dry eyes. :-)
> .equals and == has different semantics in Java.
I therefore used '=' in the post because in the mathematical sense it
is equality and not assignment. (Smalltalk used the arrow for
assignment).
> And when you are beyond beginner level, then the typing process
> is insignificant in the development so number of keystrokes does not
> matter.
No the typing is not that much of an issue, it is the READING that is
important! Having to hold 5 pages into mind or 1 makes a difference.
> [Switching on strings ] That is not something unique for Java. It is rather common in
> languages.
Yes, stupidity is widespread. But what is the rationale? The result is
that people start using if () then else if() then else ... ad nausuem
which is easy to get wrong and hard to read and probably less eficient
than the compiler could have done it. Or better with the right language
that has blocks/closures, a method could be made that performs the
switch.
Kind regards,
Peter Kriens
Arne Vajh鴍 wrote:
> pkriens wrote:
> > Shawn, you have no idea how right you are ... Unfortunately, there are
> > many domains where Java is very unsuitable, just think of how silly it
> > is that you need to do s1.equals(s2) instead of s1 = s2. Any idea how
> > much you need to compare strings in a business app?
>
> And ?
>
> .equals and == has different semantics in Java.
>
> It is not that difficult to learn.
>
> And when you are beyond beginner level, then the typing process
> is insignificant in the development so number of keystrokes does not
> matter.
>
> > Or the fact that
> > you can not switch on a String or other object type for some mysterious
> > rationale?
>
> That is not something unique for Java. It is rather common in
> languages.
>
> > I think that part of the problem is that languages are designed by
> > language experts. Notice how their first goal usually is to become
> > self-hosting. Obviously constructions that are needed to write parsers
> > tend to overwhelm the minds of the language designers. SQL, XML,
> > business logic, engineering problems, mathematics, are not really in
> > the forefront of their minds I think.
>
> I think you are rigth on that one.
>
> Languages are a backyard of computer science academia.
>
> > Though a language is syntactic sugar, it is imho important. The closer
> > the language is to the domain, the easier it is to understand what it
> > does in your domain. An extreme form of non-domain specific languages
> > is XML when used for humans. Reading an ant script or XSLT program is
> > horrendously hard because the expressions are so far removed from what
> > you are doing. Not only is this error prone, it is also harder to write
> > and read.
>
> The strictness and easy validation of XML makes it very non error prone.
>
> But it can be hard to read. Especially with a lot of namespace stuff.
>
>
> > For example, just think of the sillyness that we have thousands if not
> > millions of programmers writing business applications that involve
> > transactions, data sources, databases, and many small data entities.
> > Java is very unsuitable for those applications because it does not
> > natively support any of those things, they must all be implemented as
> > classes. They all have to be encoded as method calls. This wastes many
> > man years everyday and uncounted cost due to increased errors and hard
> > to understand code. Did you ever try to discuss a domain problem with
> > your customer together with the Java code?
>
> I am not aware og any mainstream languages that has support for those.
>
> > Java missed a surprising number of important concepts, and the lanugage
> > designers have no excuse because most of the near fatal misses were
> > available in Smalltalk (functions and blocks as objects [closures],
> > operator overloading, abstracted primitive integers, well designed
> > collections, etc. It is interesting though to see how many Smalltalkers
> > nowaday are working in Java and JCP moving the language forward!).
>
> Scary considering how well SmallTalk did commercially.
>
> Arne
|
| |
|
| |
 |
Martin Gregorie

|
Posted: 2006-11-1 20:48:00 |
Top |
java-programmer >> Why Java's math expression (power) is so inconvenient and error prone?
Luc The Perverse wrote:
> "Arne Vajh鴍" <email***@***.com> wrote in message
> news:454802e3$0$49209$email***@***.com...
>>> For example, just think of the sillyness that we have thousands if not
>>> millions of programmers writing business applications that involve
>>> transactions, data sources, databases, and many small data entities.
>>> Java is very unsuitable for those applications because it does not
>>> natively support any of those things, they must all be implemented as
>>> classes. They all have to be encoded as method calls. This wastes many
>>> man years everyday and uncounted cost due to increased errors and hard
>>> to understand code. Did you ever try to discuss a domain problem with
>>> your customer together with the Java code?
>> I am not aware og any mainstream languages that has support for those.
>
> Didn't Cobol?
>
Only for CODASYL databases (i.e. IDMS) and via a preprocessor which made
these statements look like standard COBOL.
COBOL 85 didn't have native support for any of these things or a
preprocessor. The nearest it came was the COPY statement, which is just
"include" with some limited name substitution.
The current language specification doesn't extend the language beyond
COBOL 85 in any of these areas.
--
martin@ | Martin Gregorie
gregorie. | Essex, UK
org |
|
| |
|
| |
 |
EJP

|
Posted: 2006-11-2 8:13:00 |
Top |
java-programmer >> Why Java's math expression (power) is so inconvenient and error prone?
I must admit that I prefer exponentiation as an operator rather than a
function call. It suits the mathematicians better, of whom I was one,
and it also guarantees the correct right-associativity of the operator,
which is otherwise up to the programmer in function-call land.
|
| |
|
| |
 |
| |
 |
Index ‹ java-programmer |
- Next
- 1
- Questions about porting a Java applicationHi all,
I have a Java application that I want to port and I have read the better
part of [1]. The application that I want to port unfortunately has a
specific structure that does NOT make it possible to adhere to the
practices. What is the general thing to do in such a case?
As far as I can tell from the Win32 starter script for the application it
insists on an application
directory with the following structure
INSTALL-DIR
|
+---- bin
|
+---- doc
|
+---- lib
Any advice about this?
Kind regards,
Manfred Riem
email***@***.com
[1] Porter's Handbook - Using Java - Best practices
http://www.freebsd.org/doc/en_US.ISO8859-1/books/porters-handbook/using-java
.html#JAVA-BEST-PRACTICES
_______________________________________________
email***@***.com mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-java
To unsubscribe, send any mail to "email***@***.com"
- 2
- jsp:multiple file/directory uploadHello i want to upload mutliple files at a time in jsp
i.e want to upload whole directory or folder at one go
is there any way to do this if any one knows plz let me know
thanks in advance
- 3
- Basic jstl problem - Setting a bean propertyHi,
I have a simple class :
public class MyClass {
private String attrib = null;
public MyClass() {}
public void setAttrib(String attrib) {
this.attrib = attrib;
}
public String getAttrib() {
return this.attrib;
}
}
I also have a simple JSP:
<%@ taglib prefix="c" uri="http://java.sun.com/jstl/core" %>
<jsp:useBean id="myclass" class="MyClass"/>
If I try to set the "attrib" property using
<c:set target="${myclass}" property="attrib" value="somevalue"/>
I got an error:
javax.servlet.jsp.JspTagException: Invalid property in <set>:
"attrib"
org.apache.taglibs.standard.tag.common.core.SetSupport.doEndTag(SetSupport.java:160)
I tryed target="${myclass.attrib}", but I receive another error:
javax.servlet.jsp.JspException: An error occurred while evaluating
custom action attribute "target" with value "${myclass.attrib}":
Unable to find a value for "attrib" in object of class "MyClass" using
operator "." (null)
Any help?
TIA,
Bob
- 4
- JavaBean default property editorsI am looking for information on default property editors for JavaBean
properties. There are three cases in which I am hoping that a default
property editor exists for a given property:
1) The property is a collection class of references to other beans of a
particular base type which has already been been added to a bean
context. I am hoping that there is a default property editor which
allows the end-user programmer to add items to the collection, and then
connect each item to an appropriate bean already existing in the bean
context.
2) The property is a reference to another bean of a particular base type
which has already been added to a bean context. I am hoping that there
is a default property editor which allows the end-user programmer to
connect the property to an appropriate bean already existing in the bean
context.
3) A property editor which takes a reference to another bean as an
embedded bean ( one that is already initialized as a reference in the
parent bean ), and allows the embedded bean to expand its own properties.
Do such property editors exist, or do I actually need some sort of
custom property editor in any or all of these common cases ?
- 5
- JWS Program problem with MACIn article <47e58b1b$0$1630$email***@***.com>,
Knute Johnson <email***@***.com> wrote:
> http://rabbitbrush.frazmtn.com/aviation/
Here's the diagnostic info from a failed run on Mac OS 10.4.11 (ppc),
java version 1.5.0_13:
[General]
An error occurred while launching/running the application.
Category: Launch File Error
No JRE version found in launch file for this system
[Launch File]
<?xml version='1.0' encoding='UTF-8' ?>
<jnlp spec='1.0+'
codebase='http://rabbitbrush.frazmtn.com/aviation'
href="flightlog.jnlp">
<information>
<title>VFR Flight Log</title>
<vendor>Knute Johnson Software</vendor>
<homepage href="index.html"/>
<icon kind="splash" href="catalina.jpg" />
</information>
<resources>
<java version='1.5+' />
<jar href='sVFRFlightLog.jar' />
</resources>
<application-desc
main-class='com.knutejohnson.tools.aviation.vfrlog.VFRFlightLog'>
</application-desc>
<security>
<all-permissions/>
</security>
</jnlp>
[Exception]
NLPException[category: Launch File Error : Exception: null : LaunchDesc:
<jnlp spec="1.0+" codebase="http://rabbitbrush.frazmtn.com/aviation/"
href="http://rabbitbrush.frazmtn.com/aviation/flightlog.jnlp">
<information>
<title>VFR Flight Log</title>
<vendor>Knute Johnson Software</vendor>
<homepage href="http://rabbitbrush.frazmtn.com/aviation/index.html"/>
<icon href="http://rabbitbrush.frazmtn.com/aviation/catalina.jpg"
kind="splash"/>
</information>
<security>
<all-permissions/>
</security>
<resources>
<jar
href="http://rabbitbrush.frazmtn.com/aviation/sVFRFlightLog.jar"
download="eager" main="false"/>
</resources>
<application-desc
main-class="com.knutejohnson.tools.aviation.vfrlog.VFRFlightLog"/>
</jnlp> ]
at com.sun.javaws.Launcher.handleLaunchFile(Launcher.java:210)
at com.sun.javaws.Launcher.run(Launcher.java:165)
at java.lang.Thread.run(Thread.java:613)
--
John B. Matthews
trashgod at gmail dot com
home dot woh dot rr dot com slash jbmatthews
- 6
- random names, yeap im bored/*i think someone should you this to name their baby*/
import java.util.Random;
public class name
{
public static void main(String[] args)
{
String string1;
char char1 = 7;
string1 = " ";
int temp, length;
Random generator = new Random();
length = generator.nextInt(10);
for(int blah = 0;blah <= length;blah++)
{
temp = generator.nextInt(26);
if(temp == 1)
char1 = 65;
if(temp == 2)
char1 = 66;
if(temp == 3)
char1 = 67;
if(temp == 4)
char1 = 68;
if(temp == 5)
char1 = 69;
if(temp == 6)
char1 = 70;
if(temp == 7)
char1 = 71;
if(temp == 8)
char1 = 72;
if(temp == 9)
char1 = 73;
if(temp == 10)
char1 = 74;
if(temp == 11)
char1 = 75;
if(temp == 12)
char1 = 76;
if(temp == 13)
char1 = 77;
if(temp == 14)
char1 = 78;
if(temp == 15)
char1 = 79;
if(temp == 16)
char1 = 80;
if(temp == 17)
char1 = 81;
if(temp == 18)
char1 = 82;
if(temp == 19)
char1 = 83;
if(temp == 20)
char1 = 84;
if(temp == 21)
char1 = 85;
if(temp == 22)
char1 = 86;
if(temp == 23)
char1 = 87;
if(temp == 24)
char1 = 88;
if(temp == 25)
char1 = 89;
if(temp == 26)
char1 = 90;
string1 = string1 + char1;
}
System.out.println(string1);
}
}
- 7
- dragging a transparent JFrameI'm able to get a transparent JFrame using java 1.4+ on Mac OS X. I
simply set the JFrame's background to a transparent color. However,
with a transparent color (any alpha component less than 255), when I
drag within the JFrame (not the titlebar), it drags the entire JFrame
with it. This makes for unexpected results when dragging an object
within the JFrame that also drags the entire JFrame.
Any ideas?
- 8
- Authenticating Against Users Defined In a Database - TomcatCould someone point me in the right direction - I'm trying to
authenticate users against a SQL Server database and found plenty of
articles on how to create tables such as user-roles but I want to use
the actual users defined in SQL Server, because the users are also
directly logging into the db. I also tried using NTLM but our
production environment will not allow this.
TIA
- 9
- JDK + SDKHi,
why i need JDK and JRE together. I don't understand it:
1. I can install JDK + JRE in a packet on my maschine. So i have two Folders
JDK1.5.0_06 and JRE1.5.0_06
2. only JDK
3. only JRE
If i install JDK so there is a folder in it with JDK1.5.0_06/jre/ there the
JRE ist include.
So why i must install jre separately? I want to that my browser must be use
this included jre in jdk !!!
There is the diffrent between?
thx a lot
AdrianP
- 10
- Error handling java GUILet's say that I'm reading the inputs from a TextField widget:
JTextField jt = new JTextField(20);
String text = jt.getText();
if ( !text.equals("OK") )
{
// print some error message to the user
}
If the input is bad, I want to print some error message to the user but
at the same time I don't want to exit my GUI. How do I do that? Should
I be using exceptions? Can someone point me to some sample codes
somewhere on how error handling is performed in JAVA?
Thanks
Thierry
- 11
- 12
- Question about Master and Working Memory from Chapter 17 of the Java Language SpecificationOk the following is from Chapter 17 of the Java Language
Specification.
"A variable is any location within a program that may be stored into.
This includes not only class variables and instance variables but also
components of arrays. Variables are kept in a main memory that is
shared by all threads. Because it is impossible for one thread to
access parameters or local variables of another thread, it doesn't
matter whether parameters and local variables are thought of as
residing in the shared main memory or in the working memory of the
thread that owns them.
Every thread has a working memory in which it keeps its own working
copy of variables that it must use or assign. As the thread executes a
program, it operates on these working copies. The main memory contains
the master copy of every variable. There are rules about when a thread
is permitted or required to transfer the contents of its working copy
of a variable into the master copy or vice versa."
Does this mean that, say, in the following code, there are two working
copies of the integer variable X (one belonging to aThread and one
belonging to bThread) and one master copy?
public class TestThread {
public static void main(String[] args) {
aClass a = new aClass();
Thread aThread = new Thread( a );
Thread bThread = new Thread( a );
aThread.start();
bThread.start();
}
}
class aClass implements Runnable{
int X;
public void run( ) {
while (true) {update();}
}
synchronized void update(){
X++;
}
}
- 13
- Package Naming Best PracticesSteven Garcia wrote:
> Is this inadvisable? On one hand it provides clarity for the classes
> in a package, on the other hand that clarity might confuse those who
> are really familiar with the Java API.
As it doesn't follow the package naming specification, I'd say you need
to modify your approch somewhat.
As you don't own the rights to the Java API (or the Java name), it
might be better to instead use the following, which would comply with
the spec:
net.domainname.mp.lang
net.domainname.mp.text
net.domainname.mp.util
net.domainname.mp.io
...etc.
That's my advice -- you're welcome to use it or ignore it as it suits
you :).
HTH!
Brad BARCLAY
--
=-=-=-=-=-=-=-=-=
From the OS/2 WARP v4.5 Desktop of Brad BARCLAY.
The jSyncManager Project: http://www.jsyncmanager.org
- 14
- modularity / granularity of security for a Java application (not applet)Can an administrator control the security restrictions for Java
applications, separately from restrictions for native, non-Java apps?
If so, what are (some of) the resources that can be restricted?
Specifically, can a Java application be temporarily prevented from using
network services?
Again, this is for an application, not an applet.
Thanks for any information,
George
- 15
- Backing up databasesI am looking to write some basic scripts to back-up various files and
databases as well as restore them. Do you think this would be easier
and better to do using Ant or Ruby?
I would appreciate any insight available.
Thanks!
|
|
|