| Pros and Cons of Static Methods |
|
 |
Index ‹ java-programmer
|
- Previous
- 3
- Recommend a good programming environment for beginner?Howdy. I'm taking a java class, and they unfortunately just have us
using the DOS cmd liine and notepad to program. I'd like to use a good
environment. I used to use Codewarrior. Netbeans came with the Java
download from Sun, but it overwhelmed me, seems like I'd have to invest
a lot in learning it. Does anybody know of a sleeker, easier to get
used to environment?
Alternatively, anyone know of a good, simple, easy to follow tutorial
to get one up an running in netbeans?
Thanks a heap....
Bill J.
- 5
- Please help! SecurityFilter redirects to login page again...Hi All I ha e a problem around authenticating ith Securit Filter and can t see the reasons Container is Tomcat 5 5 9 The problem is: After successful authentication response is the login page again although form default page propert is a redirect jsp for securit filter here I redirect users to the proper role s starting page If I input and send user information again the redirect orks properl Just for the second time I can t see the reasons I ha e alread used securit filter and ha en t had this error there I ha e debugged redirect jsp and could see that on the line response sendRedirect basePath admin inde jsp has run but the result is the login page again When I tr to access some resources ithin the protected area after authentication the redirect is correct The abo e described error e ists onl hen I tr to do a direct login and hope to be redirected to the form default page An idea please ? redirect jsp s running section: < @ page language= ja a import= ja a util pageEncoding= iso 8859 2 > < String path = request getConte tPath ; String basePath = request getScheme : request getSer erName : request getSer erPort path ; if request isUserInRole admin response sendRedirect basePath admin inde jsp ; S stem out println basePath admin inde jsp ; else if request isUserInRole modifier response sendRedirect basePath modifier inde jsp ; else if request isUserInRole inquirier response sendRedirect basePath inquirier inde jsp ; else response sendRedirect basePath inde jsp ; > securit filter config ml: <? ml ersion= 1 0 encoding= ISO 8859 1 ?> < DOCTYPE securit filter config PUBLIC Securit Filter org DTD Securit Filter Configuration 2 0 EN http: securit filter org dtd securit filter config_2_0 dtd > <securit filter config> < securit konfiguracio START > < admin resources START > <securit constraint> < eb resource collection> < eb resource name>Admin resources< eb resource name> <description> accessible b authenticated users of the admin role< description> <url pattern> admin < url pattern> <http method>GET< http method> <http method>POST< http method> <http method>PUT< http method> <http method>DELETE< http method> < eb resource collection> <auth constraint> <description>These roles are allo ed access< description> <role name>admin< role name> < auth constraint> < securit constraint> < admin resources END > <login config> <auth method>FORM< auth method> <realm name>lm realm< realm name> <form login config> <form login page> inde jsp< form login page> <form error page> inde jsp?badpass =Y< form error page> <form default page> redirect jsp< form default page> < form login config> < login config> <securit role> <description>admin role has access to this eb application< description> <role name>admin< role name> < securit role> <realm className= org securit filter realm catalina CatalinaRealmAdapter > <realm className= org apache catalina realm JDBCRealm > <realm param name = dri erName alue= com microsoft jdbc sqlser er SQLSer erDri er > <realm param name = connectionURL alue= jdbc:microsoft:sqlser er: 127 0 0 1:1433;DatabaseName=db_licenceman ager;User=m user;Pass ord=m pass ord;SelectMethod=cursor > <realm param name = connectionName alue= m user > <realm param name = connectionPass ord alue= m pass ord > <realm param name = userTable alue= users > <realm param name = userNameCol alue= user_name > <realm param name = userCredCol alue= pass ord > <realm param name = userRoleTable alue= user_roles > <realm param name = roleNameCol alue= role_name > < realm> < <realm className= org apache catalina realm Memor Realm > > < securit konfiguracio END > < securit filter config> eb ml: <? ml ersion= 1 0 encoding= ISO 8859 1 ?> < DOCTYPE eb app PUBLIC Sun Micros stems Inc DTD Web Application 2 3 EN http: ja a sun com dtd eb app_2_3 dtd > < eb app> < filter: securit filter konfiguracio START > <filter> <filter name>Securit Filter< filter name> <filter class>org securit filter filter Securit Filter< filter class> <init param> <param name>config< param name> <param alue> WEB INF securit filter config ml< param alue> < init param> <init param> <param name> alidate< param name> <param alue>true< param alue> < init param> < filter> < map all requests to the Securit Filter control hat it does ith configuration settings > <filter mapping> <filter name>Securit Filter< filter name> <url pattern> < url pattern> < filter mapping> < filter: securit filter konfiguracio END > <ser let> <ser let name>action< ser let name> <ser let class>org apache struts action ActionSer let< ser let class> <init param> <param name>config< param name> <param alue> WEB INF struts config ml< param alue> < init param> <init param> <param name>debug< param name> <param alue>3< param alue> < init param> <init param> <param name>detail< param name> <param alue>3< param alue> < init param> <load on startup>0< load on startup> < ser let> <ser let mapping> <ser let name>action< ser let name> <url pattern> do< url pattern> < ser let mapping> < eb app> Thanks in ad ance Peet
- 7
- Best Friends Decide To Get Fucked Together For The First Time Just few link on some movies...
All just for you...
Download
>>>>> http://download-video.12w.net
>>>>> http://world-sex.urllogs.com
>>>>> http://video-sex.12w.net
CLICK FREE DOWNLOAD VIDEO PORN...
L
I
C
K
T
O
W
A
T
C
H
V
I
D
E
O
P
O
R
N
D
O
W
N
L
O
A
D
F
R
E
E
.
.
.
W
E
L
C
O
M
T
O
M
O
V
I
E
S
P
O
R
N
D
O
W
N
L
O
A
D
.
.
.
- 9
- WebSphere 4.0 and VisibrokerI have written an application that uses Visibroker to communicate with
a remote CORBA server. I have put the vbjorb.jar and other required
JARs under WEB-INF/lib. However, since vbjorb.jar contains classes
also contained in rt.jar, I also add the WEB-INF/lib directory to ws.ext.dirs.
This WSAD configuration works just fine. This is WebSphere 4.0
application.
However, when I attempted to deploy my application to WAS 4.0, I
persistently got a NoClassFoundError. Adding a ws.ext.dirs system
directory specifying the directory containing the JARS didn't yield the desired
effects. Even specifying the absolute directory path did not work.
Is there some other "trick" in order to deploy such an application
successfully to WAS 4.0?
Thx!
Panagiotis Varlagas
email***@***.com
- 9
- development speed of struts is low?Hi
When i change my action class, struct-config.xml, i need to
restart tomcat, it will highlt affect my development speed. How to fix
this problem?
thanks
from Peter (email***@***.com)
- 9
- Robot.java low level help followupMy quest to emulate Robot.java in C# continues......
I was not able to use SendKeys, SendInput, keybd_event, or the
WH_JOURNALPLAYBACK hook to reproduce Robot.java's key sending ability
for apps that poll the asynch key state.
Since I was not able to get any info about the low-level code
Robot.java uses to execute the keyPress and keyRelease methods (any
info still appreciated :) ), I ended up creating a java app that runs
minimized that has a socket to accept keys, and uses robot.java to
send them. Any app of any kind can send the keys to this app and
utilize Robot.java's functionality.
Hope this info helps someone looking to use the wonderful Robot.java
in another platform.
- 10
- Unexpected signal: 11 [Was: Sun JDK 1.4.2_01 for Linux]> Is it just my imagination or is the Sun JDK 1.4.2_01 for Linux
> (java/linux-sun-jdk14) stable and very well performing? On my FreeBSD
It was just my imagination ;-) See below for the error message I got seconds
after I started up my application server and executed no more than 3
requests:
Unexpected Signal : 11 occurred at PC=0x2A6BD991
Function=[Unknown.]
Library=(N/A)
NOTE: We are unable to locate the function name symbol for the error
just occurred. Please refer to release documentation for possible
reason and solutions.
Current Java thread:
Dynamic libraries:
Can not get information for pid = 21338
Heap at VM Abort:
Heap
def new generation total 576K, used 138K [0x2c760000, 0x2c800000,
0x2cc40000)
eden space 512K, 24% used [0x2c760000, 0x2c77ee30, 0x2c7e0000)
from space 64K, 23% used [0x2c7e0000, 0x2c7e3b78, 0x2c7f0000)
to space 64K, 0% used [0x2c7f0000, 0x2c7f0000, 0x2c800000)
tenured generation total 3036K, used 2298K [0x2cc40000, 0x2cf37000,
0x30760000)
the space 3036K, 75% used [0x2cc40000, 0x2ce7e870, 0x2ce7ea00,
0x2cf37000)
compacting perm gen total 5376K, used 5140K [0x30760000, 0x30ca0000,
0x34760000)
the space 5376K, 95% used [0x30760000, 0x30c653f8, 0x30c65400,
0x30ca0000)
Local Time = Fri Sep 12 16:50:59 2003
Elapsed Time = 194
#
# HotSpot Virtual Machine Error : 11
# Error ID : 4F530E43505002EF
# Please report this error at
# http://java.sun.com/cgi-bin/bugreport.cgi
#
# Java VM: Java HotSpot(TM) Client VM (1.4.2_01-b06 mixed mode)
#
# An error report file has been saved as hs_err_pid21314.log.
# Please refer to the file for further information.
_______________________________________________
email***@***.com mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-java
To unsubscribe, send any mail to "email***@***.com"
- 14
- Failover pattern
2 or more hosts, each running the same application.
Each Java application on each host is assigned a specific task.
Say:
App on host1 does task X
App on host2 does task Y
App on host3 does task Z
Only one app can do any specific task.
Now, if app on host1 shutsdown for whatever reason, either app on host2 or host3 should take over task X.
I was thinking of implementing this with UDP ... but someone may have already done this ... without using a database.
Is there a design pattern for the above ... basically a failover pattern ?
- 14
- US-CA: San Rafael, Full time Java-PL/SQL programmer.Working as a team member of the I.S. group, develops, integrates, and
supports applications.
Primary Responsibilities:
* Conversion of Servlets/JSP to Swing based applications.
* Converting logic from procedures/packages in Oracle to Java.
* Maintenance of code.
* User training/support.
* Ability to work on multiple projects simultaneously.
* Research, evaluate, and implement new 3rd party software packages.
Requirements:
* 2-3 years industry level experience in the following Java
technologies: Swing, JSP, Servlet, JDBC, RMI, EJB.
* 1-2 years industry level experience in Oracle 8i (or greater) which
includes writing PL/SQL procedures, packages and triggers.
Position Type:
* Full Time.
Company Location:
* San Rafael, California, USA.
Restrictions:
* This is not an entry level position.
* No thrird party companies.
* Sorry No H1Bs visa holders.
Email resume to is0871 at gmail.com
- 14
- JDK BSD NewBeeHi all,
I'm a BSD newbie with a couple of simple questions.
Does the 1.4 jdk implementation implement the hotspot optimizer? And
are the threads green or native - and what is the difference? I've
read that the jdk1.3 binary does not implement hotspot and uses green
threads and I'm trying to decide if upgrading to the jdk 1.4 will
improve my servlet application's performance.
Also, I've noticed that there are ports for things like tomcat and
other java third party extensions. Can anyone tell me the difference
between the ports version and those that I would download from say
jakarta.apache.org? I've compiled mod_jk from the apache source using
the mac os X compile instructions, as those were the only that I could
get to work, will my compiled mod_jk work better if I use the ports?
I'm new to the ports system as I come from the land of RedHat LInux and
Mac OS X.
Thanks for all of your help.
Alden
Add Content Now
Offering a fun and interactive way to transform
your site content single handedly.
http://www.addcontentnow.com
303.279.2023
_______________________________________________
email***@***.com mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-java
To unsubscribe, send any mail to "email***@***.com"
- 14
- [Update] FreeQueryBuilder 2005.03FreeQueryBuilder 2005.03 is now available!
(http://querybuilder.sourceforge.net/)
With FreeQueryBuilder, you can create SQL queries without directly
writing SQL.
A diagram pane presents a graphic display of the tables you have
selected from the data connection.
It also shows any join relationships among them. When you make a change
in the diagram pane,
the SQL-Syntax pane are updated to reflect your change.
You can:
* Add or remove tables and specify data columns for output.
* Create,remove or modify joins between tables.
* Run a preview window.
And specify:
* Expressions for calculated columns.
* The sort order for the query.
* Search conditions.
* Grouping criteria.
Included:
* JDBC Administrator.
* Metadata search.
* Command editor.
* Queries history.
Works with any JDBC compliant database, including : ORACLE, MS
SQLServer, MySQL, FiREBiRD and HSQLDB.
Please give it a try and let me know if you have any problems or ideas
for features.
Thanks, Nickyb
- 14
- 14
- Cannot load image in applet after placing it in a packageThis has been a much discussed topic in several newsgroups, but I still
cannot figure it out.
I got this class: htmledit.class. Normal website linking to this class as an
applet. Several image files (gif&bmp) for toolbar images.
/
| -htmledit.class
|
|-image1.gif
\-image2.gif
Applet loads, no problem. images are used in the toolbar. Applet tag calls
"htmledit.class"
Trying to get the class in a package (due to OO reasons and java 1.4 jdk) I
get:
/
|-/main
| \-htmledit.class
|
|-image1.gif
\-image2.gif
Changed the header of the htmledit.class to main package, changed the html
code to call the class "main.htmledit.class". Applet loads, get null values
from getResource() call. No images are loaded.
This applet is not (yet) part of a jar file. Tried copying the image files
to the main directory, add codebase, place them in a jar with archieve
attribute in the applet tag, calling image file with a "/" in front of it.
Why is the main applet class no longer able to access the image files when
placed in a package?
G
- 14
- Regular Expression extract all links in a page.I am trying to extract all urls for a perticular page, but without a
success.
java.util.regex.Pattern p = Pattern.compile("<a
href=\"http://(.*)\">",Pattern.MULTILINE);
java.util.regex.Matcher m = p.matcher(strhtmpage);
while ( m.find() )
{
System.out.println( "LINKS: " + m.group(1) );
}
- 16
- stable java environment on FreeBSD 5.2-RELEASE
--lrZ03NoBR/3+SXJZ
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable
Hi freebsd-java@,
I would like to setup a stable java environment on a FreeBSD 5.2-RELEASE
system. The primary goal for this is to coding java programs with
eclipse. I have read all information I found on google.com and
freebsd.org/java, but I don't get all answers for the questions I have.
;)
I had tried the installation of jdk-1.3 but the only version I get to
work was the 'linux-sun-jdk1.3'. I am a little bit confused about these
many versions around. So here are the questions. :)
1. Which JDK you'll prefer on a 5.2-R focused on stability?
2. Which steps are needed to install the prefered JDK?
3. Are there issues on the threading model (kse||thr)?
best regards,
Gordon
--=20
Gordon Bergling <email***@***.com> http://www.0xFCE3.net/
PGP Fingerprint: 7732 9BB1 5013 AE8B E42C 28E0 93B9 D32B C76F 02A0
RIPE-HDL: MDTP-RIPE "There is no place like 127.0.0.0/8"
--lrZ03NoBR/3+SXJZ
Content-Type: application/pgp-signature
Content-Disposition: inline
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.4 (FreeBSD)
iD8DBQFAFqimk7nTK8dvAqARAoeMAKDB+vdwZbTJhz1AjClDXc1Vnb4hrwCePxY1
LWCoKOXfwQQUt5P8dr4cxKc=
=UQ5f
-----END PGP SIGNATURE-----
--lrZ03NoBR/3+SXJZ--
|
| Author |
Message |
Axehelm

