Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   Java (http://www.velocityreviews.com/forums/f30-java.html)
-   -   Need help,homework (http://www.velocityreviews.com/forums/t955338-need-help-homework.html)

theunknowable@lavabit.com 12-11-2012 12:21 AM

Need help,homework
 
Nooblet here, I need to write this application, I got as far as making 6
empty classes and originally needed to use swing, though since I need to
learn swing I may just make it a console application and get less points
for it. I need to be able of writing to disk the data (utilizing user
input), deleting it when I want too and show I understand how classes
work. While I understand extends, I don't quite understand what implement
does.

Extends allows you to use the methods and variables of the class you
extended (inheritance). Implement seems similar?

Anyways, since I only have 1 day to do this and I've been trying to do
this for weeks, what are the classes available that will allow me to:

1.) Write a plain text file to disk?
2.) read the file?
3.) delete the file?
4.) check for the existence of the file?
5.) search for the file?
6.) compare files?

Where can I learn more about these specific classes? Any example code that
is small and simple to read? :(

Lew 12-11-2012 01:05 AM

Re: Need help,homework
 
theunk...@lavabit.com wrote:
> Nooblet here, I need to write this application, I got as far as making 6
> empty classes and originally needed to use swing, though since I need to
> learn swing I may just make it a console application and get less points
> for it. I need to be able of writing to disk the data (utilizing user
> input), deleting it when I want too and show I understand how classes
> work. While I understand extends, I don't quite understand what implement
> does.
>
> Extends allows you to use the methods and variables of the class you
> extended (inheritance). Implement seems similar?


'extends' is the keyword to inherit from a class, including implementation of methods.

'implements' is the keyword for a _class_ to inherit from an interface, including only
method signatures from the interface and leaving details of implementation entirely
up to the implementing class.

An interface can use 'extends' to inherit from another interface. Because an interface
contains no implementation, it cannot 'implements' an interface.

> Anyways, since I only have 1 day to do this and I've been trying to do


You're going to have a hard time. Usenet isn't necessarily a one-day turnaround, and
learning Java can take a few days.

> this for weeks, what are the classes available that will allow me to:


Tutorials and Javadocs.

Tutorials:
http://docs.oracle.com/javase/tutorial/

Javadocs:
http://docs.oracle.com/javase/7/docs/api/

> 1.) Write a plain text file to disk?

http://docs.oracle.com/javase/tutori.../io/index.html
http://docs.oracle.com/javase/7/docs...ileWriter.html

> 2.) read the file?

http://docs.oracle.com/javase/7/docs...ileReader.html

> 3.) delete the file?

http://docs.oracle.com/javase/7/docs...a/io/File.html

> 4.) check for the existence of the file?

http://docs.oracle.com/javase/7/docs...a/io/File.html

> 5.) search for the file?

http://docs.oracle.com/javase/7/docs...a/io/File.html
plus
http://docs.oracle.com/javase/7/docs...ileFilter.html
plus
http://docs.oracle.com/javase/7/docs...ameFilter.html
plus glue code.

> 6.) compare files?

Read the files and compare contents. You'll need to be more specific about what you
mean by "compare".

> Where can I learn more about these specific classes? Any example code that
> is small and simple to read? :(


http://lmgtfy.com/?q=Java+simple+file+I%2FO

--
Lew

Roedy Green 12-12-2012 02:37 AM

Re: Need help,homework
 
On Tue, 11 Dec 2012 00:21:22 +0000 (UTC), theunknowable@lavabit.com
wrote, quoted or indirectly quoted someone who said :

>While I understand extends, I don't quite understand what implement
>does.


see http://mindprod.com/jgloss/implements.html
http://mindprod.com/jgloss/class.html
http://mindprod.com/jgloss/interface.html
--
Roedy Green Canadian Mind Products http://mindprod.com
Students who hire or con others to do their homework are as foolish
as couch potatoes who hire others to go to the gym for them.

Lew 12-12-2012 03:30 AM

Re: Need help,homework
 
Roedy Green wrote:
> theunknowable... wrote, quoted or indirectly quoted someone who said :
>
>> While I understand extends, I don't quite understand what implement
>> does.

>
> see http://mindprod.com/jgloss/implements.html
> http://mindprod.com/jgloss/class.html
> http://mindprod.com/jgloss/interface.html


OP, you'd be better off with the Oracle documentation and Google, whereby you
can get more accurate and insightful information.

Roedy is fond of driving traffic to his site from here. You might find something
somewhat useful there, but you're far more likely to benefit from authoritative sources.

--
Lew

Arne Vajhøj 12-13-2012 01:42 AM

Re: Need help,homework
 
On 12/11/2012 9:37 PM, Roedy Green wrote:
> On Tue, 11 Dec 2012 00:21:22 +0000 (UTC), theunknowable@lavabit.com
> wrote, quoted or indirectly quoted someone who said :
>> While I understand extends, I don't quite understand what implement
>> does.

>
> see


I am not sure that is good advice.

> http://mindprod.com/jgloss/implements.html


#implements is a keyword used on class or interface statements.

class and interface are not statements.

And an interface can not implements by definition.

> http://mindprod.com/jgloss/class.html


#Let’s say you had a TV class to deal with television sales. There are
#two kinds of variables:
#
# static variables that track facts about all televisions in
#general, e.g. total sold or a list of manufacturers.

That sounds like an awful design to me.

> http://mindprod.com/jgloss/interface.html


#The throws clauses about Exceptions in the interface’s methods must
#exactly match the throws clauses of the implementing methods.

No.

The implementing method can not throws an exception not in
the interface, but it does not need to throws all exceptions
in the interface.

Arne



Robert Klemme 12-14-2012 07:03 AM

Re: Need help,homework
 
On 12/13/2012 02:42 AM, Arne Vajhøj wrote:
> On 12/11/2012 9:37 PM, Roedy Green wrote:


>> http://mindprod.com/jgloss/interface.html

>
> #The throws clauses about Exceptions in the interface’s methods must
> #exactly match the throws clauses of the implementing methods.
>
> No.
>
> The implementing method can not throws an exception not in
> the interface, but it does not need to throws all exceptions
> in the interface.


<nitpick>The implementing class can choose to declare a more restrictive
throws clause, which means, sub classes of declared exceptions in the
interface as well as a shorter throws clause. And it is allowed to
throw all exceptions which are mentioned in the throws clause or sub
classes of them.</nitpick>

Kind regards

robert


Arne Vajhøj 12-15-2012 01:59 AM

Re: Need help,homework
 
On 12/14/2012 2:03 AM, Robert Klemme wrote:
> On 12/13/2012 02:42 AM, Arne Vajhøj wrote:
>> On 12/11/2012 9:37 PM, Roedy Green wrote:

>
>>> http://mindprod.com/jgloss/interface.html

>>
>> #The throws clauses about Exceptions in the interface’s methods must
>> #exactly match the throws clauses of the implementing methods.
>>
>> No.
>>
>> The implementing method can not throws an exception not in
>> the interface, but it does not need to throws all exceptions
>> in the interface.

>
> <nitpick>The implementing class can choose to declare a more restrictive
> throws clause, which means, sub classes of declared exceptions in the
> interface as well as a shorter throws clause. And it is allowed to
> throw all exceptions which are mentioned in the throws clause or sub
> classes of them.</nitpick>


Good point.

"not in the interface" must be "not instance of one in the
interface" or "not assignable to one in the interface".

Arne





All times are GMT. The time now is 07:46 AM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.