DEV Community

Cover image for Java Programming part 2
Sadiul Hakim
Sadiul Hakim

Posted on

Java Programming part 2

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;
Enter fullscreen mode Exit fullscreen mode

Printing on console

To print on console we use this code

System.out.println();
Enter fullscreen mode Exit fullscreen mode

out has some other methods. Some of them are

System.out.print();
System.out.printf();
Enter fullscreen mode Exit fullscreen mode

Java Comments

Java has three types of comments

  1. Single line
  2. Multi line
  3. Java Doc

  4. Single line comment

//This is a single line comment
Enter fullscreen mode Exit fullscreen mode
  1. Multi line comment
/*This is multi line comment.*/
Enter fullscreen mode Exit fullscreen mode
  1. Doc comment
/*
* This is java doc comment
*
*/
Enter fullscreen mode Exit fullscreen mode

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;
Enter fullscreen mode Exit fullscreen mode

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

  1. data type
  2. name

And to initialize a variable we need

  1. assignment operator =
  2. 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);
    }
}

Enter fullscreen mode Exit fullscreen mode

you should get 10.

That's all for today.

Thank you ❤.

Top comments (0)