Thursday, May 31, 2012

/*PROGRAM TO PERFORM ARITHMATIC OPERATIONS THROUGH A SINGLE PROGRAM*/

 /*PROGRAM TO PERFORM ARITHMATIC OPERATIONS THROUGH A SINGLE PROGRAM*/

PROGRAM:

 class Arithmetic
{
         public static void main (String[] args) 
          {
                 short x = 6;
                 int y = 4;
                 float a = 12.5;
                 float b = 7;
                System.out.println(“x is “ + x  “, y is “ + y);
                System.out.println(“x + y = “ + (x + y));
                System.out.println(“x - y = “ + (x - y));
                System.out.println(“x / y = “ + (x / y));
                System.out.println(“x % y = “ + (x % y));
                System.out.println(“a is “ + a + “, b is “ + b;
                System.out.println(“a / b = “ + (a / b));
       }
}

SAMPLE OUTPUT:

x is 6, y is 4
x + y = 10
x - y = 2
x / y = 1
x % y = 2
a is 12.5, b is 7
a / b = 1.78571


TRY YOURSELF:4

1)Write a program to calculate your shopping expense.Imagine that you have took Rs.1000 for shopping and calculate how much you money you saved by purchasing the items in that shop.Find out your total expense and your balance amount with you.


Note:Answer will be displayed after 24 hours in solution page.

Wednesday, May 30, 2012

/*PROGRAM TO FIND SQUARE ROOT USING MATH FUNCTIONS*/

/*PROGRAM TO FIND SQUARE ROOT USING MATH FUNCTIONS*/

PROGRAM: 

import java.io.*;
import java.lang.math*;
class square
{
         public static void main(string args[ ])
         {
               double x=5,y;
                y=math.sqrt(x);
                system.out.println("SQUARE ROOT="+y);
          }
}

SAMPLE OUTPUT:

SQUARE ROOT=2.2360


TRY YOURSELF:3

1)Try out the program program to find square root of the number(decimal).

Note:Answer will be published after 24 hours at solution page


/*PROGRAM TO ADD TWO NUMBERS*/

/*PROGRAM TO ADD TWO NUMBERS*/


PROGRAM:

import.java.io.*;
class add                      //Creation of Class
{                       
       public static void main(string args[ ])                           //Main function
       {
              int a=10,b=20;                                               //Declaration of variables
              int c;
              c=a+b;
              system.out.println("ADDITION OF TWO NUMBER IS  "+c);            //print the statement
        }
}

SAMPLE OUTPUT:

ADDITION OF TWO NUMBERS IS 30

Try Your Self 

1) Program for Find Simple Interest using your own variables and store the result in the variable si.

*find the solution of this program at solution page tomorrow

Tuesday, May 29, 2012

Compiling the program

Let us see now how the simple java program will look like.

You can use any editor like notepad or any Java IDE for writing java programs.
/*This is a sample java program Save this file as Welcome.java*/
import.java.io.*;
class Welcome
{
//  A java program will start from here.
        public static void main(String args[])
            {
              System.out.println("  Welcome to learndotjava ");
            }
}

For those who are using the IDE, you can follow the instructions have given by there.Suppose if you are entering your program in notepad, then save this file as Welcome.java
Filename must be same as that of Class Name

* -->symbol indicates import all function from library
.(dot)-->symbol is used to bind the functions

Compiling the program

After we have written our program we need to compile and run the program. For that we need to use the compiler called javac which is provided by java.Go to the command prompt and type the file name as shown here.


c:\>javac Welcome.java

The javac compiler will create a class file called Welcome.class that contains only bytecodes. These bytecodes have to be interpreted by a Java Virtual Machine(JVM) that will convert the bytecodes into machine codes. Once we successfully compiled the program, we need to run the program in order to get the output. So this can be done by the java interpreter called java. In the command line type as shown here.


c:\>java Welcome

Sample Output

Welcome to learndotjava 

TRY YOUR SELF

1)WRITE A PROGRAM TO PRINT YOUR NAME AND ADDRESS IN SEPERATE LINES

 

Saturday, May 26, 2012

Why Java Is Preferred?

     Before Learning About a Topic We Want To Think And Know.Why It Is Preferred.What's The Reason To Prefer It.Java as a language has significant advantages over other languages and other programming environments that make it suitable for just about any programming task. This section describes some of those advantages.
  • Java Is Platform-Independent

            Platform independence is one of the most significant advantages that Java has over other programming languages, particularly for systems that need to work on many different platforms. Java is platform-independent at both the source and the binary level.
  
  • Java Is Object-Oriented

          Working with a real object-oriented language and programming environment, however, enables you to take full advantage of object oriented methodology and its capabilities of creating flexible, modular programs and reusing code.Many of Java’s object-oriented concepts are inherited from C++, the language on which it is based, but it borrows many concepts from other object-oriented languages as well.

  • Java Is Easy to Learn

         In addition to its portability and object-orientation, one of Java’s initial design goals was to be small and simple, and therefore easier to write, easier to compile, easier to debug, and, best of all, easy to learn.Although Java looks similar to C and C++, most of the more complex parts of those languages have been excluded from Java, making the language simpler without sacrificing much of its power. There are no pointers in Java, nor is there pointer arithmetic. Strings and arrays are real objects in Java. Memory management is automatic.




Introduction And History

Introduction

    Java, having been developed in 1991, is a relatively new programming language.   At that time, James Gosling from Sun Microsystems and his team began designing the first version of Java aimed at programming home appliances which are controlled by a wide variety of computer processors.

     Gosling's new language needed to be accessible by a variety of computer processors.  In 1994, he realized that such a language would be ideal for use with web browsers and Java's connection to the internet began.  In 1995, Netscape Incorporated released its latest version of the Netscape browser which was capable of running Java programs.

     Initially called Oak, in honor of the tree outside Gosling's window, its name was changed to Java because there was already a language called Oak. 

History   

The original motivation for Java
● The need for platform independent language that could be embedded in various consumer electronic products like toasters and refrigerators.One of the first projects developed using Java

● a personal hand-held remote control named Star 7. At about the same time, the World Wide Web and he Internet were gaining popularity. Gosling  realized that Java could be used for Internet
programming. 


 


Animated Social Gadget - Blogger And Wordpress Tips