Monday, 14 July 2014

Hi Guys!!
    In this post you will learn how to control a sprite's movement in C# with Arrow Keys
          Below  is the  Code for arrow controlled object motion. Its easier than it sounds check it out guys.

1:  using System;  
2:  using System.Collections.Generic;  
3:  using System.ComponentModel;  
4:  using System.Data;  
5:  using System.Drawing;  
6:  using System.Linq;  
7:  using System.Text;  
8:  using System.Windows.Forms;  
9:  namespace KeyControlledMotion  
10:  {  
11:    public partial class Form1 : Form  
12:    {  
13:      static int xpos , ypos , circleWidth , circleHeight;  
14:      static int panelWidth,panelHeight;  
15:      static SolidBrush bgBrush , circleBrush;  
16:      static Rectangle backgroundRect;  
17:      public Form1()  
18:      {  
19:        xpos = ypos = 0;  
20:        circleWidth = circleHeight = 50;  
21:        panelWidth = 315;  
22:        panelHeight = 295;  
23:        backgroundRect = new Rectangle(0, 0, panelWidth, panelHeight);  
24:        circleBrush = new SolidBrush(Color.SteelBlue);  
25:        bgBrush = new SolidBrush(Color.Black);  
26:        InitializeComponent();  
27:      }  
28:      private void Form1_Load(object sender, EventArgs e){ }  
29:      private void Form1_MouseHover(object sender, EventArgs e){}  
30:      private void panel1_MouseHover(object sender, EventArgs e)  
31:      {  
32:        Cursor.Hide();  
33:      }  
34:      private void panel1_Paint(object sender, PaintEventArgs e)  
35:      {  
36:        Graphics g = panel1.CreateGraphics();  
37:        g.FillRectangle(bgBrush, backgroundRect);  
38:        g.FillEllipse(circleBrush,xpos,ypos,circleWidth,circleHeight);  
39:      }  
40:      void reDrawBG(Graphics gr) {  
41:        gr.FillRectangle(bgBrush,backgroundRect);  
42:      }  
43:      public void move(SolidBrush sb,int x,int y) {  
44:        Graphics gr = panel1.CreateGraphics();  
45:        reDrawBG(gr);  
46:        gr.FillEllipse(sb,x,y,50,50);  
47:      }  
48:      private void Form1_KeyDown(object sender, KeyEventArgs e)  
49:      {  
50:        if (e.KeyCode == Keys.Left)  
51:        {  
52:          if(xpos-2 >= 0)  
53:          xpos -= 2;  
54:          move(circleBrush,xpos,ypos);  
55:        }  
56:        else if (e.KeyCode == Keys.Right)  
57:        {  
58:          if(xpos < panel1.Width-circleWidth)  
59:          xpos += 2;  
60:          move(circleBrush, xpos, ypos);  
61:        }  
62:        else if (e.KeyCode == Keys.Up)  
63:        {  
64:          if(ypos >= 0)  
65:          ypos -= 2;  
66:          move(circleBrush, xpos, ypos);  
67:        }  
68:        else if (e.KeyCode == Keys.Down)  
69:        {  
70:          if(ypos < panel1.Height-circleHeight)  
71:          ypos += 2;  
72:          move(circleBrush, xpos, ypos);  
73:        } 
74:      }//keyDown event  
75:    }//class  
76:  }//namespace

 Explanation : 

                      In keyDown Event i have used if else  conditions to check which key is pressed down after  certain statements are executed  if a condition is true. For Example if the down key is pressed down the circle will move 2 pixels down and same  is the case with left , right and up keys.

                      The method reDrawBG is just used to redraw the background  after every keyDown(left,down,right,up).

                      The method move is used  to move or update the circle's position after each keyDown.
All the global variables are initialized  inside the constructor.


Output:



Download the Complete Project Arrow controlled object

Saturday, 21 June 2014

Things You will Learn:

  • Make tictactoe in Java/C#
  • Deciding a winner in TicTacToe
  • TicTacToe pseudo code

Pseudo Code :

  1. Player selects a box i.e '1' 
  2. If that box is already filled with any player symbol gives an error and repeats the current iteration
  3. If its not filled already,that box is filled with the current player's symbol
  4. when the the number of filled boxes is greater than or equal to 5 the decidewinner method is called to check if we have a winner right now continues until all the boxes are filled.

