publicclass nameOfTheJavaFile
{
publicstaticvoid main(String[] args)
{
data goes here //err ¿data?
//logic goes here
}
}
> everything so far is an object so far.
Nope. There are basic types.
Also blocks aren't objects either.
Can't remember if the classes are objects too.
i wasnt saying that every line of code was an object. data types are classes. classes are what objects come from. i was saying that the basis of java is objects.
There are 9 primitive types in Java:
boolean (bool)
byte (signed char)
char (unsigned short)
short (signed short)
int (signed int/signed long)
long (signed __int64)
float (float)
double (double) reference
The rest are classes. References are, in my opinion, a primitive, because references can only reference objects in Java and not primitives (which is why java has no support for reference-to-reference; references are themselves primitive). Think of Java references as C++ pointers that are always either valid or null, and you use . instead of -> to access fields and methods.
Java and C/C++ have strikingly similar syntax, mainly because Java was based on C. If you know C/C++, you shouldn't have a hard time adjusting to Java's syntax rules (they're nearly identical). It's the design patterns in Java that you will have a hard time adjusting to coming from C/C++.
Sometime soon you should see a post from rapidcoder explaining some other stuff and possibly disagreeing with/correcting me. He's the real Java pro around here, I just like Java as much as C++.
In Java, start class names with a capital letter: NameOfTheJavaFile, not nameOfTheJavaFile. This is the convention used everywhere, so if you do otherwise, your code would look strange.
and also what is a .jar file and what is a .class file
jar files are just archive files. I believe they're derived straight from .zip. Someone correct me if im wrong. Class files are the compiled source files (.java files).
publicclass Main{ // class name is usually the name of the file
publicstaticvoid main(String args[]){ //used to specify the executer class
System.out.println("Hello World"); //prints Hello World
}
}
Compilation:
javac Main.java
Execution:
java Main //Here Main is the class file obtained after compiling
IDE recommended : Eclipse or Netbeans
JAR( Java Archive) file is the final file obtained after the compilation. It can be compared with .exe file obtained after compiling a c++ program. It contains the class files and resources too(sometimes) . It also contains a manifest file used to specify the name of the main class which is responsible for running the project.
JAR files can be easily formed using the jar command with cvf flags on command prompt if you have installed the jdk and set the environment variables properly.
And why are you not able to get a graphics lib in C or C++ ?
I want to learn graphics in C++ but I haven't started yet . Should I concentrate on Java only because I already know Java?