-
completly new to Java , using a Mac and don't know how to make executables!
Hi! , Im trying to use Mac OS X panther's terminal to compile , but i don't know how to make an executable, all i know is that there is .jar , .java and .class.
Ive always programmed in c++, so i understand the code i see in .java files and supposedly you should be able to compile like this " java javafile.java" , "jar javafile.jar" but this dosen't work and a messege appears :
Exception in thread "main" java.lang.NoClassDefFoundError
and the problem is that the file does have a main function.
any info would be much appreciated and plz no Xcode suggestions
-
is thereno one that can help me?
-
Hi
Fist you complie using
>javac JavaFile.java make sure file name and class name should be same and casesensetive also
eg: class name is JavaFile you must same this file as JavaFile.java
then complie.
it will work and run using .>java JavaFile.java
it will show u output.
Thanks
sami
-
Zyracks,
let us know if you are having issues still. I didn't check this forum for a few days. Took a rest from telling people that java != javascript.
-
thx to samifarooq and mntall to care and answer, ive been reading a lot , java is realy similar to c++ , i have 2 Questions that would help alot if they are answered :
1- How do you input ?? i know that output(one way of) is System.out.println("" or x) but i can't find anywhere in my tutorial and in other ones ive check how to input.
2- can some one show me a decent try format (throwing normal variables(not weird ones) ) and the name that the catch parameter has to have. i can't find a decent example anywhere .
thanks for answering and hope you can helpme!
sincerly zyracks.
-
Yes, Java is very similar to C++, if you do OOP and not C in C++ .
Just remember - there are no exe's in Java (unless you get a third party tool to do it), no dual inheritance and no useful destructors.
To answer your questions:
1. System.in
2. You need to know what the method you are calling will throw. The method signature will tell you if there is a checked exception being thrown. Your best bet is to use a good IDE. Check out Eclipse or Netbeans for $0 ones.
-
a i still have some douts anout thos 2 questions.
1 is it just System.in ? cuse the output is System.out.PRINTLN() i do not no if i need something like the println after .in
2 if i want tu return an integer value how can i do it and what type of name should the catch parameter have (integer, int, int f, integer f, f,) i really do not know!!!!
-
1. System.in is the InputStream class.
http://java.sun.com/j2se/1.4.2/docs/...putStream.html
2. See the above link.
-
1. There are quite a few ways to read input. Some possiblilities:
//Read directly from System.in, like so:
byte buf[] = new byte[n];
System.in.read(buf); // and variants
//Wrap System.in in a BufferedReader:
BufferedReader br = new BufferedReader(System.in);
String line = br.readln();
//Or wrap it in some other type of Reader (see the Reader javadoc, and look for derived classes)
2. Here's a try/catch example:
System.out.println("Before the try block");
try{
System.out.println("Entered try block");
throw new Exception("Program Error");
} catch(Exception e) {
System.out.println("Caught an exception: " + e.getMessage());
} finally {
System.out.println("This block is always run, whether there was an exception or not. Do cleanup here!");
}
System.out.println("After the try block");
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
Forum Rules
|
Top DevX Stories
Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL
|
Bookmarks