This week's giveaway is in the Spring forum.
We're giving away four copies of Learn Spring Security (video course) and have Eugen Paraschiv on-line!
See this thread for details.
Win a copy of Learn Spring Security (video course) this week in the Spring forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

facing error when working with Remote invocation method

 
Laxmi Bhavisetti
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 692
Eclipse IDE Java Linux
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ....
 
John Jai
Rancher
Posts: 1776
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 20492
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It's not an error, it's a warning. And you can prevent it by reading this.
 
Harsha Smith
Ranch Hand
Posts: 287
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Right on top of the declaration use

@SuppressWarnings("unchecked")


you may consider using ConcurrentHashMap instead of Hashtable
 
Campbell Ritchie
Sheriff
Posts: 48363
56
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think Rob’s suggestion to learn the generics properly is far better than suppressing the warnings.
 
Laxmi Bhavisetti
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you guys, thannks for your help. Im totally new to java. And now im workign with remote method invocation.
 
Winston Gutkowski
Bartender
Pie
Posts: 10075
55
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Campbell Ritchie
Sheriff
Posts: 48363
56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Winston Gutkowski wrote: . . . Blimey. . . .
Careful. If you go round saying things like that, people will think you’re a Cockney
 
Rob Spoor
Sheriff
Pie
Posts: 20492
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 10075
55
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 48363
56
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3742
16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Campbell Ritchie
Sheriff
Posts: 48363
56
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 48363
56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 10075
55
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4678
7
Linux Mac OS X VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 48363
56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It’s still bad design to have that sort of name for your class.
 
Campbell Ritchie
Sheriff
Posts: 48363
56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 20492
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 48363
56
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So is an AbstractMarshallerImpl an implementation or abstract?
 
Rob Spoor
Sheriff
Pie
Posts: 20492
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Apparently both.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic