Win a copy of Node.js Design Patterns: Design and implement production-grade Node.js applications using proven patterns and techniques this week in the Server-Side JavaScript and NodeJS forum!

Jaydeep Singh

Ranch Hand
+ Follow
since Oct 02, 2000
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Jaydeep Singh

Thanks to Mohammd, Manfred and Ankush for your help. I got the problrm in my HTML File.
Thanks
Jaydeep
20 years ago
Hi Friends,
I have written a simple applet program and trying to display it , but I'm not able to see my subcomponents, only it shows a box of that size which i mension in my HTML File.
Here is the code for both files.
GridLayoutPanel.html
< applet code=GridLayoutPanel height = 300 width = 300 >
< /applet>
*****************
GridLayoutPanel.java

Pl.help me.
Thank you very much.
jaydeep

(Edited by Cindy to format code and add spaces to the HTML commands so that they would display instead of executing)
[This message has been edited by Cindy Glass (edited February 10, 2001).]
20 years ago
Hi Friends,
I would like to display a counter variable in my applet , how can i display it.
Thanks in Advancce.
Kudeep
20 years ago
Hi,
Can someone explain well these keywords " throw / throws / throwable", and their uses , how and when we have to use them.
Pls.
Thanks in advance.
jaydeep
20 years ago
Thank you so much sir, It's working great.
But is it necessary to have the source in which I am importing package has to be all the way at different location from root or just away from the package path.
I mean to say.
like i have a package called
package com.jaydeep.util, this is c:\com\jaydeep\util\FileA.java
import com.jaydeep.util.*; this inc:\com\someanother\FileB.java
20 years ago
Hi All,
I have my package sources & classes in directory c:\com\jaydeep\util>
Here I have a file called "MyClass.java"
Contents of MyClass.java is as follows.
++++++
package com.jaydeep.util;
public class MyClass{
public static void main(String args[]){
System.out.println("From com.jaydeep.util.MyClass.java");
}
}
I'll compile in the same directory.
===================
Now I am interested to use(import) MyClass in directory structure c:\thinkj\ch05> ,Here I have a file called "MyClassb.java"
======================
import com.jaydeep.util.*;
public class MyClassb{
public static void main(String args[]){
MyClass mc = new MyClass();
}
}
======
In My AUTOEXEC.BAT is like this.
SET CLASSPATH=.;
***********
Now my questions are as follows,
1> Is this is the correct way of declaring package & importing.
2> Can i import any package from anywhere, or there is some certain rule, if yes please explain here.
3> I am just wondering I can use(import) MyClass, only if my source of "MyClassb.java" is in root directory, which puts a kind or restriction.

Thanks in advance for your valuable help.
Jaydeep


------------------
20 years ago
Hi,
I think here everybody is giving correct and clear explanation,Which i would like to clear is Garbage collector is run by a low priroity thread, for which we can not schedule, But certainly before executing "new" it checks for the available memory on the heap, if it's not enough it will run garbage collector will run.
If I'm wrong please correct me.
Thanks
jaydeep
20 years ago
Hi,
I'm just wondering, I did not get any response from anybody,
What happened is it not up to standard or what???
With Regards
jaydeep
20 years ago
Overloading : I hope you are familiar with the concept of constructor if yes then you won the game , overloading is nothing, remember in different-fifferent way you are calling your constructor(of the same class), how you are differentiating your one constructor (of the same class) to another constructor(of the same class).
Here key point is just base on the parameter list, return type is optional. Now overloading does not mean only with constructor, you can play, with other methods also. Constructor is also one method, with having the name similar to your class name.

Overriding: When you are talking about the overriding , Only think about inheritance, so if are, then again you won the game, you are theMan.
Remember : you have to be very carefull about these two things because compiler could not understand what's in your mind what you want to do either overloading or overriding. It won't give you any error. Unfortunately you will not get your expected result, then you are in trouble man.
POLYMORPHISM : very interesting thing, Poly mean what " more than one " , don't get upset here, I know you are qualified person, I'm just trying to take you on the road.
POLY ===>> MORE THAN ONE
POLYMORPHISM ===>> Means refering an object MORE THAN ONE (POLY)way .
EXAMPLE: I have a class called Animal(parent class) and subclass is say Dog, can i inherit Dog from Animal, I know you will say yes.When I am inheriting Dog from Animal, it means whatever is available in Animal class I can get in Dog class also right. So do you allow me directly to reffer Dog object by the Animal reference, atleast for the similar behaviour's, your answer is yes because Dog is nothing just inherited version is of Animal.So that's the POLYMORPHISM .
Examle:
class Animal{
void play(){
System.out.println("Animal.play()");
};
void move(){
System.out.println("Animal.move()");
};
}
class Dog extends Animal{
//overriding in play method
void play(){
System.out.println("Dog.play()");
};
void move(){
System.out.println("Dog.move()");
};
void bark(){
System.out.println("Dog.bark()");
};
}
public class TestPolymorphismOverriden{
public static void main(String args[]){
//(Late)Binding because the right object(Dog) will be assigned at run time. to the Animal reference "d".
Animal d = new Dog();
d.play();
d.move();
}
}