Here is the code :

1:  import java.util.Scanner;  
2:  class TicTacToe{  
3:         
4:       Scanner in = new Scanner(System.in);  
5:         
6:       int choosedbox , iteration ;  
7:         
8:       char player1Symbol = 'x' , player2Symbol = '0' , currentSymbol = 'x' , box[] = {'0','1','2','3','4','5','6','7','8','9'};  
9:      
10:       String p1 = "Player1", p2 = "Player2" , currentPlayer = p1;  
11:          
12:         //*******draws a tic tac toe board on the screen*******  
13:  public void Board(){  
14:                        
15:            System.out.println( " " + box[1] + " | " + box[2] + " | " + box[3] );  
16:            System.out.println( " ___|___|____");    
17:            System.out.println( "  |  |");  
18:            System.out.println( " " + box[4] + " | " + box[5] + " | " + box[6] );   
19:            System.out.println( "____|___|____");  
20:            System.out.println( "  |  |");    
21:            System.out.println( " " + box[7]  + " | " + box[8] + " | " + box[9]);  
22:            System.out.println();  
23:            System.out.println();            
24:         
25:                 }// *********drawying gameboard finished*********  
26:                   
27:            // ********Starts playing********  
28:  public void startPlay() {  
29:              
30:            Board();   // calling method "Board"  
31:               
32:            System.out.println( " The Symbol for player1 is 'x' and for player2 is '0 " ) ;  
33:              
34:            out:                      // titled or named for loop with name out  
35:            for( iteration = 0; iteration < 9; iteration++ )  
36:            {                              //body of the loop starts  
37:            if( iteration % 2 == 0 ){  
38:                 currentSymbol = player1Symbol;  
39:              currentPlayer = p1;         
40:               }  
41:            else  
42:              {    
43:                 currentSymbol = player2Symbol;  
44:                 currentPlayer = p2;    
45:                 }  
46:                   
47:            System.out.println( currentPlayer + " turn please select a box= " );       
48:              
49:            choosedbox = in.nextInt(); //asks the user to enter the box he want to choose  
50:               
51:            if( box[choosedbox] == player1Symbol || box[choosedbox] == player2Symbol )  
52:               {    
53:                  System.out.println( " ERROR,This box is already filled select another box " );  
54:              iteration = iteration - 1 ; //Repeat the current iteration if box selected by the user is already filled   
55:              continue out ;    
56:             }  //continues the loop and do not move to else if statement  
57:              
58:            box[choosedbox] = currentSymbol; // filling the selected box with the symbol  
59:              
60:            Board();  
61:              
62:            if(iteration >= 4) //decideWinner(); is only called when five boxes of the gameboard are filled by symbols of the players  
63:                 decideWinner();      
64:                        
65:            }//end of for loop
66:                      
67:            }//end of method  
68:    
69:  public void decideWinner(){  
70:                        
71:            if( box[1] == box[2] && box[2] == box[3] && box[3] == currentSymbol)  
72:              {    
73:                 System.out.println( currentPlayer + " Wins." );  
74:              iteration = 9;   
75:              }  
76:              
77:            else if( box[4] == box[5] && box[5] == box[6] && box[6] == currentSymbol)  
78:                 {   
79:                 System.out.println( currentPlayer + " Wins." );  
80:                 iteration = 9;   
81:                 }  
82:                   
83:            else if(box[7] == box[8] && box[8] == box[9] && box[9] == currentSymbol)  
84:                 {   
85:                 System.out.println( currentPlayer + " Wins. " );  
86:                 iteration = 9;  
87:                 }  
88:              
89:            else if( box[1] == box[4] && box[4] == box[7] && box[7] == currentSymbol )  
90:              {    
91:                 System.out.println( currentPlayer + " Wins." );  
92:              iteration = 9;  
93:               }  
94:                   
95:            else if( box[2] == box[5] && box[5] == box[8] && box[8] == currentSymbol)  
96:              {    
97:                 System.out.println( currentPlayer + " Wins." );  
98:                 iteration = 9;   
99:                   }  
100:                        
101:            else if( box[3] == box[6] && box[6] == box[9] && box[9] == currentSymbol)  
102:             {    
103:                 System.out.println( currentPlayer + " Wins." );  
104:              iteration = 9;  
105:                }  
106:                        
107:            else if( box[1] == box[5] && box[5] == box[9] && box[9] == currentSymbol)  
108:              {   
109:                 System.out.println( currentPlayer + " Wins." );  
110:                 iteration = 9;  
111:                   }  
112:                   
113:            else if( box[3] == box[5] && box[5] == box[7] && box[7] == currentSymbol)  
114:             {    
115:                 System.out.println( currentPlayer + " Wins." );  
116:                 iteration = 9;    
117:                  }  //finished calculating the winner  
118:              
119:            if( iteration < 9 && iteration > 4 )  
120:              System.out.println( " No Result so Far Continue Playing...... " );  
121:              
122:            else if(iteration == 8)  
123:                 System.out.println( " The Game finished and its a TIE!!!!! " );//prints this if game is Draw  
124:                   
125:       }  
126:       // MAIN Method            
127:  public static void main(String argss[]){  
128:            TicTacToe game = new TicTacToe();  
129:            game.startPlay();  
130:       }  
131:  }  

