• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Tim Cooke
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Knute Snortum
  • paul wheaton
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Ron McLeod
  • Piet Souris
  • Ganesh Patekar
Bartenders:
  • Tim Holloway
  • Carey Brown
  • salvin francis

simple questions on core java

 
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?

 
Bartender
Posts: 4179
22
IntelliJ IDE Python Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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.
 
Ranch Hand
Posts: 296
Eclipse IDE Firefox Browser Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here is a Java tutorial for you...

Go through this carefully.

Java Tutorial
 
Vidya Bhargavi
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4179
22
IntelliJ IDE Python Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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
Posts: 296
Eclipse IDE Firefox Browser Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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.
 
Ranch Hand
Posts: 349
Hibernate Eclipse IDE Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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!!!
 
Ranch Hand
Posts: 177
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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"
 
Ranch Hand
Posts: 449
Scala IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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.
 
Marshal
Posts: 65425
248
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"Simple questions . . . " is hardly a good thread title.
 
Vidya Bhargavi
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi,



Thanks a lot for all of your replies.


 
We find this kind of rampant individuality very disturbing. But not this tiny ad:
Enterprise-grade Excel API for Java
https://products.aspose.com/cells/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!