Hope it helps.
jaydeep


20 years ago
Hi Satish,
Have you downloaded SDK1.2.2(JAVA compiler),if yes check the classpath. Go to the www.textpad.com it's free for evaluation, install it.
After that just open the file , click at the tool you can do this, But this is a shortcut, my suggestion is first better to understand whole story.At javaranch site itself lot of good tutorials are here read them, it will help you.
Welcome to javaFamily.
20 years ago
Hi Friends,
I have two problems in understanding the following code, solved example of TIJ.
Prblem 1>
When we will pass the argument as "finalize"from the command line, it will check "if{--else --}" condition is true,then how the main() will proceed???
Problem 2> Hard time to understand the flow of the finalise() method in respect of composit class and inheritence.
Pl. if someone can explain it, I will be more gratefull to her/him.
thanksInAdvance
Jaydeep

c07:Frog.java
// Testing finalize with inheritance.
class DoBaseFinalization {
public static boolean flag = false;
}
class Characteristic {
String s;
Characteristic(String c) {
s = c;
System.out.println(
"Creating Characteristic " + s);
}
protected void finalize() {
System.out.println(
"finalizing Characteristic " + s);
}
}
class LivingCreature {
Characteristic p =
new Characteristic("is alive");
LivingCreature() {
System.out.println("LivingCreature()");
}
protected void finalize() {
System.out.println(
"LivingCreature finalize");
// Call base-class version LAST!
if(DoBaseFinalization.flag)
try {
super.finalize();
} catch(Throwable t) {}
}
}
class Animal extends LivingCreature {
Characteristic p =
new Characteristic("has heart");
Animal() {
System.out.println("Animal()");
}
protected void finalize() {
System.out.println("Animal finalize");
if(DoBaseFinalization.flag)
try {
super.finalize();
} catch(Throwable t) {}
}
}
class Amphibian extends Animal {
Characteristic p =
new Characteristic("can live in water");
Amphibian() {
System.out.println("Amphibian()");
}
protected void finalize() {
System.out.println("Amphibian finalize");
if(DoBaseFinalization.flag)
try {
super.finalize();
} catch(Throwable t) {}
}
}
public class Frog extends Amphibian {
Frog() {
System.out.println("Frog()");
}
protected void finalize() {
System.out.println("Frog finalize");
if(DoBaseFinalization.flag)
try {
super.finalize();
} catch(Throwable t) {}
}
public static void main(String[] args) {
if(args.length != 0 &&
args[0].equals("finalize"))
DoBaseFinalization.flag = true;
else
System.out.println("not finalizing bases");
new Frog(); // Instantly becomes garbage
System.out.println("bye!");
// Force finalizers to be called:
System.gc();
}
} ///:~
20 years ago
I just overlooked. I'm sorry. about it. similar, which is not possible.
Instrument[] orchestra = new Instrument[5];

Instrument() orchestra = new Instrument();
Thanks Carl & Bodie,
I understand clearly, I got confused because of the little similarity in above lines.
Kind Regards.
Jaydeep

20 years ago
Thanks Frank. I did it in he same way.
Thanks
jaydeep
20 years ago
Hi Friends,
This is the solved exmaple from Thinking In JAVA, CHAPTER 07/
As we know abstract class can not be instantiated, but in this code , I have seen it. Even it compiles fine and working also.
Pl. can anybody explain it.

Thanks In Advance.
Jaydeep
//: c07:music4:Music4.java
// Abstract classes and methods.
import java.util.*;
abstract class Instrument {
int i; // storage allocated for each
public abstract void play();
public String what() {
return "Instrument";
}
public abstract void adjust();
}
class Wind extends Instrument {
public void play() {
System.out.println("Wind.play()");
}
public String what() { return "Wind"; }
public void adjust() {}
}
class Percussion extends Instrument {
public void play() {
System.out.println("Percussion.play()");
}
public String what() { return "Percussion"; }
public void adjust() {}
}
class Stringed extends Instrument {
public void play() {
System.out.println("Stringed.play()");
}
public String what() { return "Stringed"; }
public void adjust() {}
}
class Brass extends Wind {
public void play() {
System.out.println("Brass.play()");
}
public void adjust() {
System.out.println("Brass.adjust()");
}
}
class Woodwind extends Wind {
public void play() {
System.out.println("Woodwind.play()");
}
public String what() { return "Woodwind"; }
}
public class Music4 {
// Doesn't care about type, so new types
// added to the system still work right:
static void tune(Instrument i) {
// ...
i.play();
}
static void tuneAll(Instrument[] e) {
for(int i = 0; i < e.length; i++)
tune(e[i]);
}
public static void main(String[] args) {
Instrument[] orchestra = new Instrument[5];
int i = 0;
// Upcasting during addition to the array:
orchestra[i++] = new Wind();
orchestra[i++] = new Percussion();
orchestra[i++] = new Stringed();
orchestra[i++] = new Brass();
orchestra[i++] = new Woodwind();
tuneAll(orchestra);
}
} ///:~
20 years ago
Thanks Marlyn,
I will try but, I'm not sure about the name(left side of the Extension), How can i recover that, That's really important.
Thanks
jaydeep
20 years ago