|
Posted: 2004-5-27 6:18:00 |
Top |
java-programmer, Pros and Cons of Static Methods
Okay, I'm in a debate over whether or not static methods are a good idea in
a general domain class.
I'm personally not a fan of static methods but we seem to be using them to
load an object. For example if you have an Employee class rather then
instantiating an instance you call a static method 'GetEmployees' and it
returns a List of Employee objects.
I'm looking for what other people are doing and if you feel this is a good
or bad idea.
Thanks
|
| |
|
| |
 |
perry anderson

|
Posted: 2004-5-27 7:17:00 |
Top |
java-programmer >> Pros and Cons of Static Methods
things are done differently in Java than C++, you are in more of truely
object-oriented world and thats not just a cute term. static methods are
really class messages, that is, methods that act upon an entire
classification of objects not just one instance. it is an elegant means
by which to send messages to all instances or rather the class itself
and thats how you have to start thinking.
i know your sort of coming at it from an anti-global variable approach
but static methods are not the same thing. typically they do not create
the same hang ups as global methods used in non object-oriented languages.
i could say more but first let me hear back if you understand what i am
saying
thanks
- perry
Axehelm wrote:
> Okay, I'm in a debate over whether or not static methods are a good idea in
> a general domain class.
>
> I'm personally not a fan of static methods but we seem to be using them to
> load an object. For example if you have an Employee class rather then
> instantiating an instance you call a static method 'GetEmployees' and it
> returns a List of Employee objects.
>
> I'm looking for what other people are doing and if you feel this is a good
> or bad idea.
>
> Thanks
>
>
|
| |
|
| |
 |
