Ask Questions & Get Answers at ibibo sawaal

Dan Dan's Questions & Answers

122

Rank

7597

2954

274

84

What does it mean that a method or class is abstract?

Asked by Vidya Rani in Computers & Technology at   12:38 PM on November 11, 2008

Dan Dan's Answer

An abstract class cannot be instantiated. Only its subclasses can be instantiated. You indicate that a class is abstract with the abstract keyword like this:

public abstract class Container extends Component {

Abstract classes may contain abstract methods. A method declared abstract is not actually implemented in the current class. It exists only to be overridden in subclasses. It has no body. For example,

public abstract float price();

Abstract methods may only be included in abstract classes. However, an abstract class is not required to have any abstract methods, though most of them do.

Each subclass of an abstract class must override the abstract methods of its superclasses or itself be declared abstract.

Answered at 12:51 PM on November 11, 2008

Read all answers

What does it mean that a method or field is "static"?

Asked by Vidya Rani in Computers & Technology at   12:38 PM on November 11, 2008

Dan Dan's Answer

Static variables and methods are instantiated only once per class. In other words they are class variables, not instance variables. If you change the value of a static variable in a particular object, the value of that variable changes for all instances of that class.

Static methods can be referenced with the name of the class rather than the name of a particular object of the class (though that works too). That's how library methods like System.out.println() work. out is a static field in the java.lang.System class.

Answered at 12:51 PM on November 11, 2008

Read all answers

How do I make my applets work well on multiple browsers and virtual machines?

Asked by Vidya Rani in Computers & Technology at   12:39 PM on November 11, 2008

Dan Dan's Answer

Java is cross-platform, but that doesn't mean all platforms, browsers, and virtual machines operate identically. However, there are a number of steps a developer can take to ensure that their applet works reasonably well on most browsers.

Use Java 1.0 only. Use a Java 1.0 compiler and a Java 1.0 environment to test in. Do not use Java 1.1.

From day 1, run your tests in Netscape Navigator 3.0 and earlier. Of browsers that support Java, Navigator's probably the buggiest so if you can get something to work there it's more likely to run elsewhere. In particular, do not develop your applets using the appletviewer. The appletviewer's too reliable and too stable to accurately model real user experience.

From day 1, include multiple platforms in your tests and development. You may not be able to test on every platform Java supports, but Windows 95 and the Mac are a must. The Mac VMs in Navigator are some of the worst around so it's important to write for them. Windows NT is also a nice test, but I'd stay away from Solaris unless I had lots of time. It's too stable and reliable. However, Linux makes a very nice test since it's a stable OS (which you're not testing against) combined with a buggy VM and a strange GUI (which you are testing against). If you've got multiple people working on the project, have them work on different platforms and report bugs to each other. Better yet have them switch development environments daily so programmers are forced to make sure their code works in all browsers.

Learn to love layout managers. Provide plenty of extra white space in your user interfaces. Learn to hate absolute positioning. If you must use it, be sure to check font metrics. Don't just eyeball it.

Avoid filename filters, multiple window interfaces, and other GUI features that don't translate well across platforms

Answered at 12:50 PM on November 11, 2008

Read all answers

What is java.net??????

Asked by Vidya Rani in Computers & Technology at   12:08 PM on November 11, 2008

Dan Dan's Answer

Java.net is a premier web-based, open community created to facilitate Java™ technology collaboration in applied areas of technology and industry solutions. java.net is a central gathering place for Java technology enthusiasts and existing communities across industries, platforms, and interest groups.The goal is to expand the Java™ technology portfolio of applications, tools, and services by promoting conversation and collaboration around development of practical applications across industry groups.

Answered at 12:47 PM on November 11, 2008

Read all answers

Can applets launch programs on the client?

Asked by Vidya Rani in Computers & Technology at   12:41 PM on November 11, 2008

Dan Dan's Answer

Absolutely not. This would be a security hole big enough to walk three herds of elephants, two marching bands and at least one quarter of the people AT&T laid off through.

Answered at 12:50 PM on November 11, 2008

Read all answers

What does it mean that a class or member is final?

Asked by Vidya Rani in Computers & Technology at   12:39 PM on November 11, 2008

Dan Dan's Answer

A final class can no longer be subclassed. Mostly this is done for security reasons with basic classes like String and Integer. It also allows the compiler to make some optimizations, and makes thread safety a little easier to achieve.

Methods may be declared final as well. This means they may not be overridden in a subclass.

Fields can be declared final, too. However, this has a completely different meaning. A final field cannot be changed after it's initialized, and it must include an initializer statement where it's declared. For example,

public final double c = 2.998;

It's also possible to make a static field final to get the effect of C++'s const statement or some uses of C's #define, e.g.

public static final double c = 2.998;

Answered at 12:51 PM on November 11, 2008

Read all answers

How do I append data to a file?

Asked by Vidya Rani in Computers & Technology at   12:11 PM on November 11, 2008

Dan Dan's Answer

Appending data to a file is a fairly common task. You'll be surprised to know that there was no support for file appending in JDK1.02, and developers supporting that platform are forced to re-write the entire file to a temporary file, and then overwrite the original. As most users support either JDK1.1 or the Java 2 platform, you'll probably be able to use the following FileOutputStream constructor to append data:
public FileOutputStream(String name,
boolean append)
throws FileNotFoundException
Parameters:
name - the system-dependent file name
append - if true, then bytes will be written to the end of the file rather than the beginning

Answered at 12:46 PM on November 11, 2008

Read all answers

How do I read data from a file?

Asked by Vidya Rani in Computers & Technology at   12:13 PM on November 11, 2008

Dan Dan's Answer

Example will be a program that writes a string to a file. In order to use the Java file classes, we must import the Java input/output package (java.io) in the following manner

import java.io.FileInputStream;
import java.io.FileNotFoundException;
imp ort java.io.IOException;

public class InputFileDeclared {

private FileInputStream in;

public InputFileDeclared(String filename) throws FileNotFoundException {
in = new FileInputStream(filename);
}

public String getWord() throws IOException {
int c;
StringBuffer buf = new StringBuffer();

do {
c = in.read();
if (Character.isSpace((char) c))
return buf.toString();
else
buf.append((char) c);
} while (c != -1);

return buf.toString();
}

public static void main(String[] args) throws java.io.IOException {
InputFileDeclared file = new InputFileDeclared("testing.txt");
System.out.println(file.getWord());
System.out.println(file.getWord());
System.out.println(file.getWord());
}

}

Answered at 12:45 PM on November 11, 2008

Read all answers

What fonts does Java support?

Asked by Vidya Rani in Computers & Technology at   12:13 PM on November 11, 2008

Dan Dan's Answer

Physical fonts need to be installed in locations known to the Java runtime environment. Sun's J2SE Runtime Environments look in two locations: the lib/fonts directory within the JRE itself, and the normal font location(s) defined by the host operating system. If fonts with the same name exist in both locations, the one in the lib/fonts directory is used.
Users can add physical fonts that use a supported font technology by installing them either in the lib/fonts directory within the JRE, or by installing them in a way supported by the host operating system (dropping them into the Fonts folder on Windows, using the pkgadd command on Solaris).

Answered at 12:44 PM on November 11, 2008

Read all answers

What is Clipping in java?

Asked by Vidya Rani in Computers & Technology at   12:16 PM on November 11, 2008

Dan Dan's Answer

Clipping is the technique to do limit the redrawing to just a chosen part of the image.
The graphics context can be told by the clipRect() method to only accept changes in the clipped area.
The only hard part is calculating the red outlined area above, regardless of which way the mouse moves. Study the clip() method below to see how this is done.

Answered at 12:42 PM on November 11, 2008

Read all answers

Editor's Pick

Categories

sawaal signature
sawaal free visiting card