Explanation : 


  • variable currentSymbol stores the symbol of the active player in it                           


When we run the program "startPlay()" method  is called which prints the board.
In that method there is a for loop which iterates from 0 to less than 9. On line# 37 we check if the iteration is even or odd(even for player1 and odd for player2) if its even the "currentSymbol" is set equal to "player1Symbol" and if its odd "currentSymbol" is set equal to "player2Symbol".
      
   After that the player selects a box to fill and the currentSymbol is  printed in the selected box if the selected box is empty. If the selected box is not empty the current  iteration is repeated and the player is asked again to select a box. Then the board is printed again then. Then the process repeats until the iteration = 4.

Deciding Winner:    

When Iteration becomes Equal to 4(i.e five boxes are filled)then the decidewinner method is called to check if someone Won? In decide Winner Method we have if conditions checking for all winning combinations(i.e (1,2,3),(1,4,7),(4,5,6),(7,8,9),(2,5,8),(3,6,9),(1,5,9),(3,5,7)) . If someone has won then the loop is broken and the message showing that the current player has won is displayed.

You can Download the Source Code by Clicking Below Links

TicTacToe Code in Java

TicTacToe Code in C#

Share this Post With Your Friends!!!

Tuesday, 13 May 2014

Find out your Body Mass Index

Here are the Screen Shots of the Application :








This app is developed in C# programming language and the software used to develop is C# 2010 Express
CLICK HERE to Download.

Comment your Email Address below to get the code for this program. Like our facebook page to get the latest stuff!!!


Sunday, 11 May 2014

What You will Learn :

  • What are Static/Class variables
  • What are Instance Variables
  • Scope of Static and Instance variables
  • Difference b/w Static and Class variables


Static Variables :

  • Static variables are associated with all the objects of the class
  • Declared in the class outside of any method or block
  • They are assigned default values when created i.e 0 for integers
  • They have the same state for all objects of the class
  • No object is needed to access them i.e we access them like this  "ClassName.VariableName"
  • They can be used in the static methods
  • Just one copy of static variables per class


This image will clear all the confusion :



Instance Variables :

  • As the name tells Instance Variables are associated with the Instances or Objects of the class
  • Declared in the class outside of any method or block
  • They are assigned default values when created i.e 0 for integers
  • Every object of the class have its own set of Instance Variables.
  • They may have different or same values(states) for all the objects
  • They require the object to be accessed outside of the class as "ObjectName.VariableName"
  • One copy of Instance Variables per Object



Here is an image for further explanation :



I hope you learned something from this post if you have any questions feel free to comment them below. Like us for more free stuff!!!

You will learn :

  • Binary search
  • Linear Search
  • Where to use Linear Search
  • Where to use Binary Search
  • How Binary Search Works

Linear Search :

  • It used on unsorted List 
  • It is very slow for large Lists
  • Its easy to write code for Linear Search
  • Should be only used if the list is a few elements long

Code :