Axehelm

|
Posted: 2004-5-27 7:51:00 |
Top |
java-programmer >> Pros and Cons of Static Methods
Yes I understand what you are saying and yes I'm ant-global... :)
It just goes against what I've been taught about OO. For example a static
method cannot be overridden... correct? That seems to go against
polymorphism. Exposing multiple static methods in place of constructors
seems a bit unOO if you will to me.
"perry anderson" <email***@***.com> wrote in message
news:xz9tc.30977$email***@***.com...
> things are done differently in Java than C++, you are in more of truely
> object-oriented world and thats not just a cute term. static methods are
> really class messages, that is, methods that act upon an entire
> classification of objects not just one instance. it is an elegant means
> by which to send messages to all instances or rather the class itself
> and thats how you have to start thinking.
>
> i know your sort of coming at it from an anti-global variable approach
> but static methods are not the same thing. typically they do not create
> the same hang ups as global methods used in non object-oriented languages.
>
> i could say more but first let me hear back if you understand what i am
> saying
>
> thanks
>
> - perry
>
>
> Axehelm wrote:
> > Okay, I'm in a debate over whether or not static methods are a good idea
in
> > a general domain class.
> >
> > I'm personally not a fan of static methods but we seem to be using them
to
> > load an object. For example if you have an Employee class rather then
> > instantiating an instance you call a static method 'GetEmployees' and it
> > returns a List of Employee objects.
> >
> > I'm looking for what other people are doing and if you feel this is a
good
> > or bad idea.
> >
> > Thanks
> >
> >
>
|
| |
|
| |
 |
