File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Java in General and the fly likes facing error when working with Remote invocation method Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "facing error when working with Remote invocation method" Watch "facing error when working with Remote invocation method" New topic
Author

facing error when working with Remote invocation method

Laxmi Bhavisetti
Greenhorn

Joined: Oct 11, 2011
Posts: 16
The error is a HashTable is a raw type. References to generic type Hashtable<K,V> should be parameterized.


import java.util.Hashtable;
import java.rmi.server.UnicastRemoteObject;
import java.rmi.RemoteException;

public class BankManagerImpl implements BankManager {
private Hashtable accounts;
private Hashtable clients;

// public No-argument constructor
public BankManagerImpl()
throws java.rmi.RemoteException {
initialize();
}

public Account getAccount(String accountNumber)
throws RemoteException {
AccountImpl account = (AccountImpl)accounts.get(accountNumber);
return account;
}

public Client getClient(String clientName)
throws RemoteException {
ClientImpl client = (ClientImpl)clients.get(clientName);
return client;
}

public void initialize()
throws java.rmi.RemoteException {
// Create the hashtables
accounts = new Hashtable(20);
clients = new Hashtable(10);
// Create clients and put them in the hashtable
Client clientCharlie = new ClientImpl(this, "Charlie");
UnicastRemoteObject.exportObject(clientCharlie);
Client clientShannon = new ClientImpl(this, "Shannon");
UnicastRemoteObject.exportObject(clientShannon);
clients.put("Charlie", clientCharlie);
clients.put("Shannon", clientShannon);

// Create accounts:
// * put them into the hashtable
// * associate them with clients
Account account;
account = new AccountImpl(this, clientCharlie, "4434");
((AccountImpl)account).deposit(500);
UnicastRemoteObject.exportObject(account);
accounts.put("4434", account);
account = new AccountImpl(this, clientCharlie, "4461");
((AccountImpl)account).deposit(600);
UnicastRemoteObject.exportObject(account);
accounts.put("4461", account);
account = new AccountImpl(this, clientShannon, "6678");
((AccountImpl)account).deposit(700);
UnicastRemoteObject.exportObject(account);
accounts.put("6678", account);
}
}
naved momin
Ranch Hand

Joined: Jul 03, 2011
Posts: 692

Laxmi Bhavisetti wrote:The error is a HashTable is a raw type. References to generic type Hashtable<K,V> should be parameterized.




now it look nice ....


The Only way to learn is ...........do!
Visit my blog http://inaved-momin.blogspot.com/
John Jai
Bartender

Joined: May 31, 2011
Posts: 1776
The error is a HashTable is a raw type. References to generic type Hashtable<K,V> should be parameterized.

This is not an Error but a warning. From Java version 1.5, you are advised to use generics for collections. You have to specify the type of objects the Hashtable will hold.

You have used a String as the key and Account / Client objects as value. So change the Hashtable variables to



and initialize them like



Use HashMap instead of an Hashtable if you need not bother about concurrency (multi threading)
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19696
    
  20

It's not an error, it's a warning. And you can prevent it by reading this.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Harsha Smith
Ranch Hand

Joined: Jul 18, 2011
Posts: 287
Right on top of the declaration use

@SuppressWarnings("unchecked")


you may consider using ConcurrentHashMap instead of Hashtable
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38865
    
  23
I think Rob’s suggestion to learn the generics properly is far better than suppressing the warnings.
Laxmi Bhavisetti
Greenhorn

Joined: Oct 11, 2011
Posts: 16
Thank you guys, thannks for your help. Im totally new to java. And now im workign with remote method invocation.
Winston Gutkowski
Bartender

Joined: Mar 17, 2011
Posts: 7801
    
  21

Laxmi Bhavisetti wrote:...Im totally new to java. And now im workign with remote method invocation.

Blimey. I guess teaching styles have changed since I was a trainee.

Winston


Isn't it funny how there's always time and money enough to do it WRONG?
Articles by Winston can be found here
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38865
    
  23
Winston Gutkowski wrote: . . . Blimey. . . .
Careful. If you go round saying things like that, people will think you’re a Cockney
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19696
    
  20

RMI is definitely not a beginner's topic. It's not that advanced either, but definitely something I wouldn't recommend starting with until you have some experience.
Winston Gutkowski
Bartender

Joined: Mar 17, 2011
Posts: 7801
    
  21

Campbell Ritchie wrote:Careful. If you go round saying things like that, people will think you’re a Cockney

Nah. Old Lewes Bonfire Boy, me.

Winston
Laxmi Bhavisetti
Greenhorn