1:  public class Search {  
2:         
3:       public static void main(String args[]){  
4:            int array[] = {1,5,9,11,25,90,122};  
5:            int key = 122;  
6:     
7:      Search.LinearSearch(array,key);  
8:       }  
9:         
10:       public static void LinearSearch(int array[],int key){  
11:            int last = array.length-1;  
12:              
13:            for(int i = 0; i < array.length;i++){  
14:                 if(array[i] == key){  
15:                      System.out.println("The key found at index : "+i);  
16:                      return;  
17:                 }else if(i == last)  
18:                  System.out.println("Not in the Array");  
19:                 else System.out.println("Searching.....");  
20:            }//loop  
21:              
22:       }//method  
23:         
24:  }  
25:    

Explanation :

                     In this program an array is searched for a specific value. A for loop is used to go through and check each element if the element is found at any location in the array the loop breaks and message is displayed. In the other case the message is displayed that "Not i  the Array".



Binary Search:

  • Cuts the array half after each iteration
  • Suitable for searching in large Lists
  • Used only if the List is large enough
  • Faster than Linear Search
  • A bit complex to code

Code :

1:  public class Search {  
2:         
3:       public static void main(String args[]){  
4:            int array[] = {1,5,9,11,25,90,122};  
5:            int key = 122;  
6:     
7:      Search.BinarySearch(array,key);  
8:       }  
9:         
10:       public static void BinarySearch(int array[],int key){  
11:            int last = array.length-1;  
12:            int first = 0,mid = (first+last)/2;   
13:              
14:            for(int i = 0; first <= last;i++){  
15:                 mid = (first+last)/2;  
16:                 if(array[mid] == key){  
17:                      System.out.println("The key found at index : "+mid);  
18:                      return;  
19:                 }else if(array[mid] > key)  
20:                      last = mid - 1;  
21:                     
22:                 else if(array[mid] < key)  
23:                      first = mid + 1;  
24:                 else if(i == array.length-1)  
25:                      System.out.println("Not in the Array!!!");  
26:                 System.out.println("Searching......");  
27:            }//loop  
28:              
29:       }//method  
30:         
31:  }  

Explanation :

                    Look at line# 16 if middle element of the array is equal to the the search number then Display the message "Found the key" and break the loop. At line#19 if middle element is greater than key then the second half of the array is ignored and the end of the array shifts at mid - 1. Similarly At line# 22 if middle element is less than the key than first half is ignored and first is shifted to 'mid + 1'. Note that your array must be sorted in the ascending order first to apply this algorithm.
    Here is an image which may also help :

I hope this post have cleared out the problems and questions related to Linear and Binary Search if not Comment the question below. Like us for more!!!

Tuesday, 29 April 2014

Today You will learn :


  • How to set environment variable for Java
  • How to Run Java from Command Prompt
  • How to Compile Java code from Command Prompt


Before Starting You must check if  JDK is installed if not download install it from oracle's official website.

Lets get Started :


  • Click Advanced System Settings under Computer Properties
  • Click Environment Variables
  • Create a New one with the name path
  • Go to the bin in the JDK installation directory and copy the path
  • Now paste this path as the Variable Value and click ok


Check :


  • Open Command Prompt
  • Type javac and press enter
  • Alot of junk will Appear below

    Like our Facebook Page for more!!!

Monday, 14 April 2014

Things you will learn :

  • What are Headers
  • How to create Headers
  • Why should i create Headers
  • How to include header in your program

What are Header files?

  Header files are similar to the library files in Java. They are created once and can be used in any program in which they are included. Actually you define your functions in the header files to use them again and again without typing the whole code again. All you have to do is to include them in your program first. The most common header files in C/C++ is"conio.h" inside this header some functions are defined which are used to perform actions on console screen.

Create Header Files

Creating a Header file is not difficult at all here is the step by step method:
  • Open Notepad
  • Create your function definations there
  • Open the folder where you compiler saves its Header Files
  • For turbo C++ its in C drive --> TurboC++ --> Disk --> TurboC3 --> INCLUDE 
  • Save the file with ".h" extension  in INCLUDE folder
Congrats You have created a header file. Now you just have to include your header file in your program and check if its working in the way you want it to. You can include the file like this #include<headerfilename.h.>. There should be no errors if you followed the step by step method above.

Here is an Example :


Save this code as "sum.h" in INCLUDE directory.
 int sum(int num1,int num2){  
 return (num1+num2);  
 }  