Silvio Bierman

|
Posted: 2004-5-27 17:15:00 |
Top |
java-programmer >> Pros and Cons of Static Methods
"Axehelm" <email***@***.com> wrote in message
news:F3atc.11571$eT4.650@attbi_s54...
> Yes I understand what you are saying and yes I'm ant-global... :)
>
> It just goes against what I've been taught about OO. For example a static
> method cannot be overridden... correct? That seems to go against
> polymorphism. Exposing multiple static methods in place of constructors
> seems a bit unOO if you will to me.
>
> "perry anderson" <email***@***.com> wrote in message
> news:xz9tc.30977$email***@***.com...
> > things are done differently in Java than C++, you are in more of truely
> > object-oriented world and thats not just a cute term. static methods are
> > really class messages, that is, methods that act upon an entire
> > classification of objects not just one instance. it is an elegant means
> > by which to send messages to all instances or rather the class itself
> > and thats how you have to start thinking.
> >
> > i know your sort of coming at it from an anti-global variable approach
> > but static methods are not the same thing. typically they do not create
> > the same hang ups as global methods used in non object-oriented
languages.
> >
> > i could say more but first let me hear back if you understand what i am
> > saying
> >
> > thanks
> >
> > - perry
> >
> >
> > Axehelm wrote:
> > > Okay, I'm in a debate over whether or not static methods are a good
idea
> in
> > > a general domain class.
> > >
> > > I'm personally not a fan of static methods but we seem to be using
them
> to
> > > load an object. For example if you have an Employee class rather then
> > > instantiating an instance you call a static method 'GetEmployees' and
it
> > > returns a List of Employee objects.
> > >
> > > I'm looking for what other people are doing and if you feel this is a
> good
> > > or bad idea.
> > >
> > > Thanks
> > >
> > >
> >
>
>
You are completely right. Static methods are what the OO-purists came up
with when they discovered that there are actually good reasons for having
non-class-member functions a-la C++ (which BTW also has static methods). The
static void main stuff is the most prominent example of that.
Static methods are usefull because they give you an escape of the
everything-is-or-should-be-an-object concept. There is nothing wrong with
using them as long as you know how to.
Silvio Bierman
|
| |
|
| |
 |
sarge_chris

|
Posted: 2004-5-27 19:04:00 |
Top |
java-programmer >> Pros and Cons of Static Methods
> It just goes against what I've been taught about OO. For example a static
> method cannot be overridden... correct? That seems to go against
> polymorphism. Exposing multiple static methods in place of constructors
> seems a bit unOO if you will to me.
You've picked on a classic issue that I personally have never found an
answer to one way or the other.
As an example - which of these is best (using your example):
class Employee
{
...
public static Collection getAllEmployees() { ... }
}
Collection allEmployees = Employee.getAllEmployees();
or:
class Employee { ... }
class EmployeeMaintenance // or some such name
{
public Collection getAllEmployees() { ... }
}
EmployeeMaintenance em = new EmployeeMaintenance();
Collection allEmployees = em.getAllEmployees();
Hard to say really IMHO.
If there was just one or two static methods on a class then I'd say
the first because it's easier to maintain. If the 'maintenance' class
expanded to many methods (searches, CRUD stuff, etc) then a separate
class is probably better for cohesion reasons.
As to whether static methods are not OO or not, I don't know, it's
probably only of interest to academics.
- sarge
|
| |
|
| |
 |
