vijay malhotra

+ Follow
since Nov 26, 2000
Merit badge: grant badges
For More
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 vijay malhotra

21 years ago
The following code does not compile and give the following error
Error :-
----- class h1 is public, should be declared in a file named
public interface h1
1 error
public interface h1
void callme();
public class m1 implements h1
public void callme()
public static void main(String args[])
m1 m = new m1();
Can't the interfaces being declared public ? This entire code is
in file
Hi Manfred
Thanks for replying. But I still have doubt.I was not able to understand clearly.
But what if we still want that a method of an interface should be kept as private method for the class that implements the interface ? Will the compiler will report an error ? If yes why?
Why the methods that implement an interface must be declared public ?
Please tell me how to connect an applet to a servlet ?
Give a small piece of code and some other documentation
available on the net .
22 years ago
There are 2 applets , a1 & b1. These 2 applets are in two different html files
for ex a1.html contains applet a1 and b1.html contains applet b1.
Applet a1 has a button labeled "Go To b1" and Applet b1 contains
button labeled "Go To a1".
The location of applet classess and html files containing the
applets is C:\Applet
What I want is that on pressing button "Go To b1" in applet a1
it should load the webpage b1.html containing applet b1.
And on pressing button "Go To a1" of applet b1 it should load
the webpage a1.html containing applet a1.
Please tell me that, is the above mentioned situation possible
If Yes, please do provide the code in your answer for both
the applets and event handling part also.
Thanks in advance.
22 years ago
Following are the 3 files , and & are the applet files while is
the event handling file.
What I want the output is that when I press the button in
applet of a1 then the text in applet b1 should change
from "HI THERE" to "Hello World" , this change of
message is done in class
But when I Execute the program it throws the following exception
Exception occurred during event dispatching:
at e1.actionPerformed(
at java.awt.Button.processActionEvent(
at java.awt.Button.processEvent(
at java.awt.Component.dispatchEventImpl(
at java.awt.Component.dispatchEvent(
at java.awt.EventQueue.dispatchEvent(
at java.awt.EventDispatchThread.pumpOneEvent(
at java.awt.EventDispatchThread.pumpEvents(

Following is the code for the 3 files
/** **/
import java.awt.*;
import java.applet.*;
/*<applet code=a1 width=200 height=200>
public class a1 extends Applet
Button b1 =new Button("Change It");
e1 e = new e1(this);
String str = "";
public void init()

public void paint(Graphics g)
/** **/
import java.awt.*;
import java.applet.*;
/*<applet code=b1 width=200 height=200>
public class b1 extends Applet
e1 ee = new e1(this);
String msg = "HI THERE";
public void paint(Graphics g)
/** **/
import java.awt.event.*;
public class e1 implements ActionListener
a1 a;
b1 b;
e1(a1 a)
this.a = a;

e1(b1 b)
this.b = b;
public void actionPerformed(ActionEvent ae)

a.str = "Just Do It";
b.msg = "Hello World";


Q1. Why the exception is being thrown , please do tell the cause ?
Q2. How can I correct this problem so that I get the desierd output ?
22 years ago
In the code given below there are 2 classes and your
in the package mybanks.
The label of JButton b1 is initially set to "In Mybank" in class
I want to change this label to "In Yourbank" from set method defined in
class , But when I compile this program compiler generates
the following error
E:\javaprog\mybanks\ cannot resolve symbol
symbol : variable b1
location: class mybanks.mybank
m.b1.setText("In Your Bank");
1 error
Following is the code of 2 classes
/** **/
package mybanks;
import java.awt.*;
import javax.swing.*;
<applet code="mybank" width=250 height=150>
public class mybank extends JApplet

public void init()

Container contentpane = getContentPane();

JButton b1 = new JButton("In Mybank");
yourbank y = new yourbank();

/** **/
package mybanks;
class yourbank
void set(mybank m)
m.b1.setText("In Your Bank");
Q1. Why the compiler is giving the error even though I am passing
the reference with the help of "this" from init()method of mybank class in the statement y.set(this);
Q2. How can I rectify the problem so that I am able to change
the text of JButton b1 from the set method defined in class
yourbank ?
22 years ago
Well the oracle is installed at location
location :- D:\ora
I wrote D:\orawin by mistake , Sorry
I am unable to connect my java application to Personal Oracle8 database.
I am working on the windows platform.
I have installed JDBC OCI and THIN drivers.
Oracle is installed at D:\orawin
Using java 1.3
Please send me the simple java code which connects to Oracle
database and retrieves list of Employee names from Employee table.
Tell me how to configure JDBC so that java application is able
to connect to Oracle database ?
What all should be added in the autoexec.bat file. How the confiurigation
is to be done.
In the getConnection statement what path is to be given to connect to
the database ?
Please explain the procedure step by step.

Some More details are as under:-
Following is the Error Reported when I Execute the program:-
Exception in thread "main" java.sql.SQLException: Connection refused: no further
at oracle.jdbc.dbaccess.DBError.check_error(
at oracle.jdbc.driver.OracleConnection.<init>(
at oracle.jdbc.driver.OracleDriver.connect(
at java.sql.DriverManager.getConnection(Unknown Source)
at java.sql.DriverManager.getConnection(Unknown Source)
at Employee.main(
Following is the Java Code I am using :-
* This sample shows how to list all the names from the EMP table
* It uses the JDBC OCI8 driver. See the same program in the
* thin or oci7 samples directories to see how to use the other drivers.
// You need to import the java.sql package to use JDBC
import java.sql.*;
class Employee
public static void main (String args [])
throws SQLException, ClassNotFoundException
// Load the Oracle JDBC driver
Class.forName ("oracle.jdbc.driver.OracleDriver");
// Connect to the database
// You can put a database name after the @ sign in the connection URL.
Connection conn =
DriverManager.getConnection ("jdbc:Oracle:thin:@localhost:1521:local", "scott", "tiger");
// Create a Statement
Statement stmt = conn.createStatement ();
// Select the ENAME column from the EMP table
ResultSet rset = stmt.executeQuery ("select ENAME from EMP");
// Iterate through the result and print the employee names
while ( ())
System.out.println (rset.getString (1));
Following are the contents of autoexec file:-
SET path=C:\windows;C:\windows\command;.;c:\jdk1.3\bin;c:\jdk1.3\lib;C:\Progra~1\JavaSoft\JRE\1.3bin;
set CLASSPATH=.;C:\jdk1.3\lib\;C:\jdk1.3\lib\tools.jar;D:\ora\jdbc\lib\
set TOMCAT_HOME=c:\tomcat
set JAVA_HOME=c:\jdk1.3
Why in a static method for ex main() method we cannot
declare static variable ?
public static void main(String args[])
static int i;
Thanks Stevie in helping me understand the new concept
about the Behavior of polymorphic methods inside constructors.
Please explain what does the author means by :
"A dynamically-bound method call, however, reaches �forward� or �outward� into the inheritance hierarchy. It calls a method in a derived class."
Why a dynamically bound method call have to reach forward in the
inheritence hierarchy ?
Hello Stevie
This is in reference to your reply for question no 1 where
you gave reply from Bruce Eckel's "Thinking in Java".
If you are having the electronic version of the book
Please let me know the page number of the book where this behaviour is mentioned i.e the answer you gave to my question 1.
Hello Stevie
This is in reference to my 1st question
I have read the late binding (polymorphism) from the book , but in this
case according to me the late binding does not takes place.
Late binding takes place when we assign a sub class object to
super class reference object. During the run time it's decided
to which sub class object the super class reference is pointing to.
On the basis of that appropriate calls to the method are made.
This would have taken place in this example if in the main method
we had
Process p = new Processor();
where Process is the super class and Processor is the sub class.
But in this example it's like this
Processor p = new Processor();
Then what is happening when we make a call in Process class constructor
What this 'this' will do ?
Secondly if we have 2 variables for example int i = 100; in the
super class and int i = 200; in the subclass and if we want
to print the value of i from super class then i = 100 will
get printed , even though in the main method if we have
made the object like this
Processor p = new Processor();
See the code discussed in the previous posts.
Please explain.
I am unable to understand why the method of the subclass Processor
is called from the constructor of super class Process , even though
the call is made with the use of 'this'.

Process() //constructor of Process
this.methodA(); // this invokes subclass Processor method
1. According to me the methodA() of super class Process should be called.
Even if we do not use this , still the method of Processor class is called.
2. How can we call the methodA() of Process class from it's constructor.
Please explain the 1st question in detail.