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.

Friday, 7 November 2014

Hey friends,


Welcome to simplyjaavapro,  today I will discuss about your first java program.


Yes, you guessed it right ! It is the most famous problems of all times..to print a message called Hello, World on the screen.

If this sounds to be boring, you can print whatever you may feel like.

The code goes like this:


class MyFirstJaavaProgram
{
         public static void main(String args[])
         {
                   System.out.println("Hello, World "); // You can type your message within the quotes 
          }
 }

-------------------------------------------------------------------------------------------------------------------

Yes, this is it. Now save the file as MyFirstJaavaProgram.java 

Next you need to open up your terminal window (or a command prompt), and give the following command:

javac MyFirstJaavaProgram.java

java MyFirstJaavaProgram


----------------------------------------------------------------------------------------------------------------

And there you go, your first java program has been created, compiled and executed.

Tuesday, 4 November 2014

Hello everyone, this is a guide to install openjdk (Java Development Kit for Open Source) on your linux-based Operating System.


Following are  instructions that you need to follow:


1. open up a terminal (you may use ctrl + alt + t)

2. write the following command:

sudo apt-get install openjdk-7-jdk

3. give your password (it will not be displayed on the screen)

4. Say yes to download the installation file

5. That's all you need. Enjoy coding with java



Hello everyone this post deals with the installation of a Java development environment on a Microsoft Windows PC.

Following are the steps involved:

1. Go to

2. Download the latest JDK versionhttp://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html


3. Double click the downloaded file and follow the installation instructions.

4. That's all you need, enjoy programing with java.



Saturday, 1 November 2014

An Introduction to Java

Java, is a powerful programming language. An object oriented language, probably the most popular one as well. Well, Java is everywhere, at your PC, your hand-held device, even at your DVD player, and all that you can think of.

And what else, it is simple and easy to learn. A powerful computer programming language that facilitates programmers to do a lot of things really easily.

And, now something about me, I am Prateek Tiwari and I shall take you to a tour of J2SE.