Ryan Stewart

|
Posted: 2004-5-27 19:41:00 |
Top |
java-programmer >> Pros and Cons of Static Methods
"Chris" <email***@***.com> wrote in message
news:email***@***.com...
> > It just goes against what I've been taught about OO. For example a
static
> > method cannot be overridden... correct? That seems to go against
> > polymorphism. Exposing multiple static methods in place of constructors
> > seems a bit unOO if you will to me.
>
> You've picked on a classic issue that I personally have never found an
> answer to one way or the other.
>
> As an example - which of these is best (using your example):
>
> class Employee
> {
> ...
> public static Collection getAllEmployees() { ... }
> }
>
> Collection allEmployees = Employee.getAllEmployees();
>
Redundant naming. Try Employee.getAll().
> or:
>
> class Employee { ... }
>
> class EmployeeMaintenance // or some such name
> {
> public Collection getAllEmployees() { ... }
> }
>
> EmployeeMaintenance em = new EmployeeMaintenance();
> Collection allEmployees = em.getAllEmployees();
>
What's an "employee maintenance"? OOD is about modelling real world objects.
It sounds like you're still thinking procedurally.
> Hard to say really IMHO.
>
Not hard for me. In the latter example, how many of the "employee
maintenance" objects are necessary? You should only ever need one, correct?
Allowing more than one to be instantiated is inefficient. So you have a
couple of options: make the methods static and give it a private constructor
or implement the Singleton pattern, which also involves a static method.
Whichever way you go, static methods are your best option.
> If there was just one or two static methods on a class then I'd say
> the first because it's easier to maintain. If the 'maintenance' class
> expanded to many methods (searches, CRUD stuff, etc) then a separate
> class is probably better for cohesion reasons.
>
Cohesion? That's no OOD term I've heard of.
|
| |
|
| |
 |
kevinc

|
Posted: 2004-5-27 23:30:00 |
Top |
java-programmer >> Pros and Cons of Static Methods
Classes were not meant to become repositories for functions.
Using static methods. What you in fact have, is a function.
perry anderson wrote:
> things are done differently in Java than C++, you are in more of truely
> object-oriented world and thats not just a cute term. static methods are
> really class messages, that is, methods that act upon an entire
> classification of objects not just one instance. it is an elegant means
> by which to send messages to all instances or rather the class itself
> and thats how you have to start thinking.
>
> i know your sort of coming at it from an anti-global variable approach
> but static methods are not the same thing. typically they do not create
> the same hang ups as global methods used in non object-oriented languages.
>
> i could say more but first let me hear back if you understand what i am
> saying
>
> thanks
>
> - perry
>
>
> Axehelm wrote:
>
>> Okay, I'm in a debate over whether or not static methods are a good
>> idea in
>> a general domain class.
>>
>> I'm personally not a fan of static methods but we seem to be using
>> them to
>> load an object. For example if you have an Employee class rather then
>> instantiating an instance you call a static method 'GetEmployees' and it
>> returns a List of Employee objects.
>>
>> I'm looking for what other people are doing and if you feel this is a
>> good
>> or bad idea.
>>
>> Thanks
>>
>>
>
|
| |
|
| |
 |
Bj鰎n

|
Posted: 2004-5-28 17:21:00 |
Top |
java-programmer >> Pros and Cons of Static Methods
Silvio Bierman wrote:
>>
>
> You are completely right. Static methods are what the OO-purists came up
> with when they discovered that there are actually good reasons for having
> non-class-member functions a-la C++ (which BTW also has static methods). The
> static void main stuff is the most prominent example of that.
>
> Static methods are usefull because they give you an escape of the
> everything-is-or-should-be-an-object concept. There is nothing wrong with
> using them as long as you know how to.
Class methods doesn't need to be an escape from the pure oo concept.
Look at for instance Smalltalk where you have class methods (a kind of
static). The classes themselves are instances of meta classes therefore
the "static" methods are just ordinary methods with the full inheritance
scheme (with abilities to override and call superclass's version of the
class method).
Smalltalk does not have an "operator" new, and therefore there isn't any
need for constructors either, so to instantiate a Smalltalk object one
has to send a message to the intended class. Very often one uses the
message new; like in Set new, where the message new is sent to the class
Set; but it is not uncommon to use other class methods to instantiate
like in Circle center: 10@10 radius: 45.
By using class methods to create new instances one directly exploit the
well know Abstract Factory pattern.
E.g. Filename named: 'test.text' gives and instance of NTFSFilename on a
Windows XP platform and MacOSXFilename on a Mac OS 10 platform, etc.
That is it is possible to hide platform specific details and
instantiations from the application programmer. And thereby, among other
things, one get more portable code.
Bj鰎n
|
| |
|
| |
 |
sarge_chris

|
Posted: 2004-6-1 16:50:00 |
Top |
java-programmer >> Pros and Cons of Static Methods
I hadn't meant the code examples to be examples of good practice, just
illustrating the point.
I'm surprised you've never heard the term 'cohesion', as most of the
books and articles I read are riddled with it - maybe I'm reading the
wrong stuff.
- sarge
|
| |
|
| |
 |
Alex Kay

