Like this,you have many applications. The others include the mobile application in mobility using game builder and many more applications in ruby,UML etc.
Saturday, April 12, 2008
Have Fun
Like this,you have many applications. The others include the mobile application in mobility using game builder and many more applications in ruby,UML etc.
Tuesday, April 8, 2008
Keyboard Shortcuts
I have been harping on netbeans making life simple in a few of my previous posts. And I have been giving a lot of keyboard shortcuts in my previous posts which were actually pretty obvious. You can realise this if you had just opened netbeans once. But today,I came across a feature that ACTUALLY gave me a wide grin. Forget API,web services, GUI and all that! One can set their own keyboard shortcuts! I don't know about you but for someone like me who is pathetic in remembering shortcuts,this was such a pleasant idea. It was like finding an old friend in an isolated island! :)
To do this,click on tools->options and then select keymap. Then,you will get a list of actions for which you can add shortcuts. You can choose one action. For example,I choose to add a shortcut for obtaining the contents of the help menu. Observe the screenshot below.
Wednesday, February 20, 2008
Need for Netbeans
Why is netbeans necessary??
"Necessity is the mother of all inventions", goes the old saying. Well my dear friend,its the same case here also. Although Java has become inseparably linked with the Internet, it is important to realise that java is first and foremost a programming language. Let us just take a ride down the history lane and look at the development of programming languages. We all know that it was C which first got the status of a "programmer's language". C was developed from 'B' and this fact is well known. However, C++ was also in the coming and it came! Why did this happen? Did the arrival of C++ prove C to be an incompetent language?
NO! As the complexity and demand grew, so did all the computer languages. So after C and C++, the stage was set for Java!! After installing jdk and jre, one can execute java applications at the command prompt. In this feature, it is important for the programmer to remember all commands and recollect them at the appropriate time. Isn't this all a little tedious? Don't we like everything at the click of a button? We always aim for more compact and steady platforms! Many paradigms of view.. god o god!
And all this brings us to confluence of IDE and java applications onto a single platform.. NETBEANS IDE!!! :D I know I seemed like it was the most obvious thing.. ha ha.. Well well,I just saved you a lot of work which would have taken you a lot of time to figure out.. All my blog readers.. consider yourselves blessed!! :D
Experiment Time
Netbeans is NOT the place where one can gain expertise in java! So if you are a novice, I say-"stick to routines". Just to make my point felt, I want to cite an example. Consider this program.
class Fun
{
public static void main(String[] args)
{
int count,i=0;
String words;
count=args.length;
System.out.println("Number of arguments= " +count);
while (i < count)
{
words=args[i];
i++;
System.out.println(i+ ":" + "Java is " +words+ "!");
}
}
}
Execute this program in jdk and at the command for compilation,give the following statement(let your filename be Fun!)
java Fun Robust Simple Secure Portable Multithread
The output of your program would be as follows:
Number of arguments=5
1: Java is Robust!
2: Java is Simple!
3: Java is Secure!
4: Java is Portable!
5: Java is Multithread!
Isn't this such a cool output!!! Now, you know the use of String[] args!!! If you were a starter, I sure can swear that you wouldn't have figured this out.. As far as my knowledge with netbeans goes, I don't think there is an option where I can provide arguments at run-time.. (If there is that option, I am yet to discover it then!!)
Observe
One of the main advantages of using IDE is that it makes life easy for a programmer.
For example,if I were to type a program which has a command to print a statement,one can observe that a window pops up as soon as "System." is typed. This window is as shown below.
This happens because the System class contains several class fields and methods and they cannot be instantiated. The facilities provided by the System class include standard input, standard output, and error output streams. By convention, this output stream is used to display information or messages that are intented to be attended by the user. "println" which is normally added at the terminal end belongs to the PrintStream. This class prints Java primitive values and object to a stream as text. Errors if present can be detected by calling the checkError() method. Additionally, this stream can be designated as "autoflush" when created so that any writes are automatically flushed to the underlying output sink when the current line is terminated. "println" just terminates the current line by inserting a line separator string(which does not mean \n).
Taking the next step
Netbeans is one such platform which also aids software development. In netbeans,it is important to realise that the platform recognizes and evaluates strictly in terms of a 'project'.
Time to learn:
Of the Java SE applications of netbeans,there is an application called 'Java project with existing sources wizard'. Click on File->New project. Click on java and choose the 'Java project with existing sources wizard'. Then,choose a project name and a project folder and click next. When adding the source package folder,add the folder which contains your java programs. [In a windows system,by default,all these java programs are present in C:\Program files\Java\jdk(version)\bin]Finally,click finish and your project is created.
NOTE: If you include this folder,then the whole folder becomes a project and your individual programs gain the status of a file.
If you have followed all the steps I have mentioned above,then its first part accomplished
Now,you can run any file present in your project. To open your file,click on your project folder which will open all the files tored in it. In my example,I am going to run a program which is stored as "Accurate.java" in my systen. To illustrate this,I am now going to run a file in my project. The screenshot is as shown below.
The program I have shown is a basic multithread program. Its code is
class NewThread implements Runnable
{
String name;
Thread t;
NewThread(String threadname)
{
name=threadname;
t=new Thread(this,name);
System.out.println("New thread: " + t);
t.start();
}
public void run()
{
try
{
for(int i=15;i>0;i--)
{
System.out.println(name + ":" +i);
Thread.sleep(200);
}
} catch (InterruptedException e)
{
System.out.println(name + "interrupted");
}
System.out.println(name + "exiting");
}
}
class Accurate
{
public static void main(String args[])
{
NewThread ob1= new NewThread("One");
NewThread ob2= new NewThread("Two");
try{
Thread.sleep(1000);
ob1.t.suspend();
System.out.println("Suspending thread one");
Thread.sleep(1000);
ob1.t.resume();
System.out.println("Resuming thread one");
Thread.sleep(1000);
ob2.t.suspend();
System.out.println("Suspending thread two");
Thread.sleep(1000);
ob2.t.resume();
System.out.println("Resuming thread one");
} catch (InterruptedException e)
{
System.out.println("Main thread interrupted");
}
System.out.println("Main thread exiting");
}
}
To run this file,we click on Build->"Complile Accurate.java" (F9). After succesful compilation,we can run the program by clicking Run->Run file->Run "Accurate.java" (or Shift+F6). After this,we can observe the output which is
New thread: Thread[One,5,main]
New thread: Thread[Two,5,main]
One:15
Two:15
One:14
Two:14
One:13
Two:13
One:12
Two:12
One:11
Two:11
Suspending thread one
Two:10
Two:9
Two:8
Two:7
Two:6
Resuming thread one
One:10
Two:5
One:9
Two:4
One:8
Two:3
One:7
Two:2
One:6
Two:1
Suspending thread two
One:5
One:4
One:3
One:2
One:1
Resuming thread one
Twoexiting
Main thread exiting
Oneexiting
Formatting
I suggest you to follow the steps carefully to format your code.
1) Select your entire program with the right click of a mouse ( the picture will be as shown above).
2) Right-click and click on the option which reads "format". The shortcut is Alt+Shift+F.
Simple,isn't it?? Just by following these two simple steps,one can arrive at a correct formatted code!
Tuesday, February 19, 2008
Web Services
Right-click on the tab at facebook and click on "view API documentation". Why am I choosing facebook to explain my point? Well,today is the age of social networking and the chances that a person knows facebook is higher than the person knowing anything else!! So, your facebook application also makes method calls over the internet by sending HTTP requests to the facebook API server. This part of the option of netbeans is best learnt when the YOU choose to explore it! Like the tag line of netbeans 6.1 says..."the only IDE you need!!" Its open source! So guys,get started if you still haven't!!
Saturday, February 9, 2008
GUI!
In netbeans,GUI design takes place in the IDE workspace. The tools present in IDE's java GUI tools include
2) Inspector Window
3) Palette Window
4) Properties Window
5) Connection Wizard
6) Palette Manager
Instead of getting down to theoritical aspects of the GUI, I prefer to explain the method of implemeting this concept in netbeans by creating a project. Our project is to create a calculator.
i) Click on File-> New Project-> Java(in categories)-> Java Application(in projects). After doing this, click next.
ii) Give project name as Calculate and while doing so,ensure the following important points.
(a) Select "set as main project" .
(b) Deselect "create main class" if it is selected.
iii) Click Finish.
iv) In projects window, right click Calculate and select new->Jframe form.
Give
(b) package : my.calculateThen click finish.
v) Next,we use the Palette to create to create the layout of our calculator. To use the options present in the palette,select a JPanel from the Palette and drop it onto the JFrame. In our design of the calculator, we use four jLabels, four jTextFields and eight jButtons. After dragging and dropping all of these on to the jFrame,our screen should look similar to the one shown below. If you do not clearly understand how to use GUI builder,the following webpage might come in handy. Do check this out.
Here,I have just enlarged the photo to aid better understanding.
vi) Now,we rename every display text component added on to the jFrame window. To do this, double click on every component and rename. The screenshot after doing so will be as shown below.
Just to make the photo more clearer,I have added an enlarged version of the photo. Hope it helps..!
Here it is important to observe that basic arithmetic operations can be performed on two operands wgich is indicated by 'First Number' and 'Second Number'. 'Unary field' is used when an operation is to be performed on a single number.
vii) After renaming is done,we need to add functionality to every component of the calculator. Let us start with the EXIT button. To add functionality,right click on the exit button and choose action and select action performed. The IDE will then open up the Source Code window. Now, scroll to where you implement the action you want the button to do when the button is pressed. Your source code window contains the following statement.
private void jButton3ActionPerformed(java.awt.event.ActionEvent evt)
{ //TODO: Add your handling code here :
}
We add one line to exit and our final code looks as shown below. Similarly,one should follow the same procedure for adding functionality to different buttons and the codes for all buttons are as shown below.
I) EXIT Button
private void jButton3ActionPerformed(java.awt.event.ActionEvent evt)II) SQUARE button:
{
System. exit(0);
}
private void jButton5ActionPerformed(java.awt.event.ActionEvent evt)
{
float num,result;
num=Float.parseFloat(jTextField3.getText());
result=num*num;
jTextField4.setText(String.valueOf(result));
}
III) MULTIPLY Button:
private void jButton3ActionPerformed(java.awt.event.ActionEvent evt)
{
float x1,x2,result;
x1=Float.parseFloat(jTextField1.getText());
x2=Float.parseFloat(jTextField2.getText());
result = x1*x2;
jTextField4.setText(String.valueOf(result));
}
IV) ADD Button:
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt)
{
float x1,x2,result;
x1=Float.parseFloat(jTextField1.getText());
x2=Float.parseFloat(jTextField2.getText());
result = x1+x2;
jTextField4.setText(String.valueOf(result));
}
V) DIVIDE Button:
private void jButton4ActionPerformed(java.awt.event.ActionEvent evt)
{
float x1,x2,result;
x1=Float.parseFloat(jTextField1.getText());
x2=Float.parseFloat(jTextField2.getText());
result = x1/x2;
jTextField4.setText(String.valueOf(result));
}
VI) RECIPROCAL Button:
private void jButton6ActionPerformed(java.awt.event.ActionEvent evt)
{
float num,result;
num=Float.parseFloat(jTextField3.getText());
result = 1/num;
jTextField4.setText(String.valueOf(result));
}
VII) SUBTRACT Button:
private void jButton2ActionPerformed(java.awt.event.ActionEvent evt)
{
float x1,x2,result;
x1=Float.parseFloat(jTextField1.getText());
x2=Float.parseFloat(jTextField2.getText());
result = (x1-x2);
jTextField4.setText(String.valueOf(result));
}
VIII) CLEAR Button:
private void jButton7ActionPerformed(java.awt.event.ActionEvent evt)
{
jTextField1.setText("");
jTextField2.setText("");
jTextField3.setText("");
jTextField4.setText(" ");
}
Its mission accomplished! Our calculator looks as shown below.
To compile build/compile the project, click on build->build main project.Then to run the main project, click on run-> run main project. When you do this, you can make calculations in this calculator! :)
Friday, February 8, 2008
Installation
I consider that by now, all my blog readers would have taken the first step atleast. The installation procedure is quite simple and it moves smoothly. And hey,you must be bored waiting for the 183MB file to download!! :) Ah, are you telling me the links for online jokes to keep you entertained now?? :D Help yourself with the www guys! (waiting waitng waiting....)
Phew! At last,eh?? I know! So, your installation is complete. If you are facing problems, I suggest you have a reading of this page:
http://www.netbeans.org/community/releases/61/install.html
I hope its mission accomplished now!
Follow Traditions
People people people! No matter how adept
you are at IDE or java,traditions come first!
Meaning we always start off with our initial
little simple java program before taking it
further.. So.. here goes my mundane routine of explaining to you as to how one can carry off their first program on netbeans.
SMILE PLEASE!
In netbeans click on file->new project. After doing this,you get a window as shown below.
Click on Java application tab and click next. You then see the java application box where you enter your project name as HelloWorld(as shown ). Its very important to observe here that the main class is named automatically..!!
If you have done this,then you are on the right track. After this,writing your one line is a piece of cake because everything else in the window is ready for you! IDE's.. bliss!!!
You get your window as shown in the right. Give your basic print statement as
System.out.println("Hello World");
After this is done,you have to build your program by pressing F11 or go to build->build main project. If you are not getting your output screen,go to window->output->output(OR ctrl+F4) Then,run your program by pressing F6 or run->run main project... :)
Congratulations! You wrote the simplest program on netbeans!!
Monday, February 4, 2008
Welcome!
This is it! My first real attempt at blogging! And I chose NETBEANS to start with. Its really exciting for me to write this blog from a perspective of exploring netbeans i.e, as someone who is trying to get a strong grip of it. So, this is where you start your journey.. your all important initial view!!