Hello guys, Today i will continue my java programming series.
Let's start..
In the previous tutorial you saw i used terminal to compile code. But in large project we do not do that we simply use IDE. I use Apache Netbeans. You can download it from the bellow link. It's free.
Netbeans
Install netbeans or your favourite IDE and create a java project.
Note:
JVM start executing code from main method. It is entry point.
package declaration
At top of the file we declare package name. We use package
keyword to declare a package like..
package com.example;
Printing on console
To print on console we use this code
System.out.println();
out
has some other methods. Some of them are
System.out.print();
System.out.printf();
Java Comments
Java has three types of comments
- Single line
- Multi line
Java Doc
Single line comment
//This is a single line comment
- Multi line comment
/*This is multi line comment.*/
- Doc comment
/*
* This is java doc comment
*
*/
Comments are skipped by compiler while compiling. That means you can write anything in comment. That would have no effect on you code.
Identifiers
In simple words Identifiers are the name of variables ,methods, class
Note:
Java is case-sensitive language. That means JAVA and java is completely different.
Variables
what are variables?
Suppose we take two input from user. We keep that data in a part of our memory. We can call that particular portion of memory as container. Now suppose we want to use that data in our code. How do we bring that data from memory. To solve this problem we can give a name of that particular memory and we can bring that data calling by that given name. And that particular memory is our variable. Java is a type safe language. That means you have to specify type of data you want to keep in the variable. We will talk about data types later.
Now lets create our first variable...
int num=10;
The type of variable is int
(Integer) it holds only integer value. And the value of the variable is 10 and the name of variable is num
. We assigned 10 in variable num using =
assignment operator.(We will talk about operators later).
So, To declare a variable we need
- data type
- name
And to initialize a variable we need
- assignment operator
=
- value
Now lets print the variable
package blogging.java;
/**
*
* @author Hakim
*/
public class first {
public static void main(String[] args) {
int num=10;
System.out.println(num);
}
}
you should get 10.
That's all for today.
Thank you ❤.
Top comments (0)