|
Posted: 2004-6-1 17:23:00 |
Top |
java-programmer >> Pros and Cons of Static Methods
> I'm personally not a fan of static methods but we seem to be using them to
> load an object. For example if you have an Employee class rather then
> instantiating an instance you call a static method 'GetEmployees' and it
> returns a List of Employee objects.
>
> I'm looking for what other people are doing and if you feel this is a good
> or bad idea.
Hi,
IN A NUTSHELL
I know what you mean but the scenario your describe is pretty normal and ok.
That type of constructor is called a "static factory", in some circumstances
they are actually preferable. Sun use them quite a bit in Java itself.
Things like Xyz.getInstance(); Of course like everything else they need to
be used wisely.
MORE DETAILS
Pros of construction using static factory methods:
Generally you get more control and flexibility.
1. Regular constructors will create an object every time they are invoked
and only when they are invoked, but with a static factory you can have
pre-built objects. Sometimes this flexibility of *when* things are really
built is highly desirable.
2. Or you can defer real construction until the object is actually used
a.k.a lazy instantiation.
static private Blah blah;
static public Blah createBlah() {
if(blah==null)
blah= new Blah();
return blah;
}
This is good for "expensive" objects, they only get created if/when they
are used.
3. Can return any type.
eg return Collection of Whatever's
Your GetEmployees() is a good example.
4. static factory's can have meaningful names, this can be good
Whatever.createAllShoppingTrolleys()
Cons:
1. Poor naming conventions can make it hard to know that is going on
eg Whatever.getGizmo() could be a constructor but with that kind of name
you'd never know.
2. You cannot subclass (or extend) a class which only has static factory
constructors. You must use containment rather than inheritance.
Hope that helps?
Alex K
|
| |
|
| |
 |
Alex Kay

|
Posted: 2004-6-1 17:24:00 |
Top |
java-programmer >> Pros and Cons of Static Methods
> I'm personally not a fan of static methods but we seem to be using them to
> load an object. For example if you have an Employee class rather then
> instantiating an instance you call a static method 'GetEmployees' and it
> returns a List of Employee objects.
>
> I'm looking for what other people are doing and if you feel this is a good
> or bad idea.
Hi,
IN A NUTSHELL
I know what you mean but the scenario your describe is pretty normal and ok.
That type of constructor is called a "static factory", in some circumstances
they are actually preferable. Sun use them quite a bit in Java itself.
Things like Xyz.getInstance(); Of course like everything else they need to
be used wisely.
MORE DETAILS
Pros of construction using static factory methods:
Generally you get more control and flexibility.
1. Regular constructors will create an object every time they are invoked
and only when they are invoked, but with a static factory you can have
pre-built objects. Sometimes this flexibility of *when* things are really
built is highly desirable.
2. Or you can defer real construction until the object is actually used
a.k.a lazy instantiation.
static private Blah blah;
static public Blah createBlah() {
if(blah==null)
blah= new Blah();
return blah;
}
This is good for "expensive" objects, they only get created if/when they
are used.
3. Can return any type.
eg return Collection of Whatever's
Your GetEmployees() is a good example.
4. static factory's can have meaningful names, this can be good
Whatever.createAllShoppingTrolleys()
Cons:
1. Poor naming conventions can make it hard to know that is going on
eg Whatever.getGizmo() could be a constructor but with that kind of name
you'd never know.
2. You cannot subclass (or extend) a class which only has static factory
constructors. You must use containment rather than inheritance.
Hope that helps?
Alex K
|
| |
|
| |
 |
Alex Kay

|
Posted: 2004-6-1 17:24:00 |
Top |
java-programmer >> Pros and Cons of Static Methods
> I'm personally not a fan of static methods but we seem to be using them to
> load an object. For example if you have an Employee class rather then
> instantiating an instance you call a static method 'GetEmployees' and it
> returns a List of Employee objects.
>
> I'm looking for what other people are doing and if you feel this is a good
> or bad idea.
Hi,
IN A NUTSHELL
I know what you mean but the scenario your describe is pretty normal and ok.
That type of constructor is called a "static factory", in some circumstances
they are actually preferable. Sun use them quite a bit in Java itself.
Things like Xyz.getInstance(); Of course like everything else they need to
be used wisely.
MORE DETAILS
Pros of construction using static factory methods:
Generally you get more control and flexibility.
1. Regular constructors will create an object every time they are invoked
and only when they are invoked, but with a static factory you can have
pre-built objects. Sometimes this flexibility of *when* things are really
built is highly desirable.
2. Or you can defer real construction until the object is actually used
a.k.a lazy instantiation.
static private Blah blah;
static public Blah createBlah() {
if(blah==null)
blah= new Blah();
return blah;
}
This is good for "expensive" objects, they only get created if/when they
are used.
3. Can return any type.
eg return Collection of Whatever's
Your GetEmployees() is a good example.
4. static factory's can have meaningful names, this can be good
Whatever.createAllShoppingTrolleys()
Cons:
1. Poor naming conventions can make it hard to know that is going on
eg Whatever.getGizmo() could be a constructor but with that kind of name
you'd never know.
2. You cannot subclass (or extend) a class which only has static factory
constructors. You must use containment rather than inheritance.
Hope that helps?
Alex K
|
| |
|
| |
 |
Alex Kay

