The addition of two numbers in C language is performing the arithmetic operation of adding them and printing their sum on the screen. For example, if the input is 5, 6, the output will be 11. Small Basic is the only programming language created specially to help students. Screenshot of Small Basic code. Small Basic combines a friendly.
![Program Program](/uploads/1/2/6/3/126329477/147023827.jpg)
Java is an object oriented language (OOP). Java objects are part of so-called 'Java classes'.
Let's go over the Hello world program, which simply prints 'Hello, World!' to the screen.
The first line defines a class called Main.
![Code Code](https://i.ytimg.com/vi/YW0oUBfe7Kg/maxresdefault.jpg)
In Java, every line of code that can actually run needs to be inside a class. This line declares a class named
Main
, 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 (Main.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.
The next line is:
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 ofMain
.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.
Exercise
Print 'Hello, World!' to the console.
You need the following 2 software to create your first Java Program
- The Java SE Development Kit
Please refer our last tutorial to download and install JDK
- A Text Editor
In this example, we'll use Notepad. it is a simple editor included with the Windows Operating System. You can use a different text editor like NotePad++
This video will help you code your first Java program.
Click here if the video is not accessible
Steps to Compile and Run first Java program
Step 1) Open Notepad from Start menu by selecting Programs > Accessories > Notepad.
Step 2) Create a Source Code for your Program
- Declare a class with name A.
- Declare the main method public static void main(String args[]){
- Now Type the System.out.println('Hello World'); which displays the text Hello World.
Step 3) Save the file as FirstProgram.java make sure to select file type as all files while saving the file in our working folder C:workspace
Step 4) Open the command prompt. Go to Directory C:workspace. Compile the code using command,
Step 5) If you look in your working folder, you can see that a file named A.class has been created.
Step 6) To execute the code, enter the command java followed by the class name, as expected output Hello World is displayed now.
Note: Java is case sensitive Programming language. All code, commands, and file names should is used in consistent casing. FirstProgram is not same as firstprogram.
Step 7) If you copy and paste the same code in IDE like Eclipse the compiling and execution is done with the click of a button Using IDE is convenient and improves your efficiency but since you are learning Java, we recommend you stick to notepad.