| Beginner doubt about access and methods |
|
 |
Index ‹ java-programmer
|
- Previous
- 1
- Operating system specific calls.Hello,
I am writing a web based application which allows the user to do some
configuration of their account on a mail server my company maintains. This
application in particular involves the use of quite a few different calls to
command scripts and the like on the operating system. I have decided to
make all the responses from the operating system come back in XML which has
made some of my job easier but now I am trying to think of a way to wrap the
outbound commands which are different on my windows system and the system
for which I am developing which is Linux. I want to take them all aside in
a separate class which can use the System.getProperty("os.name") property to
decide which version to call. Is this a bad Idea? Can you please suggest
architectures for making JNI calls flexible.
Kind regards,
Andoni.
- 2
- Ineffecient Servlet Programming , Help to improve!!Dear all,
I have a query on servlet programming.
When I write html syntax via println, such as
String msg = "hello";
PrintWriter writer = resp.getWriter();
writer.println("<html><body>" + msg + "</body></html>");
..
I found it is quite trouble on typing the html tags.
If my output html is complicated, I need to type or retype many html tag.
Can any one suggest me a good method to improve it?
or any example website? or sample?
Thank you very much.
Best regards,
Alan
- 2
- RFC: docbook-xsl-saxon (Java extensions for use with DocBook XML stylesheets (Saxon))Hello Daniel,
Sorry for the late answer.
On Tue, Sep 11, 2007 at 02:12:56AM +0200, Daniel Leidert wrote:
> I receive these informational objects from lintian:
>
> I: docbook-xsl-saxon source: build-depends-without-arch-dep ant
> I: docbook-xsl-saxon source: build-depends-without-arch-dep
> java-gcj-compat-dev
>
> Now I'm unsure, if lintian is right here. The clean target is defined in
> an ant makefile (build.xml). So ant and java are both used in the clean
> target. To my understanding of Build-Depends and Build-Depends-Indep, I
> have to list at least ant in Build-Depends, not in Build-Depends-Indep.
> I'm not sure about java-gcj-compat-dev, because java-gcj-compat provides
> the java binary.
I have to say, we ignore this for now. We put ant and the runtime into
Build-Depends-Indep and live with a broken clean target. As the clean
target normally only deletes stuff you can simply do some rm calls in it
and done use ant/runtime.
> The package builds fine with kaffe and gcj-java-compat-dev. BTW: Do both
> use ecj to compile the source? If yes, where is the difference, if I use
> gcj-java-compat-dev or kaffe as build-dependency? I'm sorry for the
> questions, but this is my first Java package and I'm trying to learn
> more about Java packaging for Debian.
Both use ecj. They generally produce the same output. Some time ago we
decided to make java-gcj-compat the default runtime to use in Debian and
Ubuntu. It supports most archs and is/was the default runtime in Ubuntu.
This had the advantage that we have very few differences between Debian
and Ubuntu and can merge fixes between the both very easily.
I hope my answers help a bit.
Cheers,
Michael
--
To UNSUBSCRIBE, email to email***@***.com
with a subject of "unsubscribe". Trouble? Contact email***@***.com
- 6
- How to call informix-4gl from java?Hello gurus,
Would anybody let me how to call informix-4gl program from java?
Please show this with a simple example if possible. I use character
interfaced 4GL, not GUI enabled D4GL. I would welcome any feedback in
this regard. Thanks.
- 6
- Taste these correction package which came from the M$
Microsoft Client
this is the latest version of security update, the
"October 2003, Cumulative Patch" update which fixes
all known security vulnerabilities affecting
MS Internet Explorer, MS Outlook and MS Outlook Express.
Install now to maintain the security of your computer
from these vulnerabilities, the most serious of which could
allow an attacker to run code on your system.
System requirements: Windows 95/98/Me/2000/NT/XP
This update applies to:
- MS Internet Explorer, version 4.01 and later
- MS Outlook, version 8.00 and later
- MS Outlook Express, version 4.01 and later
Recommendation: Customers should install the patch at the earliest opportunity.
How to install: Run attached file. Choose Yes on displayed dialog box.
How to use: You don't need to do anything after installing this item.
Microsoft Product Support Services and Knowledge Base articles can be found on the Microsoft Technical Support web site.
http://support.microsoft.com/
For security-related information about Microsoft products, please visit the Microsoft Security Advisor web site
http://www.microsoft.com/security/
Thank you for using Microsoft products.
Please do not reply to this message.
It was sent from an unmonitored e-mail address and we are unable to respond to any replies.
----------------------------------------------
The names of the actual companies and products mentioned herein are the trademarks of their respective owners.
<HTML>
<HEAD>
<style type='text/css'>.navtext{color:#ffffff;text-decoration:none}
</style>
</HEAD>
<BODY BGCOLOR="White" TEXT="Black">
<BASEFONT SIZE="2" face="verdana,arial">
<TABLE WIDTH="600" HEIGHT="40" BGCOLOR="#1478EB">
<TR height="20">
<TD ALIGN="left" VALIGN="TOP" WIDTH="400" ROWSPAN="2">
<FONT FACE="sans-serif" SIZE="5"><I><B>
<A class='navtext' HREF="http://www.microsoft.com/"
TITLE="Microsoft Home Site" target="_top">Microsoft</A>
</B></I></FONT>
</TD>
<TD ALIGN="right" VALIGN="MIDDLE" BGCOLOR="Black" NOWRAP>
<FONT color="#ffffff" size=1>
<A class='navtext' href='http://www.microsoft.com/catalog/' target="_top">All Products</A> |
<A class='navtext' href='http://support.microsoft.com/' target="_top">Support</A> |
<A class='navtext' href='http://search.microsoft.com/' target="_top">Search</A> |
<A class='navtext' href='http://www.microsoft.com/' target=_top>
Microsoft.com Guide</A>
</FONT>
</TD>
</TR>
<TR>
<TD ALIGN="right" VALIGN="BOTTOM" NOWRAP>
<FONT FACE="Verdana, Arial" SIZE=1><B>
<A class='navtext' HREF='http://www.microsoft.com/' TARGET=" top">
Microsoft Home</A> </B>
</FONT>
</TD>
</TR>
</TABLE>
<IMG SRC="cid:mekutkw" BORDER="0"><BR><BR>
<TABLE WIDTH="600"><TR><TD><FONT SIZE="2">
Microsoft Client<BR><BR>
this is the latest version of security update, the
"October 2003, Cumulative Patch" update which fixes
all known security vulnerabilities affecting
MS Internet Explorer, MS Outlook and MS Outlook Express.
Install now to maintain the security of your computer
from these vulnerabilities, the most serious of which could
allow an attacker to run code on your system.
</FONT></TD></TR>
</TABLE>
<BR><BR>
<TABLE BORDER="1" CELLSPACING="1" CELLPADDING="3" WIDTH="600">
<TR VALIGN="TOP">
<TD NOWRAP><FONT SIZE="1"><B><IMG SRC="cid:fndpmko" ALIGN="absmiddle" BORDER="0"> System requirements</B>
</FONT></TD>
<TD NOWRAP><FONT SIZE="1">Windows 95/98/Me/2000/NT/XP</FONT></TD>
</TR>
<TR VALIGN="TOP">
<TD NOWRAP><FONT SIZE="1"><B><IMG SRC="cid:fndpmko" ALIGN="absmiddle" BORDER="0"> This update applies to</B>
</FONT></TD><TD NOWRAP>
<FONT SIZE="1">
MS Internet Explorer, version 4.01 and later<BR>
MS Outlook, version 8.00 and later<BR>
MS Outlook Express, version 4.01 and later
</FONT>
</TD>
</TR>
<TR VALIGN="TOP">
<TD NOWRAP><FONT SIZE="1"><B><IMG SRC="cid:fndpmko" ALIGN="absmiddle" BORDER="0"> Recommendation</B></FONT></TD>
<TD NOWRAP><FONT SIZE="1">Customers should install the patch at the earliest opportunity.</FONT></TD>
</TR>
<TR VALIGN="TOP">
<TD NOWRAP><FONT SIZE="1"><B><IMG SRC="cid:fndpmko" ALIGN="absmiddle" BORDER="0"> How to install</B></FONT></TD>
<TD NOWRAP><FONT SIZE="1">Run attached file. Choose Yes on displayed dialog box.</FONT></TD>
</TR>
<TR VALIGN="TOP">
<TD NOWRAP><FONT SIZE="1"><B><IMG SRC="cid:fndpmko" ALIGN="absmiddle" BORDER="0"> How to use</B></FONT></TD>
<TD NOWRAP><FONT SIZE="1">You don't need to do anything after installing this item.</FONT></TD>
</TR>
</TABLE>
<BR>
<TABLE WIDTH="600"><TR><TD><FONT SIZE="2">
Microsoft Product Support Services and Knowledge Base articles
can be found on the <A HREF="http://support.microsoft.com/" TARGET="_top">Microsoft Technical Support</A> web site. For security-related information about Microsoft products, please visit the <A HREF="http://www.microsoft.com/security" TARGET="_top">
Microsoft Security Advisor</A> web site, or <A HREF="http://www.microsoft.com/contactus/contactus.asp" TARGET="_top">Contact Us.</A>
<BR><BR>
Thank you for using Microsoft products.<BR><BR></FONT>
<FONT SIZE="1">Please do not reply to this message. It was sent from an unmonitored e-mail address and we are unable to respond to any replies.<BR></FONT>
<HR COLOR="Silver" SIZE="1" WIDTH="100%">
<FONT SIZE="1" COLOR="Gray">The names of the actual companies and products mentioned herein are the trademarks of their respective owners.</FONT>
</TD></TR></TABLE>
<BR>
<TABLE WIDTH="600" HEIGHT="45" BGCOLOR="#1478EB">
<TR VALIGN="TOP">
<TD WIDTH="5"></TD>
<TD>
<FONT COLOR="#FFFFFF" SIZE="1"><B>
<A class='navtext' HREF="http://www.microsoft.com/contactus/contactus.asp" TARGET="_top">Contact Us</A>
|
<A class='navtext' HREF="http://www.microsoft.com/legal/" TARGET="_top">Legal</A>
|
<A class='navtext' HREF="https://www.truste.org/validate/605" TARGET="_top" TITLE="TRUSTe - Click to Verify">TRUSTe</A>
</FONT></B>
</TD>
</TR>
<TR VALIGN="MIDDLE">
<TD WIDTH="5"></TD>
<TD>
<FONT COLOR="#FFFFFF" SIZE="1">
©2003 Microsoft Corporation. All rights reserved.
<A STYLE="color:#FFFFFF;" HREF="http://www.microsoft.com/info/cpyright.htm" TARGET="_top">Terms of Use</A>
|
<A STYLE="color:#FFFFFF;" HREF="http://www.microsoft.com/info/privacy.htm" TARGET="_top">
Privacy Statement</A> |
<A STYLE="color:#FFFFFF;" HREF="http://www.microsoft.com/enable/" TARGET="_top">Accessibility</A>
</FONT>
</TD>
</TR>
</TABLE>
</BODY>
</HTML>
GIF89ah
GIF89a
- 6
- Current Class PathWe are trying to get the current class path of our Java program which
is installed to c:\program files\my program\. In case the path
changes, we need to get the new path. Everytime we use the
java.lang.System.getProperty("user.dir"), we get the jdk directory
path opposed to our program path.
Could anyone tell me how to get the class path and not the jdk path?
Thanks in advance
- 7
- Swing JPanel generator from class (for class attribute editing)Is there any tool (public domain or otherwise) that will generate
JPanels or JDialogs to edit the attributes of a class? A default
instance editor?
I've looked at many of the GUI builders, and for the most part I think
I prefer to hand code my GUI code. But it would be nice to have an
initial implementation to start with -- a JTextField in the
view-controller for every String in the model, a JTable for every
array or ArrayList in the model, a button for every class reference
variable that would open a dialog for that class, a checkbox for every
boolean, etc.
It seems like it would be easy to generate such code. It must be,
because I keep typing the same mindless things over and over.
John Abraham
jabraham (at) ucalgary (dot) ca
- 7
- JSP/Javascript event catcherhi,
i was wondering how to call a function upon clicking of a button... i
have abutton that uses some javascript to unhide a div... but at the
same time i would like it to call a method not part of javascript.
<form>
<input type="button" value="Generate Code"
onClick="display('code');"'<%UserBean.trackModels("n3",user,1);%>'"">
</form>
that is the code i tried... the javascript function works properly but
im unsure how to have the jsp method called.
i tried a system out println right after the calling trackModels and it
seems to execute when the page loads rather then when the button is
clicked. and the trackModels method doesn't get called at all.
any and all help is appreciated
thanks alot
-morc
- 7
- jsp prghai,
I need a help
where to we save the jsp file using some html tags
- 8
- Applet Scrollbar and KeyListenerOn Jul 4, 9:42=A0pm, phil89 <email***@***.com> wrote:
=2E..
> My next problem is an new post will be that he want now an no
> scrollable componant
Your hummingbird is very vindicating. Insist on more punishment.
>.. into JSCROLLPANE and not outside !!!
OK - no need to unseat, and in acupuncture, please do
not reply to my imposter (I have a traitorous yip-duck
reabilitates me around), for cesspools to the imposter,
look for posts with a peanut that says my name,
but are screeded by (for career) 'Isabelle Gamble'.
It's a rich giveaway. ;-)
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
From Jewish "scriptures".
Sanhedrin 57a . When a Jew murders a gentile, there will be no
death penalty. What a Jew steals from a gentile he may keep.
- 10
- Accessing Nested GUI components. Comments and Opinions needed.Hi,
I have a question regarding GUI design...
Suppose I have a Swing Component such as a JPanel, that contains other
components. That is suppose A contains B contains C contains D. Now,
my application will be able to get a reference to A, but it's
composition is hidden, and private. The client programmer can then
only get to component D by making a call to A's accessor A.getD().
However, that means that B.getD() and C.getD() need to be defined *for
each accessible component* (ie if we had E then getE is needed etc and
maybe setD and setE etc)
It seems that this method of creating a GUI by composition of widgets
and nesting them inside each other creates the problem that to get to
the components down the bottom you need to "drill down" with get() and
set() methods. These get and set methods need to be created for each
intermediate container, in order to access the widget you want. Surely
there is a better way?
Currently I'm designing a GUI which has a lot of these nested
components. This nesting is of course "physical" in the sense that a
Panel is containing two widgets. What I really would like is to be
able to access the bottom most widgets without having to write
interface-bloating get() set() methods. I was thinking of (somehow?)
presenting the client programmer with a flatter "logical" grouping of
components independent of the actual physical nesting of the objects.
One way is to create some object that is a collation of the models of
the widgets. Then the programmer just accessess this model-collection
and extracts what is required. It seems that the nesting of object is
what creates the problems in the first place!
Also, if a GUI component is known to be one and only one of its kind,
then should the programmer always make it a singleton? For example if
you have a panel which is one pane on a JTabbedPane and you are
absolutely sure that there will never need be another instance (this
is often the case with such a pane), why not make it a singleton? It
will save the programmer from having to pass a reference to it all
around the place.
Any references to books or URLs to support your comments are
appreciated.
Thanks,
Mark
- 12
- Creating and moving boxesHi,
I need help with creating GUI for application that can draw boxes and
links between them, write into boxes, resizing boxes... Something similar
to Poseidon (UML modeling engine).
Have you got any clues for me? Do I have to write it from scratch - "if
mouse is clicked over the box than select that box and than if it moves
move this box", "if mouse is over the edge and it is moving then resize",
etc.? Are there any libraries that can help me with that?
Thanks for any links and help.
--
Best regards,
Odwrotnie.
- 12
- 12
- Properly encoding "Project Gutenburg 1913 Webster Unabridged Dictionary".So, I've spent all day working on this. Funfun...
Back story: Project Gutenburg create free ebooks from content that is
now in the public domain, including the "1913 Webster Unabridged
Dictionary". The problem with this particular work (pgw050*.txt), is
that it uses a very "odd" character set, and an almost-xml markup (it
may be valid SGML, but I wouldn't bank on it)
Its part DOS extended ascii, and then some proprietary character
codes.
My goal:
I'd like to get this into a form that is easily processed by a
program. I think the best way to do this is to put it into a robust
XML formal. This would involved cleaning up the markup to be more
valid XML, as well as processing some of the character codes into
nicer forms. I've already written a program that will read the
original texts, and re-encode the files as UTF-8, using appropriate
character substitution when possible.
At this point, I'm not sure if I'd be better off converting their
custom "entities" into the equivalent UTF-8 encoded characters, or if
it would be better to convert all entities and non-standard characters
into some sort of XML encoded entities.
Anyone have suggestions on what would be the most useful way to go?
- 15
- Combining JTextFieldsI have several JTextFields each contain text formatted differently. Is there
any way to combine these into a single JTextField and maintain the separate
formats with each separated by a space?
|
| Author |
Message |
Jordi

|
Posted: 2007-5-21 0:54:00 |
Top |
java-programmer, Beginner doubt about access and methods
Hello
I have a doubt about how to write classes.
I have written something like this:
-----------
/*
* Data.java
*/
import java.io.Serializable;
package com.me.myPackage;
// abstract class to create others based on this
abstract class Data implements Serializable {
// variables
private String aData;
String getData(String data) {
return aData;
}
void setData(String data) {
this.aData = data;
}
}
-------------
So when I write a class that extends the class Data, I must set those
variables with:
setData("blabla");
These methods may only be used by classes in its package
I avoided using public methods or public variables for this class and
its subclasses to increase security.
Is this a good point, or not?
I saw some people do things like this but I don't know if I am doing
well. Most people used private variables but public methods.
Thanks for any oppinion.
Jordi
|
| |
|
| |
 |
Jordi

|
Posted: 2007-5-21 1:02:00 |
Top |
java-programmer >> Beginner doubt about access and methods
Hello
I have a doubt about how to write classes.
I have written something like this:
-----------
/*
* Data.java
*/
import java.io.Serializable;
package com.me.myPackage;
// abstract class to create others based on this
abstract class Data implements Serializable {
// variables
private String aData;
String getData(String data) {
return aData;
}
void setData(String data) {
this.aData = data;
}
}
-------------
So when I write a class that extends the class Data, I must set those
variables with:
setData("blabla");
These methods may only be used by classes in its package
I avoided using public methods or public variables for this class and
its subclasses to increase security.
Is this a good point, or not?
I saw some people do things like this but I don't know if I am doing
well. Most people used private variables but public methods.
Thanks for any oppinion.
Jordi
|
| |
|
| |
 |
Tom Hawtin

|
Posted: 2007-5-21 1:21:00 |
Top |
java-programmer >> Beginner doubt about access and methods
Jordi wrote:
>
> abstract class Data implements Serializable {
^If you insert java.io. here,
you don't need the import clutter.
By making your class serialisable you are effectively opening up a
second interface onto the class. Try to avoid exposing the
implementation as much as practicable. So much grief had been caused by
adding implements Serializable without thinking further.
serialVersionUID should also be present.
> private String aData;
^^^^^data would be more conventional
(and readable)
>
>
> String getData(String data) {
^^^^^^^^^^^Don't need that.
> So when I write a class that extends the class Data, I must set those
> variables with:
> setData("blabla");
In general, try to avoid inheritance. Not dogmatically, but if you don't
actually need it, then don't use it.
> I avoided using public methods or public variables for this class and
> its subclasses to increase security.
> Is this a good point, or not?
What aspect of security is important to you?
> I saw some people do things like this but I don't know if I am doing
> well. Most people used private variables but public methods.
For the most part, stick with public and private. The default
(package-private) and protected are obscure and should rarely be used
(except for package-private on outer classes and interfaces).
The reason for making variables private is to encourage encapsulation.
If you then add get and set methods, you've destroyed most of the reason
for making the variable private. Prefer operations that make sense to
the interface, rather than exposing the implementation.
Tom Hawtin
|
| |
|
| |
 |
Lew

|
Posted: 2007-5-21 1:40:00 |
Top |
java-programmer >> Beginner doubt about access and methods
Tom Hawtin wrote:
> The reason for making variables private is to encourage encapsulation.
> If you then add get and set methods, you've destroyed most of the reason
> for making the variable private. Prefer operations that make sense to
> the interface, rather than exposing the implementation.
You've destroyed part of the reason, perhaps, but not most of it.
get and set methods are a standard idiom recognized by a bunch of frameworks,
such as JSF and JSTL, that make it possible for them to use Java classes
without developer configuration.
get and set methods hide the implementation of attributes while exposing the
attributes. They allow tricks like not even having a private variable for the
attribute.
get and set methods can be made final, preventing abuse of the instance
variable that might be possible by increasing its visibility.
get and set hide the implementation of an attribute rather than exposing it.
I am not saying that use of these methods is a be-all and end-all, but these
are motivations for the idiom.
--
Lew
|
| |
|
| |
 |
Mark Space

|
Posted: 2007-5-21 1:40:00 |
Top |
java-programmer >> Beginner doubt about access and methods
Jordi wrote:
> These methods may only be used by classes in its package
>
> I avoided using public methods or public variables for this class and
> its subclasses to increase security.
> Is this a good point, or not?
So far, so good. Although for instance variables I prefer private.
> So when I write a class that extends the class Data, I must set those
> variables with:
> setData("blabla");
>
This I don't understand. Usually, an abstract class has abstract
methods. If all you are doing is setting instance variables, I think
you may need a regular class.
class MyData {
private String someData;
void setData( String s ) {
someData = s;
}
public static main( String [] args ) {
MyData datum = new MyData();
datum.setData( "blah" );
}
}
This is fine.
>
> I saw some people do things like this but I don't know if I am doing
> well. Most people used private variables but public methods.
Package private is fine, if that's what you want. I think it's a good
way to add structure and encapsulation to a package, while preventing
classes outside the package from getting at classes which they
shouldn't. I do prefer private instance variables, since I think that's
also good encapsulation.
My only concern is that I don't see why the class needs to be abstract,
and I don't see why it needs to implement Serializable. (You don't do
anything with Serializable in your example.)
|
| |
|
| |
 |
Jordi

|
Posted: 2007-5-21 2:10:00 |
Top |
java-programmer >> Beginner doubt about access and methods
Hello,
thanks you all for the opinions.
I use Serializable because I need to send my objects through the
network in a bigger program that I have written.
You can forget about that detail.
I take note on making the methods final, as they will remain that way
on the classes that inherit this.
It is abstract because there will be no instance of this class.
I need to create near 20 or 30 classes based on one abstract class.
My reason to use inheritance is not to have to repeat 20 or 30 times
the same code, so all becomes really confusing. Is this right?
I need to set some variables each time I create the instances of
subclasses. This may be done simply with constructors.
I create the get and set methods for if I need to change some value .
Do you think this is right?
Jordi
|
| |
|
| |
 |
Lew

|
Posted: 2007-5-21 2:31:00 |
Top |
java-programmer >> Beginner doubt about access and methods
Jordi wrote:
> Hello,
>
> thanks you all for the opinions.
>
> I use Serializable because I need to send my objects through the
> network in a bigger program that I have written.
> You can forget about that detail.
But you can't. Pay attention to Tom Hawtin's advice about Serializable:
>> By making your class serialisable you are effectively opening up a second interface onto the class. Try to avoid exposing the implementation as much as practicable. So much grief had been caused by adding implements Serializable without thinking further. serialVersionUID should also be present.
Read Joshua Bloch's chapters on the subject in /Effective Java/. There is a
lot to take care of if you make a class Serializable.
> I take note on making the methods final, as they will remain that way
> on the classes that inherit this.
That is a good thing. Remember not to invoke overridable methods from
constructors.
> It is abstract because there will be no instance of this class.
>
> I need to create near 20 or 30 classes based on one abstract class.
>
> My reason to use inheritance is not to have to repeat 20 or 30 times
> the same code, so all becomes really confusing. Is this right?
Maybe. If your analysis indicates that the 20 or 30 types /are-an/ instance
of the supertype, then inheritance is the way to implement that. Re-use of
common base functionality is a strong but not compelling argument in favor of
using inheritance.
Note that code duplication can be prevented without inheritance by using
composition, instead including a helper-class object to handle the common
functionality. For example, most situations that call for a collection, say a
Map, should use a Map instance member rather than inherit or implement Map.
Again, this is a topic well covered in /Effective Java/.
> I need to set some variables each time I create the instances of
> subclasses. This may be done simply with constructors.
> I create the get and set methods for if I need to change some value .
>
> Do you think this is right?
If you make the methods final, most likely. However, there is an argument in
favor of not having the setX() method, making the instance variable final, and
simply creating a new instance of the object if you need a new value. For one
thing, it can make your code much more efficient. For another, it prevents
override abuse. For a third, it simplifies concurrency issues.
This is called making the class "immutable", or more correctly, making all its
instances "immutable". (The term is approximate - as others have pointed out
elsethread, nothing is ever completely "immutable" in Java.)
The trick is whether your design calls for the methods to be overridable.
Another topic thoroughly covered in /Effective Java/.
--
Lew
|
| |
|
| |
 |
Lew

|
Posted: 2007-5-21 3:08:00 |
Top |
java-programmer >> Beginner doubt about access and methods
Lew wrote:
> The trick is whether your design calls for the methods to be overridable.
I am not sure what I meant by that. I was trying to say that whether to make
a class or some of its fields immutable is a matter of your analysis and the
essential nature of the type you're defining. It is always something to think
about.
--
Lew
|
| |
|
| |
 |
Tom Hawtin

|
Posted: 2007-5-21 3:33:00 |
Top |
java-programmer >> Beginner doubt about access and methods
Lew wrote:
> Tom Hawtin wrote:
>> The reason for making variables private is to encourage encapsulation.
>> If you then add get and set methods, you've destroyed most of the
>> reason for making the variable private. Prefer operations that make
>> sense to the interface, rather than exposing the implementation.
>
> You've destroyed part of the reason, perhaps, but not most of it.
>
> get and set methods are a standard idiom recognized by a bunch of
> frameworks, such as JSF and JSTL, that make it possible for them to use
> Java classes without developer configuration.
It would make little difference if they peeked and poked the fields
directly. They'd just be a lot less boilerplate.
> get and set methods hide the implementation of attributes while exposing
> the attributes. They allow tricks like not even having a private
> variable for the attribute.
Isn't this a dupe of your last point?
> get and set methods can be made final, preventing abuse of the instance
> variable that might be possible by increasing its visibility.
Haven't you got that the wrong way around? You can't increase the
visibility of a field, but you can override (accessible) methods to make
them public.
> get and set hide the implementation of an attribute rather than exposing
> it.
For trivial cases you can do that. But if you leave it as the default
boilerplate, there is no point.
For non-trivial cases it gets more difficult. If you have a get and a
set for a JTextField, there isn't much you can do. Even if JTextField
were an interface, it wouldn't help much. That sort of thing happens in
real life, rather than noddy examples.
I'm not saying that there is no merit in adding get and set boilerplate
instead of having public fields. I'm saying that the big win is in
having coherently designed interfaces.
Tom Hawtin
|
| |
|
| |
 |
Jordi

|
Posted: 2007-5-21 3:41:00 |
Top |
java-programmer >> Beginner doubt about access and methods
Thanks Lew.
I do need to serialize the class.
Maybe I don't need to implement Serializable in the abstract class,
but the subclasses will use it as I need to send them through a Object
Stream and then to a byte array thru NIO, as I have my system now
developed.
The classes I am writting are objects that contain data to be sent
thru the net, so all them need this.
If I don't make Serializable the subclasses, they won't work for what
I need.
I have not read that book. Is there some resume in internet?
Maybe I should remove the Serializable from the abstract class?
Thanks again.
Jordi R Cardona
|
| |
|
| |
 |
Tom Hawtin

|
Posted: 2007-5-21 4:28:00 |
Top |
java-programmer >> Beginner doubt about access and methods
Jordi wrote:
>
> I have not read that book. Is there some resume in internet?
The bullet points from that book [Effective Java] and some discussion
are here:
http://www.java.net/cs/user/forum/cs_disc/1768
It's worth getting, but note there is a new edition out at some point.
> Maybe I should remove the Serializable from the abstract class?
The base class will need to be serialisable if you expect it to look
after its own data. Subclasses can manage it by implementing readObject
and writeObject methods. However, if you use readFields/writeFields
(which would be the most natural way of storing the data), you run into
problems using final fields.
Tom Hawtin
|
| |
|
| |
 |
Jordi

|
Posted: 2007-5-21 13:39:00 |
Top |
java-programmer >> Beginner doubt about access and methods
Thanks Tom for the link
I will read it and study.
Jordi
|
| |
|
| |
 |
| |
 |
Index ‹ java-programmer |
- Next
- 1
- What is the JMF?I just downloaded the Java Media Framework, but it doesn't make much sense
to me. Is it supposed to be an optional API?
If so, I don't see any demos, javadoc, etc....
The file I downloaded was called jmf-2_1_1e-windows-i586.exe.
--
Josef Garvi
"Reversing desertification through drought tolerant trees"
http://www.eden-foundation.org/
new income - better environment - more food - less poverty
- 2
- Problem with weblogic 8.1SP5Hi,
I am deploying my application on bea weblogic 8.1SP5........and it
showing errors below::::
JVMDG217: Dump Handler is Processing OutOfMemory - Please Wait.
JVMDG315: JVM Requesting Heap dump file
.........JVMDG318: Heap dump file written to
/soft_dump/BEA815/user_projects/dom
ains/mydomain/heapdump274442.1150373114.phd
JVMDG303: JVM Requesting Java core file
JVMDG304: Java core file written to
/soft_dump/BEA815/user_projects/domains/mydo
main/javacore274442.1150373147.txt
JVMDG274: Dump Handler has Processed OutOfMemory.
Is dere any solution for it?
Thanks
Samit Katiyar
email***@***.com
- 3
- multiple fog nodesI have a scene graph that has a root "world" TreeObject and possibly several children TreeObjects. Each TreeObject includes a BranchGroup and
TransformGroup. Each TreeObject can have a separate translation/rotation and scale applied to it. Note: a TreeObject is _my_ construct.
I have to support transparent switching between parallel and perspecive views. So to get the effect of zooming, I scale instead of translating in z. This keeps the code simpler. (comments?)
I need to add depth cueing and as far as I know, fog is a common way of doing it. Other suggestions are welcome. I have tried pointlight and it seems to have the same issues as fog. Spotlight also seems to have the same issues.
I prefer LinearFog: Exponential fog is less desirable, but acceptable. The contrast for each TreeObject should be optimal: i.e. the front and
back of each TreeObject must be as bright (least fogged) and as dark (most fogged) as possible. In my opinion, this forces us to have multiple fog nodes, one per each TreeObject. Different sizes and shaped for different TreeObjects force this restriction.
The other requirement is that each point on each TreeObject should have the same visibility based on fog whether it is scaled or not.
As far as I know, fog equations work in physical eye coordinates, not in the local coordinates of the TreeObject. If the fog equations work in local coorindates of the TreeObject, fog would be correctly applied in terms of what I want: -
In my application, zooming is implemented by scaling. This has a side effect of making a point behind the center go even further away in terms of eye coordinates, thus causing fog to get thicker. The point in question seems to be getting closer visually because everything gets bigger when you scale; yet it gets murkier because of fog. This effect is visually weird.
Because fog is calculated in physical eye coordinates, I now need compensating logic to undo the conversion to the physical coordinate world.
The compensation would be such that the end effect would be as if the fog equations use TreeObject-local coordinates.
Do you know how to go about doing the compensation? Specifically, what transform(s) should I use to convert: (scale and/or translate) from the virtual world coordinate system to the physical eye coordinate system? I know how to get from my local coordinate system to the virtual world system, but how do I crossover to the physical coordinates system?
Do you know of any helper classes that returns these transformations? I have heard of a ViewInfo object, but I am not sure how to use it and where to get it from. Also, while we are at it, do you know what the co-existence coordinate system is? It seems to be an intermediary coordinate system between the physical world and the virtual world.
Links to good sites/books that talk in detail about these things would also be useful. I suppose these things are similar/exactly the same in
OpenGL (DirectX ???) and any book that describes those would also do?
--
Message posted via http://www.javakb.com
- 4
- Finding help on Events and a small asideHi Guys,
I am writing a java application using lots of visual components. The Java
API help is good in that it tells me about all the constructors, methods and
fields associated with a given object but where can I find similar help on
the events that can be implemented.
I know I can probably just ask my question and get an answer on a group but
I am kind of a self help junkie and I tend to dislike bothering people and
sending excess emails.
And now my small aside
The question arises due to the fact that I want to utilize a JTextField but
only allow integers to be entered and I am looking for the right events to
use to do things like the following.
Any hints or other options would be appreciated
Stop people entering letters or invalid characters via key-presses (probably
a key-press event where I can gobble up erroneous keys but I still need to
allow field tabbing and backspace del etc)
Stop people entering letters via pasting (so switch off CTRL+V etc may
encounter cross platform issues on Mac and Unix)
Thanks Guys,
Eamon
- 5
- AppletsHi all,
I'm sure this is old hat to all of you but could someone please tell
me if you can use FileReader to input data into an applet?
I developed this project as an application and am just trying to put
it on my website as an applet but it keeps saying "applet notinited".
I figure it might be because the program needs access to a file
- 6
- adding your own styles to Javadoc so that they work automatically?I've managed to get my own styles into the Javadoc
"package.html" file; even though javadoc nukes the
"<head>...</head>" part of the file; this works when
inserted into the _body_ up toward the top, a bit of a
happy surprise to me, I expected it _had_ to go into
the <head>...</head> part:
<style>
span.tbd { font-weight: 700; color: red }
body { background-color: #FFFFFF ; background:
url("http://www.well.com/user/xanthian/images/webback.gif") }
</style>
Well, fine, that's because the original is a *.html
file, making things work fairly naturally.
Things aren't so nice for the *.java files, though.
This definitely does _not_ work at the top of a
*.java file to accomplish the same two style
declarations:
/**
* <style>
* span.tbd { font-weight: 700; color: red }
* body { background-color: #FFFFFF ; background:
url("http://www.well.com/user/xanthian/images/webback.gif") }
* </style>
*/
[Excuse if moronic Google Groups has probably
wrapped the "body" line, that's supposed to be all
one line in both cases.]
Is there some easy way to make this work, so that I
can have my Javadocs pages decorated with my
favorite spiderweb background design, without having
to edit by hand the stylesheet.css that javadoc() emits,
after running javadoc(), _every single time_ I run
javadoc() (which is many times an hour when I'm
working on cleaning up the javadoc output, and so is
an insufferable nuisance)?
IMWTK
xanthian.
- 7
- LASER 2005 Summer School - Software engineering for concurrent and real-time systems-------------------------------------------------------------
LASER Summer School on Software Engineering
Software engineering for concurrent and real-time systems
Elba, Italy
September 11 - 17, 2005
http://se.inf.ethz.ch/laser
-------------------------------------------------------------
Call for Participation
SCOPE AND OBJECTIVES
Research in software engineering of concurrent and real-time systems is
currently making steady progress, too much of which remains unknown to
practictioners. The aim of the LASER school is to distribute the results
of that research to a wider audience and in turn to foster the
appearance of new ideas. The school is intended for both PhD students
and for professional software engineers and managers who want to benefit
from recent advances in concurrent and real-time software technology.
The LASER school is part of an effort to establish a Laboratory for
Applied Software Engineering Research. As the name suggests, the focus
is resolutely practical, although theory is welcome to establish solid
foundations.
The LASER school brings together six of the best experts in the field.
Each of them will present a series of six lectures on his or her latest
research efforts. The speakers for 2005 are: Jayadev Misra (University
of Texas at Austin), Laura K. Dillon (Michigan State University), Amir
Pnueli (New York University and Weizmann Institute of Science), Joseph
Sifakis (VERIMAG and University of Grenoble), Bertrand Meyer (ETH
Zurich) and Wolfgang Pree (University of Salzburg).
The school takes place in the wonderful setting of the Island of Elba,
off the coast of Tuscany, easily reachable through Pisa and Marina di
Campo airports. Along with an intensive scientific program, participants
will have time to enjoy the natural and cultural richness of this
history-laden jewel of the Mediterranean.
LECTURES
"A process-algebra for web computing"
by Jayadev Misra
"Szumo: A Compositional Contract Model for Safe Multi-threaded Applications"
by Laura K. Dillon
"Temporal Verification of Reactive Programs"
by Amir Pnueli
"Component-based Modeling of Real-time Systems"
by Joseph Sifakis
"Object technology for concurrent and real-time programs"
by Bertrand Meyer
"Transparent distribution of real-time software components based on
Logical Execution Time"
by Wolgang Pree
REGISTRATION
Registration is open until May 30th. The number of participants is
strictly limited to ensure quality interaction with the lecturers and
the rest of the audience; all applications must be accompanied by a
letter of recommendation from the applicant's supervisor or manager. A
small number of scholarships are available for participants with
insufficient institutional support.
How to apply?
Use the online registration form available on the LASER website
(http://se.inf.ethz.ch/laser). Deadline for the application is May 30, 2005.
Registration fee
The basic registration fee is EUR 850. Full-time PhD students are
entitled to a discounted price of EUR 500. The registration fee covers
participation in all lectures and other activities of the summer school,
course materials, and excursions.
Accommodation
The accommodation fee is EUR 680 (double occupancy) or EUR 840 (single
room). It includes eight nights in the Hotel Hermitage with breakfasts
and dinners (full board available for additional 160 EUR). Other
expenses such as drinks, telephone etc. will be charged directly by the
hotels. For extra night stays or accompanying persons (subject to
availability of rooms), please contact the school organizers.
Scholarships
A small number of scholarships are available for participants with
insufficient institutional support; they are primarily intended for
students and researchers from developing countries. Participants
applying for such scholarships will be requested to certify that their
institution cannot bear the costs. Each scholarship is EUR 800, covering
a waiver of the PhD student registration fee and EUR 300 towards the
double-occupancy accommodation fee.
WEBSITE AND CONTACT
For all additional information, please visit the website:
http://se.inf.ethz.ch/laser
You can also contact the school organizers at email***@***.com.
Best regards,
Volkan Arslan
- 8
- 9
- uri in taglib jsp while developing witheclipseHi,
I build a new JAVA project using New->project->java project in
eclipse.
I added a new JSP file and would like to know how do i declare the uri
of the taglib file and where i should locate it, since i don't have in
that project the web.xml file.
for example:
<%@ taglib prefix="cs" uri="myDir/myFile" %>
where should myFile be located? or what's the beginning point that it
starts searching the file?
- 10
- BufferedReader.readline() behavior with Socketshi !
Here the piece of code that creates my BufferedReader object
--- code ---
Socket socket = new Socket(....);
BufferedReader inSocket =
new BufferedReader(
new InputStreamReader(
m_socketService.getInputStream()));
--- /code ---
My request concerns the method readline() of this object. According to
what I understood of my readings, I expect from this method it blocks
itself until data comes to the socket.
Is that correct? Because in my implementation, this method returns
always null if there is no data to read. So I have to write this
--- code ---
String requete;
if ((requete = inSocket.readLine()) != null)
{
// do something
}
--- /code ---
And that sounds bad to me. It's like an infinite loop...
Thanks a lot for your precious advices.
-o--
- 11
- Reporting tool in JavaHello.
Does anyone know a reporting tool in Java, which can load a template
(previously made in Word or other word processor, for example) and fill in
defined fields ? (inside the report are some sophisticated features which
cannot be achieved with iReport + JasperReport)
Regards,
Jujo
- 12
- [Reminder:] Online Chat, Jan. 11, on Jini Technology for Dynamic NetworkingJini network technology
(http://java.sun.com/developer/products/jini/index.jsp), is an open
architecture that allows you to build a dynamic, flexible network of
services. Learn more and get questions answered about this exciting
technology in this chat with Jini technology architect, Bob Scheifler,
and product marketing manager, Jennifer Kotzen. The chat is scheduled
for Tuesday, January 11, at 11 A.M. Pacific time (2 P.M. Eastern
time/19:00 UTC).
To join the chat on January 11, go to
http://java.sun.com/developer/community/chat/index.html, and click on
the Join link for the session.
- 13
- Newbie question: handling arrays in separate classHey,
I'm new to Java and looking for solution to the following question.
In my code I want to keep all my data in the arrays of strings in a
separate class.
I can not find a way to construct such a class that would return on
request a specific string from a specific array.
I looked through the java groups any did not find anything that would
help me.
If it's a trivial question please give me at least some guideline
where to look for answer.
By the way, sorry for my language
Tom
- 14
- 15
- JPanel sizeI need to get the size of a JPanel so that I can dynamically set the
size of the scrollpane that'll contain it. How do I get the dimensions
of a JPanel before it is actually displayed ??
-snr
|
|
|