Showing posts with label JAVA. Show all posts
Showing posts with label JAVA. Show all posts

Saturday, 4 July 2015

Hello World

The 'Hello World' program is the first program in any programming language. The following[ program simply writes the string in double quotes (" "), on the output screen.


class HelloWorld
{
 public static void main(String[] args)
 {
System.out.print("Hello World! Welcome to Programming Infinitum.");
 }
}

Sunday, 8 June 2014

ESSENTIALS OF JAVA PROGRAMMING



ESSENTIALS
Consider a simple java program.
class hello
{
public static void main(String ar[])
{
System.out.println(“HELLO”);
}
}                  //main ends here
Let us now examine the parts of this simple program
   1.     class hello
the line class hello means that a class is defined. The defined class is the initial class (an initial class is a class that contains a main function inside it). It should be kept in mind that the class name is same as the name of the program. The extension of the java programs is given as .java.
   2.     Method main
Our class contains one method and the name of this method is main. The main method is where a program begins execution. if we have multiple classes then the execution of the program begins from the point where main method is encountered, if we do not have a main method then the program will not get executed. The main method is also termed as driver method because it drives our program.
   3.     System.out.println("Hello”)
This statement prints HELLO to our standard output device which is generally our monitor. We must notice that this statement is terminated by semicolon(;) as usual.
   4.     Comments /*……..*/ and //
We include comments in our program to enhance code readability. /*…..*/ is used to write multiline comments and // is used to write single line comments. The comments are ignored by the compiler and not executed at all even if we write a valid java statement.

Wednesday, 4 June 2014

Finding vowels in a string

import java.io.*;
class vowels
{
    public static void main()throws IOException
    {
        BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
        System.out.println("ENTER A STRING");
        String s=br.readLine();
        int l=s.length();
        char array[]=new char[l];
        for(int i=0;i<l;i++)
        {
            array[i]=s.charAt(i);
        }
        int counter=0;
        for(int i=0;i<l;i++)
        {
            if(array[i]=='a' || array[i]=='e' || array[i]=='i' || array[i]=='o' || array[i]=='u')
            counter++;
        }
        System.out.println("total number of vowels in the sentence are"+counter);
    }
}



Shashank Chauhan
Naveen Dengani

Java program which gives initials of your name

import java.io.*;
class initials
{
    public static void main(String ar[])throws IOException
    {
        BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
        System.out.println("enter a name");
        String s=br.readLine();
        int l=s.length();
        char k;
        char a[]=new char[l];
        for(int i=0;i<l;i++)
        {
            a[i]=s.charAt(i);
        }
        System.out.println(a[0]);
        for(int i=0;i<=l-1;i++)
        {
            if(a[i]==' ')
        {
        System.out.println(a[i+1]);
        }
        }
    }
}
   

Tuesday, 3 June 2014

Beginning with Java

import java.util.Scanner;
class random1
{
    public static void main(String []ars)
    {
        int a;
        float b;
        String s;
       
        Scanner in=new Scanner(System.in);
        System.out.println("ENTER YOUR NAME");
        s=in.nextLine();
        System.out.println("entered name is"+s);
        System.out.println("enter the number");
        a=in.nextInt();
        System.out.println("number entered is"+a);
        System.out.println("enter the float value");
        b=in.nextFloat();
        System.out.println("entered number is"+b);
    }
}

Sunday, 1 June 2014

simple java program

import java.util.Scanner;
/* We import Scanner class from java.util package for
     taking input from the keyboard*/
class temperature
{
    public static void main(String []ars)
    {
        Scanner in=new Scanner(System.in);
        System.out.println("enter temperature in fahrenheit");
        float a=in.nextFloat();
        float b=(a-32)*5/9;
        System.out.println("temperature in celsius is"+b);
    }
}
       

Sunday, 25 May 2014

C# and JAVA

C# and JAVA are the programming languages that have a common root and this root is C++.
Moreover C# was developed by Microsoft as an alternative to JAVA for web based programming.


 Differences between C# and JAVA
1.       C# has more primitive data types than Java.
2.       Arrays are declared differently in C#.
3.       Unlike Java , all C# data types are objects.
4.       C# supports struct type and Java does not.
5.       C# provides static constructors for initialization.
6.       Java does not directly support enumerations.
7.       Java does not have any equivalent to indexers.
8.       Catch blocks should be ordered correctly in Java.
9.       There is no labeled break statement in C# . The goto is used to achieve this.
10. C# supports another iterative statement foreach along with the three(for , while and do while).