Now include the header file in the program like this:
 #include<stdio.h>  
 #include<conio.h>  
 #include<sum.h>  
  void main(){  
   clrscr();  
   printf("%d\n",sum(5,5));  
   getch();  
  }  

Explanation : 

In the header file i have defined a function which takes two numbers as parameters and returns their sum. And in my program i just included header file(#include<sum.h>) and called the function which i defined earlier in my header file(printf("%d\n",sum(5,5))). The output is 10.

Today i discussed probably the easiest way of creating the header files. If you know even easier method than that. Share it with others in the comments below. And if you like this post Share it with your friends and Subscribe for more :)


Tuesday, 8 April 2014

Today You will learn :

  • How to use Inner Class to use Key Events and Mouse Events
  • How to cancel key typed event in Java
  • How make numeric JTextField
  • How to limit the number of characters in JTextField
  • consume() method of the KeyListener interface
  • Character.isDigit() method and getKeyChar() method

The main things here are the JTextField , KeyEvents , Inner Classes in Java and how to create numeric TextFields in Java and if you want numeric text box in C# Click Here 

How to use Inner Classes to Implement KeyEvents?

 When i first used inner classes i really avoided them because they a bit complex. But trust me Inner classes are'nt that difficult as they are thought to be. Here's how its done :
  • Create a private inner class
  • Use the implement keyword to implement the KeyListener interface
  • Override all the methods of the interface KeyListener
  • Create the Object of the Inner Class in the enclosing Class like that "InnerClass i = outerclassobject.new InnerClass()"(you have to create outer class object first)
  • Add the object of inner class to the object of component class which you want to implement KeyEvents for example "JTextField.add(KeyListenerObject)"

Here is the code:


 import javax.swing.*;  
 import java.awt.event.KeyEvent;  
 import java.awt.event.KeyListener;  
   
 public class NumericBox{  
      static JTextField tf = new JTextField();  
        
      public static void main(String arh[]){  
             
           NumericBox g = new NumericBox();  
           Handle h = g.new Handle();  
           JFrame f = new JFrame();  
           JPanel p = new JPanel();  
             
           tf.setColumns(5);  
           tf.addKeyListener(h);  
             
           p.add(tf);  
             
           f.add(p);  
           f.setSize(200, 200);  
           f.setVisible(true);  
             
      }//end of main method  
        
      private class Handle implements KeyListener{  
   
       public void keyTyped(KeyEvent e) {  
           if(tf.getText().length() == 6)  
                     e.consume();  
                       
           if(e.getKeyChar() != 13 && !Character.isDigit(e.getKeyChar())   
                && e.getKeyChar() != 42 && e.getKeyChar() != 43   //key codes of the keys
                && e.getKeyChar() != 45 && e.getKeyChar() != 46   //you want to enable
                && e.getKeyChar() != 47)  
                     e.consume();            
           }  
   
           public void keyPressed(KeyEvent e) {}  
           public void keyReleased(KeyEvent e) {}  
             
      }//end of inner class  
        
 }//end of outer class  
   
   

Output:

Explanation : 

                   In the keyTyped method of the inner class at  I have checked if the the characters typed in the text field is equal to 6 then the key event is canceled by using the consume() method in the this way i have restricted from entering more than 6 character in the text field.  To restrict the user to enter digits only i have used Character.isDigit(e.getkeyChar()). e.getKeyChar() returns the ASCII code of the key pressed here if the key pressed do not represent a digit the key event is canceled similarly i have enabled several other keys using ASCII code if you don't know the ASCII code of keyboard keys CLICK HERE.

I hope You have learned Something from this post if have any suggesions for me contact me at daniequreshigmail.com or comment below And Follow Me for more stuff!!!



Thursday, 3 April 2014

What You are About to Learn?


  • Array Reversing
  • Java String.charAt(index) method
  • String Reversing
  • StringBuilder
  • StringBuffer.reverse() method in Java
  • Java String.toCharArray() method


String Reversing Method # 1 : 
 public class StringReversing {  
   public static void main(String args[]){  
   char temp;  
   String s = new String("Hello");  
   System.out.println(s);  
   char str[] = s.toCharArray();  
   int last = s.length() - 1;  
   for(int first = 0; first < s.length()/2; first++){  
      
   temp = s.charAt(first);  
     
   str[first] = str[last];  
   str[last] = temp;  
     
   last--;  
   }  
   s = new String(str);  
   System.out.println(s);  
  }//end of main  
    
  }//end of class  
   
   
                                             
 OUTPUT :