|
Posted: 2004-6-1 17:25:00 |
Top |
java-programmer >> Pros and Cons of Static Methods
> I'm personally not a fan of static methods but we seem to be using them to
> load an object. For example if you have an Employee class rather then
> instantiating an instance you call a static method 'GetEmployees' and it
> returns a List of Employee objects.
>
> I'm looking for what other people are doing and if you feel this is a good
> or bad idea.
Hi,
IN A NUTSHELL
I know what you mean but the scenario your describe is pretty normal and ok.
That type of constructor is called a "static factory", in some circumstances
they are actually preferable. Sun use them quite a bit in Java itself.
Things like Xyz.getInstance(); Of course like everything else they need to
be used wisely.
MORE DETAILS
Pros of construction using static factory methods:
Generally you get more control and flexibility.
1. Regular constructors will create an object every time they are invoked
and only when they are invoked, but with a static factory you can have
pre-built objects. Sometimes this flexibility of *when* things are really
built is highly desirable.
2. Or you can defer real construction until the object is actually used
a.k.a lazy instantiation.
static private Blah blah;
static public Blah createBlah() {
if(blah==null)
blah= new Blah();
return blah;
}
This is good for "expensive" objects, they only get created if/when they
are used.
3. Can return any type.
eg return Collection of Whatever's
Your GetEmployees() is a good example.
4. static factory's can have meaningful names, this can be good
Whatever.createAllShoppingTrolleys()
Cons:
1. Poor naming conventions can make it hard to know that is going on
eg Whatever.getGizmo() could be a constructor but with that kind of name
you'd never know.
2. You cannot subclass (or extend) a class which only has static factory
constructors. You must use containment rather than inheritance.
Hope that helps?
Alex K
|
| |
|
| |
 |
Hal Rosser

