Introduction to Java (Part 1) - Your First Java Program

Before we start actual coding, let me introduce you with some basic things of java . This will definitely help you to write your very first code using Java . 

JAVA is an Object Oriented Programming Language . So you need to write your whole java code inside the Class.

You need to pre-install Java on your machine. You can either run your program using command line or by installing any editor like Eclipse or you can simply use online editor like  Onlinegdb

🔸 Create Class in Java : 

Sample Java Class -


You can use any of this Access Specifiers  - 
  • Default
  • Public
  • Private
  • Protected 
FileName and ClassName should be SAME. So I will save this file as 'Main.java' 

🔸 main ( ) Method in Java :

When you compile Java Code, JVM (Java Virtual Machine) search for main() method in your code.So main () method is the starting point of execution of code.

Syntax of main() method is -

Syntax of main () method is FIXED so we must use this snippet as it is in our code.

🔸 Printing Output on Console :

- System.out.print() or System.out.println() methods used to print output on the console.

- System.out.println() method used to print output on new line. 

Example - 


🔸 Import Package :

- Java Package is a group of similar classes , interfaces and sub-packages .

- There are two types of packages - Built In and User Defined .

- Java contain many built-in packages and we can definitely use them to simplify our task by just importing that package in our code.

- Some of the built-in packages are - java, lang, awt, javax, swing, net, io, util, sql etc.

For ex: If you want to read input from console, you can import java.util.Scanner package to use methods like nextInt() to read int , next() to read String ,  nextFloat() to read float etc which are defined in Scanner Class.

IMPORT is the keyword used to import any package in our code.

Sample Code -


In the next post, We will study to take Input in Java.



All the Best 👍👍👍
Happy Learning 😇😇😇 

Post a Comment

Comments :

Previous Post Next Post