hello world…

//code for hello.java

class hello

{

public static void main(String args[])

{

System.out.println(”hello world”);

}

}

This is a simple hello world program. The most imp thing is that for every .java file there has to be atleast one class and the a class with the exactly same name as the .java file name. Like in this example the file name is hello.java and the name of the class is also hello ( please remember that even the case of the filename and the class name should match as java is a case sensitive language).

Next is the main function which is also imp as C/C++ but unlike C/C++ its in the main class (hello in this case).since main has to be accesed from outside when the program has to be executed so it has to be public ( which has same meaning as in C/C++ classes) and static so that its initialised only once, and void if it returns nothing.

The control flow of the program starts from the main function and goes line by line in sequence. “System.out.println” is a predefined function for console output. System.out.print is also a similar predefined function the difference is that println returns a newline at the end of the thing to be printed and print just prints the thing to be printed.

example :-

System.out.println(”1″);System.out.println(”2″);

this will print :

1

2

where as –

System.out.print(”1″);System.out.print(”2″);

will print :         1 2

Posted by: rishabh_kalra | Comments (0)
First things first…

To start java programming you need to have a java compiler/interpreter.

In linux GCC has a java frount end for compiling java programs namely “gjc” which unfortnately doesnt work on my openSUSE 11.0 (maybe i m missing something) so u need to do 1 thing, open “yast” and open “software management” and then choose “patterns” as “filter” and then under the “development” heading check “java development” and a command will be added to your linux system –> “javac” <– which is used to compile a java program.

And if you dont want to do all this you can simply go to the sun’s site and download JDK (java development kit) which is available for downlaod for every platform.The only thing is that is you download it u will have to update it manually and if you adapt the above method for openSUSE u will get updates automatically through the update manager.

Now that you have obtained the basic requirements now commands “javac” and “java” will be added.

For linux find these commands in the terminal and for windows open the command prompt.

javac command is used to compile a java program that has .java extention and the code is converted to an intermediate java code which is coppied to a new file with same name and having .class extenstion now use java command to run the program but just feeding the filename (without any extension) to the java command, this command will automatically find the .class file in the current working directly and the program is executed.

example –>

$> javac Example.java

$> java Example

this is a test program.

$> _

Posted by: rishabh_kalra | Comment (1)
Getting your hands wet with JAVA programming

Well i m about to join na company that requires me to use java. So i thought y not help others with java…

i will be updating this blog with small n simple java tutorials. Firstly, i have a good hand on C/C++ n m learning java for the first time, so the aproach i have adopted is to learn java by comparing every thing with C/C++ so all those who know C/C++ will have advantage.

I dont know to what depth i will be going in this course of tutorials but lets start with from the basics n then see how well the boat can sail :)

So heres a welcome to all willing to use my tutorials to learn JAVA and do help me improve these tutorials with your valuable comments.

I will be programming on openSUSE 11.0 but as java is purely cross-platform it wont make a difference what ever platform you use…

Posted by: rishabh_kalra | Comments (0)
Running JAR files on linux

To execute .jar files on linux u need to have java runtime evniornment (JRE) and simply run the command ” java -jar path_to_jar_file”.

example to run your-freedom on linux go to terminal and type the command “java -jar /root/freedom.jar” (here the path of jar file can vary.

to add shortcut of your-freedom to k menu do the following steps:-

1. right click on the k menu icon.

2. click on “menu editor”.

3.select where you want the shortcut to be added and from the file menu select new item.

4.enter the name of the item. eg:- freedom.

5.on the right side fill in the command as mentioned above(command to run the .jar file).

6.select the icon and in the file menu click on save.

7.a new shortcut is added in the k menu at your desired position.

screen34.jpg screen35.jpg screen36.jpg

Posted by: rishabh_kalra | Comments (0)