This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes simple questions on core java Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "simple questions on core java" Watch "simple questions on core java" New topic
Author

simple questions on core java

Vidya Bhargavi
Greenhorn

Joined: Jul 09, 2009
Posts: 26
hi,


I have 2 questions.Please tell me the answers for those.

1)for eg:

public abstract class vidya
{
void coding();
}

The above code is valid if we use or do not use the keyword abstract in the class....Then can you please tell me why " abstract" is used there.

2)Please tell me where do we use throw,throws with examples in exception handling?

Steve Luke
Bartender

Joined: Jan 28, 2003
Posts: 4165
    
  21

Vidya Bhargavi wrote:hi,


I have 2 questions.Please tell me the answers for those.

1)for eg:

public abstract class vidya
{
void coding();
}

The above code is valid if we use or do not use the keyword abstract in the class....

Not in my compiler it's not. The method must be labeled abstract in order for the code to compile. Now, if this were an interface rather than an abstract class it would be different.

Then can you please tell me why " abstract" is used there.

The abstract keyword tells the compiler that this method does not have an implementation - it is up to concrete subclasses to provide the implementation. Without the abstract keyword then you must provide implementation.


2)Please tell me where do we use throw,throws with examples in exception handling?

Read the Exception Handling part of the Java Tutorial. It explains catching and throwing exceptions and when to use which.

Steve
Sumit Patil
Ranch Hand

Joined: May 25, 2009
Posts: 296

Here is a Java tutorial for you...

Go through this carefully.

Java Tutorial


Thanks & Regards, Sumeet
SCJP 1.4, SCWCD 5, LinkedIn Profile
Vidya Bhargavi
Greenhorn

Joined: Jul 09, 2009
Posts: 26
hi,


For the 1st question please check in kathy sierra SCJP book.It is given like,the code which i have specified is valid.


For the 2nd Question,Please suggest me other simple links other than Sun so that i may find it simple.
Steve Luke
Bartender

Joined: Jan 28, 2003
Posts: 4165
    
  21

Vidya Bhargavi wrote:hi,


For the 1st question please check in kathy sierra SCJP book.It is given like,the code which i have specified is valid.


I don't have the book. I do have a compiler. And it is possible that a book has a mistake in it, even very good ones. My compiler tells me the code is not valid, and I believe it because it behaves like the JLS says it should. When you get into these types of questions the best thing to do is to take your code, copy it into a .java file and compile it to see what you get.


For the 2nd Question,Please suggest me other simple links other than Sun so that i may find it simple.


1) Why is Sun not good enough? Is there a problem with the links provided?
2) You could try some research on your own - like, perhaps using Google to search on some key words like Java throws exception tutorial. Or something like that.
Sumit Patil
Ranch Hand

Joined: May 25, 2009
Posts: 296

Vidya Bhargavi wrote:hi,


For the 1st question please check in kathy sierra SCJP book.It is given like,the code which i have specified is valid.


It is designed this way
1) Any class having a abstract method should be defined abstract.
2) It is not required for an abstract class to have any abstract method, i.e it is perfectly valid to have all the implemented methods in an abstract class.


For the 2nd Question,Please suggest me other simple links other than Sun so that i may find it simple.


Just start learning java using the Head First Java, book by kathy seirra, it is good place to start.

Any queries are welcomed.
Ananth Chellathurai
Ranch Hand

Joined: Nov 21, 2007
Posts: 349

A 5 minutes google didn't give me a better tutorial than what sun gives. Does any one has a better url?

And I am puzzled why you don't want sun's documents!!!


Ananth Chellathurai [Walk on software]
Max Rahder
Ranch Hand

Joined: Nov 06, 2000
Posts: 177
Vidya Bhargavi wrote:
The above code is valid if we use or do not use the keyword abstract in the class....Then can you please tell me why " abstract" is used there.


One can think of abstract as meaning "not implemented" for a method, and "not fully implemented" in the case of a class. Unimplemented methods -- methods without a body -- must be declared abstract. A class must be declared abstract if it has unimplemented methods, either because that class itself defines abstract methods, or because the superclass is abstract (and therefore, has unimplemented methods).

In terms of inheritance, one way to think of "final", default, and "abstract" is:
final means "you can not override it"
default inheritance means "you can override it if you need", and
abstract means "you must override it in some subclass"
Muhammad Khojaye
Ranch Hand

Joined: Apr 12, 2009
Posts: 449

Vidya Bhargavi wrote:For the 2nd Question,Please suggest me other simple links other than Sun so that i may find it simple

Exceptions in Java

When and How to Use Exceptions

Hope it helps.


http://muhammadkhojaye.blogspot.com/
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 37945
    
  22
"Simple questions . . . " is hardly a good thread title.
Vidya Bhargavi
Greenhorn

Joined: Jul 09, 2009
Posts: 26
hi,



Thanks a lot for all of your replies.


 
Consider Paul's rocket mass heater.
 
subject: simple questions on core java
 
Similar Threads
Why do we have concrete methods in abstract class ?
deploying and running web application in the home pc
about abstract class
abstract inner class??
abstract class