Hello World Using C sharp, C and Java Simple Hello World Program In any Language.




Learn to write your first Hello World Program : Hello World Program Using C sharp, C and Java


/*This the first Program in C */
#include <stdio.h>
int main() {

   printf("Hello, World.... \n");

   return 0;
}

——————————————-

Output :

Hello, World….

Let us take a look at the various parts of the above program −

  • The First line /*…*/ will be ignored by the compiler and it has been put to add additional comments in the program. So such lines are called comments in the program.
  • The next line of the program #include <stdio.h>  which tells a C compiler to include stdio.h file before going to actual compilation.
  • The next line int main() is the main function where the program execution begins.
  • The next line printf(…) is another function available in C which causes the message “Hello, World….” to be displayed on the screen. Any thing that you write inside of this function used to display on the screen.
  • The next line return 0; terminates the main() function and returns the value 0.

Hello World program in JAVA

/* Helloworld in Java */
public class HelloWorld {
  public static void main(String args[]) 
 { 
   System.out.println("Hello world in Java");
 }
}

output:

  • The First line /*…*/ is used for comments, Which is same as used  in the c Program .
  • In Java, every line of code that can actually run needs to be inside a class. This line declares a class named HelloWorld, which is public, that means that any other class can access it. This is not important for now, so don’t worry. For now, we’ll just write our code in a class called Main, and talk about objects later on.
  • Notice that when we declare a public class, we must declare it inside a file with the same name (HelloWord.java), otherwise we’ll get an error when compiling.When running the examples on the site, we will not use the public keyword, since we write all our code in one file.
  • In the next line,

    This is the entry point of our Java program. the main method has to have this exact signature in order to be able to run our program.
  • public again means that anyone can access it.
  • static means that you can run this method without creating an instance of Main.
  • void means that this method doesn’t return any value.
  • main is the name of the method.
  • The arguments we get inside the method are the arguments that we will get when running the program with parameters. It’s an array of strings. We will use it in our next lesson, so don’t worry if you don’t understand it all now.
  •  System is a pre-defined class that Java provides us and it holds some useful methods and variables.out is a static variable within System that represents the output of your program (stdout).println is a method of out that can be used to print a line. This is same as printf in c

Hello World Program in C#

/* First Hello World Program in C# */

namespace HelloWorld 
{
 class Hello
 { 
     static void Main() {
        Console.WriteLine("Hello World!"); 
        // Keep the console window open in debug mode. 
           Console.WriteLine("Press any key to exit."); 
           Console.ReadKey(); 
      }
 }
}

output: