Wednesday 10 December 2014

This is a sample code for if-else statements in Java.
This is a sample code to implement switch statements in java.
Hey friends, welcome to simlplyjavapro! 


After you have successfully got the user-input. Well the analysis is perhaps the most interesting part of computer programming. It begins with checking for simple conditions and then it could be extended to any level.


So, lets get started . Java provides you with two tools that help you to analyse your data.

1. The first option is switch-case clause.

       when you choose this option you are supposed to follow the syntax given below:

                     switch(var)
                     {
                               case <value 1>:   //code for case 1
                                                          break;
                               case <value 2>:  //code for case 2
                                                          break;

                                defalut: 
                                                   //code for the default case 
                    }

       Note: When you are using switch case, there are a set of things that you must consider that the                      variable you use in either int or char.You must ensure to use a break after every case, or  
                 you "FALL THROUGH". Under a fall through the control matches a case , it executes                        each case that follows without matching for it, unless it finds a break or the end of the                          switch.

2. The second option is to use if -else clauses:

         Syntax:
                        if (condition)
                        {
                                      //code block for the case when the condition holds true
                        }
                        else
                        {
                                      //code block for the case when the condition is false
                        }
                   Note: The only restriction here is that the condition must be finally a boolean value. 
                             for example :  age <25


So that is it !!! In the next post  I will share a sample code to implement the clauses mentioned above.
                          



                                          

Tuesday 25 November 2014

Hey friends, this is an example of a simple java program which takes an input from the user.


Hey friends, welcome to simplyjavapro,


Well Its been quiet a lot of time since you've had known about Data types in Java.


So, lets get stated and try to do some really stuff in Java Programming.

Have you ever wondered how does the computer access that you "Input" and process it to give you a desired Output. Well, it is nothing but a set of codes, which make it possible.

In a powerful programming language, such as Java, you are expected to "import" the ability to use the Input/Output devices.


The first thing that you need to do in java to enable I/O(input-output) is to the following line of code before you mention your class.

import java.io.*;

The statement above imports a package called "io" from the java library which enables you to do input and output stuff in your programs.

The next step is obviously to mention your class, and then the main method.

class InputOutputExample
{

        public static void main(String args[]) throws IOException
       {
                 //Block of code              
        }
}
The code "throws IOException" takes care for any abnormalities that may occur during an IO.

Notice the double slashes used inside the main method. These indicate single line comments in Java.We shall discuss more about comments later. For now, you may consider that the line written in such a manner is not a part of the executable code.

In place of the Commented section you've got to use a few Classes to enable standard I/O in your program.

Write the following line of code:

InputStreamReader isr=new InputStreamReader(System.in);
BufferedReader br=new BufferedReader(isr);


The above two lines allow you to take input from the standard input device, the keyboard (thanks to System.in)


Now take input using the readLine() method of the BufferedReader class.

Write the following line of code:

String input=br.readLine();


and this is it....

You have got your input from the keyboard. Now you could use it whichever way you like, print it perhaps.

System.out.println(input);

now just close your main methods and your class. Compile and run your code.

During the interpretation of the code(or during the time you program is running) your programs halts to take the input, type in any string and press ENTER.

and there you have your output.


Monday 17 November 2014

class DataTypes
{
          public static void main(String args[])
         {
                  int a;
                  a=5;
                  float f=3.14;
                  boolean b=true;
                  String s="smaple string";
                  System.out.println("a= "+a);
                  System.out.println("f= "+f);
                  System.out.println("b= "+b);
                  System.out.println("s= "+s);
          }

}

Saturday 15 November 2014

Hey friends, welcome to simplyjaavapro. Today, I shall discuss about data types in java.

Well, you may have heard that Java is a highly typed language.  The statement basically means that there exists a set of semantics for data types in Java programming language. Java provides data types under broad categories:


1. Pre -defined data types: These come in naturally with Java. They include:

i.  For integral Numbers         : int, short, long
ii. For floating point Numbers : float
iii.For characters                 : char


2. User - defined data type: These are defined by the user.


Note: A user defined data-type is basically an object reference to some object. One such data type comes pre-defined, called String.


Note: String is not rigidly a pre-defined data-type, although it may seem to be. It is actually an Object reference similar to any other user defined data type.