Explanation : In line number 06 i have used the String.toCharArray() method to store the converted(to array of characters) value of the  string in Array of characters "str" .
charAt(index) is the build in method in Java String it simply returns the character at the index "index"(index is an integer) it can not be used to assign the value For example i cant do this  s.charAt(0) = 'c' . At line #10 the value of first character of the "str" is copied in the variable temp. In 1st iteration of the loop the first char in "str" is replaced by the last and last is replaced by the first one. 

       Similarly in second iteration of the loop 2nd character is replaced by second last and vice versa. This process will carry on until the whole Array is reversed. And at the end the result is printed in line #18.



String Reversing Method #2 :
 public class StringReversing {  
  2   
  3 public static void main(String args[]){  
  4    
  5   String s = new String("Hello");  
  6   StringBuffer sb = new StringBuffer(s);  
  7   System.out.println(s);  
  8    
  9   sb.reverse();  
 10    
 11   s = new String(sb.toString());  
 12   System.out.println(s);  
 13 }//end of main  
 14   
 15 }//end of class  
   
   
             
                         
Output will be the same.

Explanation :  Here i used StringBuffer. I saved the string in the StringBuffer. Then i used the reverse(reverse method is build in for StringBuffer) method for StringBuffer to reverse the it. At the end i copied the saved the converted(to string) value of StringBuffer in the string value and displayed it.

Share other methods which you find useful too!!

                                                                                                                                                    

I Hope You Learned Something from this Post if you have any problem comment below i will reply as soon as possible, FOLLOW Me for more Good Stuff :) 


Tuesday, 1 April 2014

Why to make a TextBox numeric ?
  
Imagine the situation in which you are making a calculator app and if the user types chars except digits that may result in undesired output. A wise programmer will not let that happen and he will restrict the user to type only numbers so that the chance of user mistyping is eliminated. 
     
    Today i am going to tell you how to make numeric textbox and other useful stuff you can do with textbox
    Here is the code :


  private void textBox1_KeyPress(object sender, KeyPressEventArgs e)   
    {   
     if (!(e.KeyChar >= 48 && e.KeyChar <= 57 && e.KeyChar != 8))   
      e.Handled = true;   
    }   

     "textBox1_KeyPress" method is called every time a key is pressed inside the "textBox1". Inside the method there is an if which checks  weather or not ASCII key Code of the key pressed by the user is greater or equal to 48 and less than or equal to 57 if both the conditions becomes true then the corresponding character appears in the "textBox1" if not then the "keyEvent" is cancelled. KeyEvent is cancelled by setting "e.Handled = true;".

 You can restrict your textbox to accept only the keys you want it to accept for this you need to know  ASCII values for keyboard keys.
  If you don't know the ASCII values for keyboard keys you can check them HERE

 There is another method for doing this which is a bit easier for beginners :

  private void textBox1_KeyPress(object sender, KeyPressEventArgs e)   
    {   
     if (!char.IsDigit(e.KeyChar) && e.KeyChar != 8)   
      e.Handled = true;   
    }  

   In this case whenever the user presses the key C# checks weather or not the key pressed by the user represents a digit if the key represents a digit the key event goes fine but if not then the key event is cancelled. The other thing you have to do is to enable the backspace button by using its ASCII value.



 
Other useful textbox Properties

You can make your textbox secure by using the PasswordChar property you can set the PasswordChar to any char and when you type in the textbox the digits are hidden and password char is diplayed instead. This is useful in many situations for example if you are creating the facebook login app you don't want anyone to see what you typed in password textbox.

You can set the maximum length of the characters the textbox accepts by setting textbox.MaxLength.

 If you want some different text color in the textbox you can use textbox.ForeColor property and you can do the same for Background as well. See which colors C# supports HERE.

Hope you Liked this FOLLOW Me for more!!!

Saturday, 29 March 2014

You can launch your Java project by just double clicking the jar file of the project. For that you have create the jar file first. Don't worry you don't have to download additional tools for that purpose it can be done using Eclipse.

