Lalit K Kumar

Ranch Hand
+ Follow
since Jan 29, 2004
Cows and Likes
Total received
In last 30 days
Total given
Total received
Received in last 30 days
Total given
Given in last 30 days
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Lalit K Kumar

try this one out.
To convert long to int :-
total =total+Integer.parseInt(String.valueOf(text));
To convert int to long :-
text =text+Long.parseLong(String.valueOf(total));
[ February 26, 2004: Message edited by: Lalit K Kumar ]
15 years ago
Lazy initialization is postponing the initialization of a variable until it is really needed.
More information at
15 years ago
hi shane,
I really could'nt found which parameters do you want to pass. but lets say you want to pass variable x (of int type). then in your "decodemessage" class set the properties.
public int X;
public int getX()
return X;
public void setX(int temp)
X = temp;
Similarly for all your other variables. you can write this code at the end of you current code.
15 years ago
hi wu,
welcome to java ranch. its your friend ,lalit, from India. don't ever hesitate to post any query.
15 years ago
hi ranchers,
I have a small problem. I have one class in java. whenever a key is pressed i want to determine whether the specified key is a regular input key or a special key that requires preprocessing. (this was done by using the method "IsInputKey" in C#)
bye n regards.
[ February 23, 2004: Message edited by: Lalit K Kumar ]
15 years ago
here is second posting.
65.) An interface defines a protocol of behavior that can be implemented by any class anywhere in the class hierarchy. An interface defines a set of methods but does not implement them. A class that implements the interface agrees to implement all the methods defined in the interface, thereby agreeing to certain behavior.
So, we can different implications of same method (that is in interface) in different classes.
69.) In object-oriented programming, polymorphism refers to a programming language's ability to process objects differently depending on their data type or class. More specifically, it is the ability to redefine methods for derived classes. For example, given a base class shape, polymorphism enables the programmer to define different area methods for any number of derived classes, such as circles, rectangles and triangles. No matter what shape an object is, applying the area method to it will return the correct results. Polymorphism is considered to be a requirement of any true object-oriented programming language (OOPL).
72.) Within a class definition, you can specify functions as being "virtual". Virtual functions can be re-implemented by sub-classes. Say you declare the function within the class Synchronous:
virtual void getReady();

Whatever your class needs to do to get ready will be done in getReady(). Now, a sub-class (say QuintSynchronous) can also delcare this function:

virtual void getReady();

However, it may do something else to get ready. It may, however still wish to call the getReady() function of its parent class, this can always be done by specifying the name of the parent class to distinguish between the own implementation of getReady() and the one of the parent class:
Purely Virtual functions.
Sometimes, a base class doesn't implement any functionality, but defines a function that the sub-classes necessarily need to provide. The rest of the code can then rely on using this class, no matter what kind of sub-class is used. Such functions are called purely virtual and defined using "=0": void getReady()=0; // I don't implement anything, but the sub-classes need to !