Joined: Oct 11, 2011
Posts: 16
Hi, this another error im facing. When im working with simple banking system.
The error is AccountImpl.java:38: getCash(long) in AccountImpl cannot implement getCash(long
in Account: overriden method does not throw NoCashAVailableException
public long getCash(long amount)

import java.rmi.*;

public class AccountImpl implements Account {

private BankManager bankManager;
private Client client;
private long balance;
private String accountNumber;

// public constructor
public AccountImpl(BankManager bankManager, Client client
, String accountNumber) {
this.bankManager = bankManager;
this.client = client;
this.balance = 0;
this.accountNumber = accountNumber;
}

public void deposit(long amount) {
balance += amount;
}

public BankManager getBankManager()
throws RemoteException {
return bankManager;
}

public Client getClient()
throws RemoteException {
return client;
}

public long getBalance()
throws RemoteException {
return balance;
}

public long getCash(long amount)
throws NoCashAvailableException, RemoteException {
if (amount > balance) {
throw new NoCashAvailableException();
}
balance = balance - amount;
return amount;
}
}


I tried to include try and catch on the above program like below. But im still facing the same erro
can you please help me
public long getCash(long amount)
throws RemoteException {
if (amount > balance) {
try {
throw new NoCashAvailableException();
} catch (NoCashAvailableException e) {
e.printStackTrace();
} finally {
}
}
balance = balance - amount;
return amount;
}
Laxmi Bhavisetti
Greenhorn

Joined: Oct 11, 2011
Posts: 16
hehe im not that new to java as well. Ive just finished sam's java 2 version in 21 days. like java programming, advanced and swings :P
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38865
    
  23
Lewes? I havent’t been there for nearly a year. Towards the end of last October, I went round Sahf Lunnon and the Sahf Coast visiting friends, while the Missus was wiv her skin-and-blister at Bromley (the Kent version, not -by-Bow).

If you declare a method and try to override it, the overriding method should not throw any “new” exceptions, ie Exceptions which cannot be thrown by the superclass method. The compiler will not notice if it is an unchecked Exception, but obviously NoCashAvailableException is a checked Exception which the superclass method does not declare.
Laxmi Bhavisetti
Greenhorn

Joined: Oct 11, 2011
Posts: 16
Yeah but i declared a seperate class with that exception

public class NoCashAvailableException extends Exception {
}

So, i dont need to show this exception in the AccountImpl.
Joanne Neal
Rancher

Joined: Aug 05, 2005
Posts: 3556
    
  15
Campbell Ritchie wrote:Lewes? I havent’t been there for nearly a year. Towards the end of last October, I went round Sahf Lunnon and the Sahf Coast visiting friends, while the Missus was wiv her skin-and-blister at Bromley (the Kent version, not -by-Bow).


Please UseRealWords


Joanne
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38865
    
  23
You can only declare it in the AccountImpl class if it throws the same Exception or its supertype in the supertype method.

AccountImpl? What an unpronounceable name for a class; call it Account and call the superclass AbstractAccount, or BankAccount extends/implements Account or similar.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38865
    
  23
Joanne Neal wrote: . . . Please UseRealWords
I am a Cockney, even though I only spent a short time living in the Smoke. Those are real words, Joanne
Winston Gutkowski
Bartender

Joined: Mar 17, 2011
Posts: 7801
    
  21

Campbell Ritchie wrote:Towards the end of last October, I went round Sahf Lunnon and the Sahf Coast visiting friends, while the Missus was wiv her skin-and-blister at Bromley...

Oh...does that make her a "blister of Kent" or a "Kentish blister"? Always forget that one.

Winston
Pat Farrell
Rancher

Joined: Aug 11, 2007
Posts: 4658
    
    5

Laxmi Bhavisetti wrote: Im totally new to java. And now im workign with remote method invocation.

If you are new to Java, I would strongly recommend that you stay away from RMI. Very very far away.

You don't need it. You are much better off passing messages rather than objects and doing remote invocation.
Laxmi Bhavisetti
Greenhorn

Joined: Oct 11, 2011
Posts: 16
Campbell Ritchie wrote:You can only declare it in the AccountImpl class if it throws the same Exception or its supertype in the supertype method.

AccountImpl? What an unpronounceable name for a class; call it Account and call the superclass AbstractAccount, or BankAccount extends/implements Account or similar.



Well we use AccountImpl because it is implementation, second phase in remote method invocation. And the exception is defined in another class and it has no subclasses.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38865
    
  23
It’s still bad design to have that sort of name for your class.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38865
    
  23
Winston Gutkowski wrote: . . .does that make her a "blister of Kent" or a "Kentish blister"? Always forget that one.

Winston
Neither, nor. She was born at Balham, which is in Surrey, even though they now call it London. If she’d been born at Bromley she would be a Kentish Maid; east of the Medway it would be a Maid of Kent. Still “Maid” after 30 years of marriage and two children!
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19696
    
  20

Campbell Ritchie wrote:It’s still bad design to have that sort of name for your class.

Tell that to Sun / Oracle:
- AbstractMarshallerImpl
- AbstractUnmarshallerImpl
- AttributeListImpl
- Attributes2Impl
- AttributesImpl
- DatagramSocketImpl
- DatagramSocketImplFactory
- IIOMetadataFormatImpl
- ImageInputStreamImpl
- ImageOutputStreamImpl
- Locator2Impl
- LocatorImpl
- NotIdentifiableEventImpl
- org.omg.CORBA.portable.ObjectImpl
- org.omg.CORBA_2_3.portable.ObjectImpl
- ParseConversionEventImpl
- PrintConversionEventImpl
- RMIConnectionImpl
- RMIIIOPServerImpl
- RMIJRMPServerImpl
- RMIServerImpl
- RowSetMetaDataImpl
- SocketImpl
- SocketImplFactory
- SQLInputImpl
- SQLOutputImpl
- ValidationEventImpl
- ValidationEventLocatorImpl
- XMLFilterImpl
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38865
    
  23
So is an AbstractMarshallerImpl an implementation or abstract?
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19696
    
  20

Apparently both.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: facing error when working with Remote invocation method