If you don't have Eclipse you can download it for your platform HERE
If you don't have JDK you can download it free for you OS HERE

Here is the step by step method to create Executable Jars using Eclipse :


  • Right Click the project from which you want to create jar file 

  • Click Export 
  • Choose Export destination as Java 
  • Select Runnable JAR file  under Java 
  • Select a Launch configuration i.e select the main class 
  • Select the destination where u want to create JAR file
  • Select Extract required libraries into Generated JAR file under Library Handling  



  • Click Finish


Hope You liked this post FOLLOW ME For more HAPPY CODING :)


Monday, 24 March 2014

Java is extremely powerful and Easy Language. But don’t misunderstand its easy but powerful and popular language. It is a must learn programming language for you weather you want to develop web Applications or desktop Applications. It is also good for you if you are willing to develop for mobile phone. Java is Ideal choice for everyone.

Lest's check  the reasons behind Java's success and why it is the first choice for every programmer in application development market.
1 : Its Easy to Learn  :
Java is the easiest programming language to start with. Believe me if you are a beginner you are gonna love its syntax as it is quiet easy and almost same to the natural language. Beginners can learn and understand  a lot faster as compared to C++. The syntax of Java is easy to remember so the beginners do not have to waste a lot of their time in learning the complicated syntax unlike C++ so beginners can give more time for learning programming rather than learning the syntax. Java is free and it is object Oriented.
2 : Platform Independent and Powerful development tools :
Java introduced the concept of WORA(Write Once Run Anywhere)which is One of the biggest reasons of Java’s success. You can develop on one platform and can run it on many others which saves a lot of time and effort. But JRE(Java Runtime Environment) should be installed on the target platform first. You can get latest version of JRE for your platform at Oracle Website.
Java has powerful development tools like Eclipse , NetBeans and IntelliJ.
3 : 3rd Party Support:
Many other companies support Java. Java supports Android application an OS development (which attracts mobile developers). It can also easily integrate with databases like MySQL. Web pages can also be created using Java. GWT(Google Web Toolkit) supports java to create web pages. Java is also used to create dynamic webpages and Server side Applications(JSP's and Servlets).
4 : Highly in Demand :
JAVA is highly in demand by employers and its not going end up soon due to its advanced features and ease of usage. Most of the applications developed now a days are coded in Java. 
Java developers are more likely to get a good job as compared to C++ developers. As mentioned above java has 3rd party support which makes it much more popular as compared to other programming languages.
5 : Free notes plus free IDE's :
Java have a lot of online support and free notes are available in thousands of websites. It also has the better IDE's than others like Eclipse EE ,Net Beans. And all of that for Free!!! 
6 : Java is an All Rounder :
You can do anything using Java you can create web pages and web applications using Java. Java is also a must learn if you want to develop mobile applications. You can create Databases using Java. You can create games with high quality graphics. There is nothing which you can not do with java.  Java is fun And i Bet you will never feel tired of Java.

If You Liked my Post FOLLOW ME for more stuff  :) !!!

Saturday, 22 March 2014

The biggest problem a beginner faces is the problem of Logic Developing. Many of Beginners do not have too much creative thinking. Today i m going to share with you the techniques which i used to strengthen my logic in programming and  they helped me a Ton. Believe me you are going to love them.
Know what you are doing 1 : Most of the beginners just want to make their code run rather then thinking of logic behind it. Trust me you are not going to learn anything if you continue doing this.The better way is to break your problems into pseudo code and then try to implement each line of pseudo code into the program.
Read Other programmer’s Code 2 : Obviously I am not asking to copy other programmer’s code always use your own methods. But after developing your own logic for a problem try to compare that with other’s programs. You can learn a lot by doing this.
Challenge Your Skills 3  : Keep testing and Challenging yourself on a regular basis. Try to do something new and challenging whenever you find time. Your quest for knowledge should never end.
Challenge The Rules 4 : Always keep challenging the rules of the language for example java does not allow constructor overriding. Think that why the developers chose not to allow constructor overriding. What problems would arise if it was allowed? and what are the possible benefits if it is allowed?
Understand The Algorithms 5 : Try to understand the algorithms you find on the internet and write code for them by yourself rather than copying code from the internet some example algorithms are Bubble Sort , Array Reversing , Even or odd functions , drying shapes using asteriks and loops and many more.
Teach others and Discuss 6 : Teaching others will help you a lot to review the things you skipped and its also going to make you much more confident of what you can do. 
Write Your Own Code 7 :  Always try to develop your own logic don’t copy code from the internet, internet should always be your last option.
Never Lose Heart 8 : A large number of beginners fail to become a successful programmer because they are impatient and lose heart too early. So Never even think of giving up just keep trying and you will see the improved version of yourself everyday.