|
Posted: 2004-6-2 6:14:00 |
Top |
java-programmer >> Pros and Cons of Static Methods
Use each when warranted.
For instance, in a class 'Person';;; fields like name, address, height,
weight should be instance vars, but it would make sense for personCount (the
number of "Person' objects instantiated) to be static - it belongs to the
class along with the set/get methods for it.
"Axehelm" <email***@***.com> wrote in message
news:KI8tc.28988$af3.1594862@attbi_s51...
> Okay, I'm in a debate over whether or not static methods are a good idea
in
> a general domain class.
>
> I'm personally not a fan of static methods but we seem to be using them to
> load an object. For example if you have an Employee class rather then
> instantiating an instance you call a static method 'GetEmployees' and it
> returns a List of Employee objects.
>
> I'm looking for what other people are doing and if you feel this is a good
> or bad idea.
>
> Thanks
>
>
---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.690 / Virus Database: 451 - Release Date: 5/22/2004
|
| |
|
| |
 |
| |
 |
Index ‹ java-programmer |
- Next
- 1
- Finding valid ENUM values
I have a MySQL (5) database which has a table containing an ENUM column.
I'd like to (programatically) get a list of what the valid options are for
this ENUM. I've looked through the metadata but can't see anything. Can
someone point out what I'm missing?
Many thanks
- 2
- DataInputStream - random incorrect data reading...Hi,
I am working on a small java client and server program pair which at
client side packetizes data (such as jpeg image file) and appends some
header info for each packetized packet. At the server side, the
packetized data is reassembled back into the original image.
At client side I am using DataOutputStream/BufferedOutputStream:
DataOutputStream data_out = new DataOutputStream(
new BufferedOutputStream(client_socket.getOutputStream()));
data_out.writeInt(seq_Num); // part
data_out.writeLong(time_stamp); // of
data_out.writeInt(image_size); // header
data_out.writeInt(length); // for each packetized data
data_out.write(data, 0, length); // Packetized Data
On the server side I read back packetized data back sent by client and
later reassemble it back to original image:
DataInputStream data_in = new DataInputStream(
new BufferedInputStream(connection_socket.getInputStream()));
for ( ; ; ) {
seq_num = data_in.readInt();
time = data_in.readLong();
size = data_in.readInt();
dlength = data_in.readInt();
System.out.println(seq_num + ", " + time + ", " + size + ", "
+ dlength);
byte[] p_data = new byte[dlength];
rlen = data_in.read(p_data, 0, dlength);
Here's my problem
=================
When I read data back at the server side I get corrupted data when I
parse byte packetized data, that is data from DataInputStream data_in
Here's the output:
seq_num=1, time=1067733150359, size=65366, dlength=1000
Received Packet No. 1 from Node A . . .
seq_num=2, time=1067733150361, size=65366, dlength=1000
Received Packet No. 2 from Node A . . .
seq_num=3, time=1067733150363, size=65366, dlength=1000
Received Packet No. 3 from Node A . . .
seq_num=2134239293, time=5009899065144553973, size=-2132742293,
dlength=1480003007
Exception in thread "main" java.lang.OutOfMemoryError
Any ideas what causes this error? Any help would be greatly appreciated...
-John
- 3
- How to ensure a square JComponent?I have a JComponent inside some container
and want it to be square (equal width
and height) always but still resizeable
when its container is resized.
I can think of a few solutions, but none of
them are very elegant.
Thanks!
- 4
- Determining interface implementations during runtime ?Hi All,
Hope all is going well!
I was wondering if anyone had any ideas how I might be able to determine
reasonably efficiently what implementations of a given interface are
available within the current scope of available jars/classfiles during
runtime in my application?
Anyone done something like that before using reflection or similar?
Any ideas/etc appreciated.
Cheers,
Marcus
--
.....
,,$$$$$$$$$, Marcus Crafter
;$' '$$$$: Computer Systems Engineer
$: $$$$: ManageSoft Corporation
$ o_)$$$: Melbourne Australia
;$, _/\ &&:'
' /( &&&
\_&&&&'
&&&&.
&&&&&&&:
- 5
- J2ME: Transferring RMS Data from Emulator to Mobile DeviceWe are planning to use the RMS to store our mobile application's
resource data (plain text), which are mainly used for populating the
drop downs (a.k.a. Choice Group) in the GUI. We have a lot of files
that need to be deployed with the mobile application. One of them has a
size of about 300K! It is fast to just download the file(s) via http.
However, it takes a very long time to process the downloaded data. By
"process", I mean by first storing the downloaded data in an RMS record
store and then place the data to different RMS record stores according
to certain criteria. We do this "process" because the requirements
state that we cannot show hundreds of data item in the drop downs at
any given instance for the sake of usability.
I would like to know if it is possible for us to use the J2ME emulator
to first load the resource data into the emulator's RMS, and then
deploy the emulator's RMS to the mobile device. If possible, how to do
it?
Thanks!
Simon.
- 6
- java.util.Properties strange behaviourHello all,
I am facing a weird problem with java.util.Properties. I am trying to
store the Log4J configuration from a Properties object into a file
using Properties.store(OutputStream) method.
All the key-value pairs are written properly to the file except for
one: The JDBC URL.
This URL is of the form
jdbc:postgresql://my_server:myport/dbName
When this URL goes into the file, it becomes
jdbc\:postgresql\://my_server\:myport/dbName
The colons (:) get escaped. I dont know why this is happening, but
this URL is simply not recognized as a valid URL by Log4J when
encountered. How do I get rid of this problem ?
Please help.
Thanks in advance.
Best regards.
- 7
- Eclipse: Visual editor view vanishedHello.
I'm sorry for asking such helpless questions here, but I'm completely
out of ideas now.
I created a visual class and designed the gui with the visual editor
project. Well, this worked perfectly until, at some point, the class had
switched back to the standard java view from the visual editor view. And
now I can't get the visual editor back whatever I try!
Could somebody help me?
- 8
- Struts & Scaffold questionHi !
I've started to explore struts recently and now i'm looking into Artimus
example . So what i see is that through all this aplecation a lot of
Jakarta Commons pacages are used and one of them is Scaffold . It hides
original struts implementation . So i bump into several questions is it
common practice to use this pacage or there there are a lot of
alternatives or it's more recomendet to use struts and write my own
implementation. If Scaffold is a good thing to use where can i found
more matireal about it ?
Thanks a lot in advance !
- 9
- How do you use another class file... SeriouslyCan anyone tell me the exact process to use a class file in a project.
Every beginner website has the same crap about writing a "hello
world" program and then there's some presumed leap that you know how
to add class files.
Maybe this is one of those things that is considered so easy that
nobody ever mentions it but I've been looking for this process for
days and can't figure it out.
For example I have a class file that gets the path to the current
folder, the only method in it is a main method.
Now if I want to use that class file from some other project that
already has a main method how can I do it. What is the exact
"process" that I would use to somehow use that class file that gets me
the directory in a different project.
All I ever read is that class files are the building blocks of more
robust projects but I can't find anything anywhere that tells me how I
can actually use the damn class file. I'm just supposed to somehow
magically know this already.
If anyone could just assume that I am mentally retarded and tell me
exactly the steps I would need to do to use the class file I would
seriously appreciate it because I'm getting nowhere.
If it matters the ide I have is eclipse.
Thank you.
- 10
- reading / writing xmlHey,
I want to save some user data in a xml-file.
What is the best way to do that?
thnx A.T.
example xml:
<persons>
<person>
<name>Person1</name>
<address>1234, blaatstreet</address>
</person>
....
</persons>
- 11
- disabling screensaverDoes anyone know how I can disable the screensaver in my java program?
Thanks,
Martin
- 12
- 13
- Recommendations for SWT library of chart and plot widgets?Hello,
I'm looking for a library of chart and plot widgets for SWT.
I'm willing to consider both commercial and noncommercial s/w.
Chart FX has the right widgets but it is meant for the server side
of a web app, not native Java client apps, if I understand correctly.
(If Chart FX for SWT does exist, please let me know!)
Any recommendations you might have are much appreciated.
best
Robert Dodier
- 14
- JBoss/Tomcat or sth else?I greet,
(sorry for my english language + translator)
In relationship from this that I would like to learn to programme in
J2EE my
question is such:
I from what server should begin science JBoss / Tomcat or another one.
It what server was it been proper was to learn at the beginning if in
I would like to look for near future work as programmer Java.
Programming J2SE, applets is me already familiar { in some part
obviously). And even dust already first (rather successful) start take-
off from J2EE /
JavaMail :P and I tried to create own JSP + servlet'y.
As well as second question, what technology/framework to learn on
beginning and what of them are uses in work. I read recently
post that it does not it bribe to learn Struts'a because oneself him
already rather it
it uses.
Spring, Struts, Seam, Hibernate, JSF, EJB3.0, SOAP, RMI ... ?
I will add that they wake up that the technology of realization be
dependent on
from project.
- 15
- Can someone explain this to me?Hello,
I have a very strange problem here. I have found the solution, but I would
like to know what is happening.
I load a file from a JAR file, using the following code :
InputStream stream=this.getClass().getResourceAsStream(name);
if (stream!=null)
{
int size=stream.available();
byte data[]=new byte[size];
stream.read(data);
}
stream.available() returns the correct size, the size of the file in the jar
file (0x1610E).
But the above code does not work! Only the first 0x3111 bytes of the stream
are read, the rest of the array is still 0!
But it works if I do the following code !
int c;
for (c=0; c<size; c++)
{
data[c]=(byte)stream.read();
}
Could it be that the stream cannot handle such a massive data output at
once?
Have you got any idea about this?
Thanks!
|
|
|