We help IT Professionals succeed at work.

how to start out in Java

onyourmark
onyourmark asked
on
Hi. I am running Windows 7 32-bit, I want to try to run examples like the ones here: http://weka.wikispaces.com/Use+WEKA+in+your+Java+code

I studied a little Java a long time ago but really don't know how to begin.
Is there some simple way to try this out?
1. Do I need to install some special version of Java? How do I check if I have Java running and if it is the right version?
2. Do I have to do things like set a path and where should I most conveniently run these examples
3. I have Weka installed in C:\Program Files\Weka-3-7  and the weka.jar file is located there. Do I need to run these examples in that folder?
4. How do I run one of these examples? Can I just copy and paste the example and put it in a text editor and save it? and where should I save it and with what file extension. Is there some text editor I should use? I have notepad++.
5. How do I call the file created in #4?
6. When reading in a data file, do I have to put it somewhere special? For example, it says " DataSource source = new DataSource("/some/where/data.arff");".  Can I have the data.arff file anywhere as long as I reference its location properly in "/some/where/data.arff"?

Thanks for the help!!!
Comment
Watch Question

Awarded 2011
Awarded 2011
Commented:
Most probably you would not have installed JDK (development), you proabbly have installed only runtime JRE.
To check that open cmd and type
javac

If this command is not recognized you don't have JDK.

Then best of all to install JDK
Awarded 2011
Awarded 2011
Commented:


download JDK from this page
http://www.oracle.com/technetwork/java/javase/downloads/jdk-6u29-download-513648.html

select Windows X86 at the bottom of the page

Author

Commented:
I thought I have installed JDK but I ran javac and it said not recognized. I will install JDK
Awarded 2011
Awarded 2011
Commented:
I guess you are going to develop - compile new code, then you need JDK
Awarded 2011
Awarded 2011
Commented:
Then if you are going to do signiificant amount of devbelopedmnt - not just compile copule of times - tehn you may want to install IDE,
say Eclipse - if you just need to compile stiff severla times, then you can use any text editor, like TextPad, edit code and compile it
Awarded 2011
Awarded 2011
Commented:
In general to compile and exeute witout any third party libraries (withot WEka)
you jsut need to have youe JAVA_HOME/bin in the pATH
Most Java developers I know use Eclipse with the latest Java Runtime Environment:
http://eclipse.org/downloads/moreinfo/java.php
Awarded 2011
Awarded 2011

Commented:

Once you set JAVA_HOME/bin in the PATH

javac ClassName.java

will compile

java ClassName

will execute

Awarded 2011
Awarded 2011
Commented:
if you are on windows in the code you refer to files in this way:

File f = new  File("C:\\temp\\test\\myfile.txt");
you need to dupliacte backslashes
Awarded 2011
Awarded 2011

Commented:
maybe you want go through soem basic tutorial:
http://www.javabeginner.com/toc.htm
Awarded 2011
Awarded 2011

Commented:
In order to access your WEKA classes you need to place them on CLASSPATH
Awarded 2011
Awarded 2011

Commented:

read about classpath here for the beginning:

http://www.javabeginner.com/learn-java/getting-started-with-java

Author

Commented:
should I set the path like this

;JAVA_HOME/bin

Author

Commented:
I set the path like this
;JAVA_HOME/bin

then did cd to C:\Users\Bill\Desktop\hw
then ran javac hw.java but I got
'javac' is not recognized as an internal or external command,
operable program or batch file.
Awarded 2011
Awarded 2011

Commented:
no I meant JAVA_HOME is the actual foler wher you java is instaled
It is usullay

C:\Program Files\Java\...\bin

also if there are spaces ion between you need tohave it in quotes - acctding the genal rues of PATH on windows
don't read this literally -  some undestadning of windows is really necessary

Author

Commented:
Hi edited my Path variable as below and I was able to use the javac command!


C:\Python27\;C:\Python27\Scripts;C:\Program Files\Common Files\Microsoft Shared\Windows Live;C:\Program Files\ActiveState Perl Dev Kit 9.0.1\bin\;%GTK_BASEPATH%\bin;C:\Perl\site\bin;C:\Perl\bin;%SystemRoot%\system32;%SystemRoot%;%SystemRoot%\System32\Wbem;%SYSTEMROOT%\System32\WindowsPowerShell\v1.0\;C:\strawberry\c\bin;C:\strawberry\perl\site\bin;C:\strawberry\perl\bin;C:\Program Files\MySQL\MySQL Server 5.1\bin;C:\PROGRA~1\ADDINS~1\XLSTAT~1;C:\perl2exe;C:\Program Files\ActiveState Perl Dev Kit 9.0.1\bin;C:\Program Files\Windows Live\Shared;C:\Program Files\Microsoft SQL Server\100\Tools\Binn\;C:\Program Files\Microsoft SQL Server\100\DTS\Binn\;C:\Program Files\QuickTime\QTSystem\;"C:\Program Files\Java\jdk1.7.0_01\bin"
Awarded 2011
Awarded 2011

Commented:
good.

you are using jdk 7 - that's fine,
i'd rather start with java 6, but once you installed it - let it be

Author

Commented:
THANKS! Got it going!