This is extremely useful when using pointers to an object, as the rest of the code can stay umodified when substituting one sub-class for another, if the rest of the code only depends on the functions declared in the parent-class (for instance Quintessence or Perturbation).
88.) Java has absolutely no control over hardware
Java has no pointers
Java's class declaration syntax is alot easier than C++
Java has no header-files
Java has an automatic garbage collection
Java is multithreaded
15 years ago
Hi ,
To make the posting readable I will post the answeres in two parts (a total of 9 questions).
17. Yes I have used the hashtables and dictionary. Here are the differences I found :-
A dictionary is a key-value pair somewhat akin to a hashtable. The crucial difference between the two structures is that a dictionary supports the notion of multi-keyed data whereas a hashtable uses a single object as a key
48. A lightweight component is one that "borrows" the screen resource of an ancestor (which means it has no native resource of its own -- so it's "lighter").
The advantages of creating lightweight components are the following:
The Lightweight component can now have transparent areas by simply not rendering to those areas in its paint() method (although, until we get full shape support from Java2D, the bounding box will remain rectangular).
The Lightweight component is "lighter" in that it requires no native data-structures or peer classes.
There is no native code required to process lightweight components, hence handling of lightweights is 100% implemented in common java code, which leads to complete consistency across platforms.
62. Difference between Application and Applet
The difference between an application and an applet, is that an applet is used in a browser, and an application, in a stand alone mode. A Java applet is made up of at least one public class that has to be subclassed from java.awt.Applet. The applet is confined to living in the user's Web browser, and the browser's security rules, (or Sun's appletviewer, which has fewer restrictions).
In an application, if you want to "show" something, you have to declare one or more panel, and add your stuff in it. In an applet, you only add your stuff directly into your applet. (Well, because an applet is just a kind of panel 8). A Java application is made up of a main() method declared as public static void that accepts a string array argument, along with any other classes that main() calls. It lives in the environment that the host OS provides.
63. Serializable is a tagging interface; it prescribes no methods. It serves to assign the Serializable data type to the tagged class and to identify the class as one which the developer has designed for persistence.
64. Difference between and servlet
Servlets are effectively a Java version of CGI scripts, which are written in Perl, C, C++, UNIX shell scripts, etc. There are however, a few important differences.
When a CGI program (or script) is invoked, what typically happens is that a new process is spawned to handle the request. This process is external to that of the webserver and as such, you have the overhead of creating a new process and context switching, etc. If you have many requests for a CGI script, then you can imagine the consequences! Of course, this is a generalization and there are wrappers for CGI that allow them to run in the same process space as the webserver. I think ISAPI is/was one of these.
Java Servlets on the other hand actually run inside the webserver (or Servlet engine). The developer writes the Servlet classes, compiles them and places them somewhere that the server can locate them. The first time a Servlet is requested, it is loaded into memory and cached. From then on, the same Servlet instance is used, with different requests being handled by different threads.
Of course, being Java, the compiled Servlet classes can be moved from one Servlet compatible webserver to another very easily. CGI programs or scripts on the other hand may be platform dependent, need to be recompiled or even webserver dependent
15 years ago
hi stephen,
I did'nt said that you should'nt pass the values to the constructor. i said that it is not the preferred way. In our case there are only 3 variables so we can also pass it through constructor. but lets say we want to pass some 10 variables. then what will you do? pass all the 10 variables through constructor. In that way your code will look dirty.
In the code snippet I posted , I just took an example of passing a string value. If you want to pass any other datatype , you can do so by simply replacing the keyword "String" by your "required datatype"
15 years ago
I do not totally agree with the explains given. Infact the keyword "static" is crucial in the sense that it makes sure that the second object of the same kind is not created . so if the main is called back then the keyword "static" prevents it from creating another object
15 years ago
hi shane,
you can do it in two different ways. the first one is to pass it in the constructor of the class in which you want to use it. but this is'nt the preferred way (since you have to pass 3 values).
the second method is to make these 3 values as properties (by using get-set). since yuor other class is in same project you can access it directly there.
here is a snapshot.
public String aaa;
public String getaaa()
return aaa;
public void setaaa(String X)
aaa = X;
15 years ago
whenever you inherit from a class you get all the methods of superclass automatically inherited. you can apply your own implementation if you wish (but it is'nt necessary)
if you inherit from an interface you are bound to implement all the methods contained in the interface,
[ February 20, 2004: Message edited by: Lalit K Kumar ]
15 years ago
Remember the extension of your manifest file must be .tmp and not .txt.
manifest.tmp must contain the following text:
Name: yourfilename.class
Java-Bean: True
now run the command
jar cfm yourfilename.jar manifest.tmp yourfilename.class
give the path of manifest file (instead of manifest.tmp) in case it is not in the same folder as your files are.
15 years ago
In your code snapshot , you have'nt initialized your variable "result". though you have assigned the variable some value depending on your "if" condition , but it is'nt enough. since you are assigning the value if a particular condition gets fulfilled , it would be advisable if you initialize your "result" by some value (say 0).
this way your problem will be solved. here is the snapshot:-
else {
// get input from TextField
int result =0 ; //CHANGE MADE TO THIS LINE
int temperature = Integer.parseInt(input.getText().trim());
// get selected type of conversion and convert it
if (fahrenheit.getState() == true)
result = 5 * (temperature - 32) / 9;
if (celsius.getState() == true )
result = (9 * temperature / 5) + 32;
// format the output
15 years ago
I guess you intend to make a bean and use it in your program.
Following are the steps to do so :-
(1)Write a javabean in jbuilder (or any other ide).Don't forget to implement
(2)Make sure the CLASSPATH environment variable is set to point to all needed .class (or .jar) files
(3)Compile the bean (by using javac filename)
(4)Create a manifest.tmp file , the contents of which are
Name: SimpleBean.class
Java-Bean: True
(5)Create the JAR file by using the command
jar cfm filename.jar manifest.tmp filename.class
(6)Load the JAR file into the ToolBox. Select the File|LoadJar... menu item
15 years ago
I guess you might be using three different textboxes to get the user input (firstname,middlename and surname).
to get the Initials you can use jTextBox1.charAt(0) and similarly for other textboxes.
To get the total length add the length of all the textboxes. (jtextBox1.length()+...)
15 years ago