First C Program, Hello World

Following C program will simply print “Hello World” on screen. Write carefully because C language is a case sensitive language.

#include < stdio.h>
void main()

{

printf(“Hello World\n”);

}

Press ALT+F9 to compile your program. If you have any error in your program, you will get the message, remove your errors and then execute your program you will got the out put.

Hello World

The printf()

The printf() function prints output to stdout, according to format and other arguments passed to printf(). The string format consists of two types of items – characters that will be printed to the screen, and format commands that define how the other arguments to printf() are displayed.

printf( “Hello World”);

The scanf()

The scanf() function reads input from stdio, according to the given format, and stores the data in the other arguments. It works a lot like printf(). The format string consists of control characters, white-space characters, and non-white-space characters.

void main(void)
{

int i;
scanf(“%d”,&i);
printf(“%d”,i);

}

Java Syntax

In computer programming the syntax is a set of rules which define how a program is written and interpreted. The java syntax is similar to C++.

Java Hello World

public class JavaHelloWorld {

/* This program will print Java Hello World on screen */

public static void main(String []args) {

System.out.println(“Java Hello World”);

}

}

Save this program in JavaHelloWorld.java file.

In command prompt go to the directory where this file is located and type ‘javac JavaHelloWorld.java’

It will compile your program. after that type ‘java JavaHelloWorld’ to see the output.
Code blocks

In java braces { and } are used for code blocks. Body of a method, if statement, loops etc are written inside these braces.

void myFun() {

int a;

a = 5;

}

Java Comments

Comments are ignored in program execution. Comments are also used by javadoc tool to generate automatic documentations. In java we can add comments in following ways.

// This is a single line comment

/* multi-line comment.

…. */

/**
* This is a javadoc comment.
*
* @author Allen Kooper
* @version 1.0.1
*/