Hope this helped. If there are some other tips which worked for U comment below and and   FOLLOW ME for more  :) !!!

Thursday, 20 March 2014

 Have you ever thought about what if you could know the time taken by your code to run. That's what todays post is all about.

Knowing the speed of your program or algorithm is very important. Because that's the only way to make it better and faster. Today i am going to show you how you can calculate the running time of your program.
     For doing this you first need to include the header file "time.h". Then declare two variables of "time_t" type i.e "time1" and "time2". Save the current time in variable time1(time (&time1);) then at the end of the program again save the value of current time this time in "time2"(time (&time);). Then call the method "difftime(time2,time1);"  like this. And this will return you the time taken in seconds.
      Similarly if you want to calculate the time for a specific method save the current time before and after the method and call the function "difftime()".

#include <stdio.h> #include <time.h> #include<conio.h> #include<iostream.h> void main (void) { clrscr(); int sum,a,b; time_t time1,time2; double dif_sec; time (&time1); cout << "Enter the value of a :"<<endl; cin >> a; cout << "Enter the value of b :"<<endl; cin >> b; sum = a + b; time (&time2); dif_sec = difftime (time2,time1); cout << "\nThe sum is : " << sum<<endl; cout << "\nIt took you " << dif_sec << " seconds to enter the numbers and calculate the sum"<<endl; cout << "Press Any key to Continue....."; getch(); }

Output :


If you like my post Comment below and subscribe for more :) !!!

Wednesday, 19 March 2014

To understand this first you need to know why do we create static methods and how do we call them learn about static methods at :
Main method is declared static because static methods do not need any instance to get themselves called. Java is Object Oriented language so it is necessary to declare the  main method as static because their are some conditions in which we don’t want to create the object for example if we want to do simple programming without using Concepts of OOP then their is no way to call the main method but by declaring it static. The code below will help you understand.
  public class MyClass{
public void main(String arguments[]){
System.out.println(“KodingExamples.blogspot.com”);
}
}
The above code generates an error: main method is not static please define the main method as:
   public static void main(String[] args)
But when the main is made static this code runs fine and gives the output: KodingExamples.blogspot.com
          If you find my answer interesting and easy to understand invite your friends to read this and Don’t Forget to Like and give your feedback and suggessions and FOLLOW me for More :)!!

Tuesday, 18 March 2014

Today i m going tell you how you can calculate your typing speed using Java code
Here is the Code :


 import java.util.Scanner;  
   
 public class TypingSpeedCalculator {  
  int no_of_words=0;  
  static int z;  
  double minutes;  
  double start,end;  
    
    
 public int count_Words(){  
 int a=1;  
 String b;  
   
 Scanner s1 = new Scanner(System.in);  
   
 System.out.println("Type some text : ");  
   
 start = System.currentTimeMillis();  
 b = s1.nextLine();  
   
 end = System.currentTimeMillis()-start;  
   
 minutes = end/60000;  
   
 for(int i = 0;i < b.length();i++){  
   
  if(b.charAt(i) == ' '){  
  a = a + 1;  
  }  
 }  
 no_of_words = a;  
   
 return a;  
 }  
   
 public void typing_Speed(){  
  double a = 0;  
    
  a = no_of_words/minutes;  
   
  System.out.println("Your typing Speed is "+a+" WPM");  
 }  
   
 public static void main(String args[]){  
    
  TypingSpeedCalculator ui=new TypingSpeedCalculator();  
   
  System.out.println("\nOutput : \n");  
   
  ui.count_Words();  
   
  ui.typing_Speed();  
 }  
 }  
Output:


  Hope you Liked this. FOLLOW me for more awesome stuff!!! 



Get Your Programming Related Problems SOLVED




Subscribe to RSS Feed Follow me on Twitter!