Copy Link
Add to Bookmark
Report
Java Coffee Break Newsletter Volume 4 Issue 02
Java Coffee Break Newsletter Volume 4, Issue 2
http://www.javacoffeebreak.com/
ISSN 1442-3790
=================================================================
In this issue
* Events : JavaOne 2001 Conference (June 4-8)
* Q&A : What is the difference between public, private, and
protected keywords? Do I even need to use them?
* Q&A : When I compile a Java application using the
new JDK1.1, or Java 2 compiler from Sun, it says
that it uses "a deprecated API". What does this mean?
=================================================================
Events : JavaOne 2001 Conference (June 4-8)
If you're new to Java, you might not be aware that in early June,
almost the whole Java community grinds to a halt, stops what it's
doing, and heads to San Francisco. Why you ask? One word : JavaOne.
JavaOne is the annual conference for Java developers. While there are
other conferences throughout the year, JavaOne is the official
conference, and a must not miss event. Sun always puts on a great show,
with a diverse lineup of keynote speakers, conference presentations.
Then, of course, there is the exhibition hall, with Java companies from
all around America and the world. Plus you'll get plenty of freebies
from vendors, such as t-shirts, hats, and other logo-emblazoned
merchandise. If you're looking to get up to speed with emerging Java
technologies, or to see what's going on with your peers and your rivals,
then JavaOne is the place to be in June.
To see what you missed at last year's conference, read our coverage
at http://www.javacoffeebreak.com/articles/javaone00/index.html
=================================================================
Q&A : What is the difference between public, private, and
protected keywords? Do I even need to use them?
We use these keywords to specify access levels for member
variables, or for member functions (methods). Public variables,
are variables that are visible to all classes.
Private variables, are variables that are visible only to the
class to which they belong.
Protected variables, are variables that are visible only to the
class to which they belong, and any subclasses.
Deciding when to use private, protected, or public variables is
sometimes tricky. You need to think whether or not an external
object (or program), actually needs direct access to the information.
If you do want other objects to access internal data, but wish to
control it, you would make it either private or protected, but
provide functions which can manipulate the data in a controlled way.
Take the following example :
public class bank_balance
{
public String owner;
public int balance;
public bank_balance( String name, int dollars )
{
owner = name;
if (dollars >= 0)
balance = dollars;
else
dollars =0;
}
}
We have declared our string and integer to be public. This means
that any object in the system can change the balance (setting it
to zero, or even giving us a negative balance). This could cause
the program to fall over, even though we wrote code in our
constructor to prevent negative balances.
Instead, we should have provided a getBalance/setBalance method,
and made our balance private or proteced. Other objects can still
access the data, but they can't put invalid data in.
public class bank_balance
{
public String owner;
private int balance;
public bank_balance( String name, int dollars )
{
owner = name;
if (dollars >= 0)
balance = dollars;
else
dollars =0;
}
public int getBalance()
{
return balance;
}
public void setBalance(int dollars)
{
if (dollars >= 0)
balance = dollars;
else
dollars = 0;
}
}
=================================================================
Q&A : When I compile a Java application using the
new JDK1.1, or Java 2 compiler from Sun, it says
that it uses "a deprecated API". What does this mean?
Applications written for JDK1.0 used the existing Java API, but
with JDK1.1 onwards, some methods have been marked as deprecated.
The API has been restructured and modified, with new classes and
methods that provide similar functionality. Whenever possible, you
should modify your application to remove references to deprecated
methods/classes, and use the new alternatives offered as part of the
Java API.
For more details on exactly which parts of your code is using a
deprecated API, use the '-deprecation' parameter with the javac
compiler.
=================================================================
The Java Coffee Break Newsletter is only sent out to email
subscribers who have requested it, and to readers of the
comp.lang.java.programmer and comp.lang.java.help
newsgroups.
If you'd like to receive our newsletter, and get the latest
Java news, tips and articles from our site, then get your FREE
subscription & back issues from
http://www.javacoffeebreak.com/newsletter/
If you are an email subscriber and no longer wish to receive
the JCB Newsletter, please unsubscribe by emailing
javacoffeebreak-unsubscribe@listbot.com