0% found this document useful (0 votes)
10 views7 pages

Java Programming Basics Explained

Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views7 pages

Java Programming Basics Explained

Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

NITCODE ACADEMY

“JAVA”

Network Information Security By Prof. Golandaj Sir’s ( NITCODE Academy, contact us:
+91- 8180959594, and download APP NITCODE Academy)
What is Java

Java is a class-based high-level object oriented programming language


developed by “James Gosling and his friends in 1991 by Sun Microsystems

Java follows the principle Write Once, Run Anywhere (WORA), which means a
Java program can run on any operating system having a Java Virtual Machine
(JVM).

Java programs are first compiled into bytecode, and then the JVM converts this
bytecode into machine code. Java is secure, robust and widely used for desktop,
web and Android applications.

Java 1.0 (1996) Java 1.0 was the first official version of Java. It introduced
the basic concepts of class, object and JVM.

Syntax:

Class class_name

​ public static void main(String argos[])

[Link](“ “);

NIS By Prof. Golandaj Sir’s ( NITCODE Academy, contact us: +91- 8180959594, and download APP NITCODE Academy)

2
1️⃣ Class Declaration

●​ Every Java program must contain at least one class.​

●​ The class keyword is used to declare a class.​

●​ The class name should start with a capital letter.​

2️⃣ Curly Braces { }

●​ Curly braces define the beginning and end of a class or method.

3️⃣ public Keyword

●​ public is an access modifier.​

●​ It allows the JVM to access the main method from anywhere.

4️⃣ static Keyword

●​ static means the method can be called without creating an object.​

●​ JVM calls the main method directly using the class name.

NIS By Prof. Golandaj Sir’s ( NITCODE Academy, contact us: +91- 8180959594, and download APP NITCODE Academy)

3
5️⃣ void Keyword

●​ void specifies that the method does not return any value.​

●​ The main method always has void return type.

6️⃣ main() Method

●​ main() is the entry point of a Java program.​

●​ Program execution starts from the main method.​

7️⃣ String[] args

●​ It is used to store command-line arguments.​

●​ args is an array of String objects.

8️⃣ Statements

●​ Statements are instructions written inside the main method.​

●​ Every statement must end with a semicolon (;).

🔹 Output Statement (Very Important)


NIS By Prof. Golandaj Sir’s ( NITCODE Academy, contact us: +91- 8180959594, and download APP NITCODE Academy)

4
[Link]("Hello Java");

●​ System is a predefined class.​

●​ out is an output stream object.​

●​ println() prints output and moves to a new line.

Note : Rules of Java Syntax

●​ Java is a case-sensitive language.​

●​ The file name must match the class name.​

●​ Each statement ends with a semicolon (;).​

●​ Execution always starts from the main method.

🔹 Example 1: Simple Java Program (Hello World)


// Basic Code

class Hello {

public static void main(String[] args) {

[Link]("Hello Java");

NIS By Prof. Golandaj Sir’s ( NITCODE Academy, contact us: +91- 8180959594, and download APP NITCODE Academy)

5
🔹 Example 2: Addition of Two Numbers
class Add

public static void main(String[] args) {

int a = 10;

int b = 20;

int sum = a + b;

[Link]("Sum = " + sum);

Explanation:

●​ int a, b are integer variables.​

●​ sum = a + b performs addition.​

●​ Output is displayed using [Link]().

🔹 What is a Command Line Argument?


Command-line arguments are values passed to a Java program at the time of
execution.​
They are received through the parameter String[] args of the main()
method.
NIS By Prof. Golandaj Sir’s ( NITCODE Academy, contact us: +91- 8180959594, and download APP NITCODE Academy)

6
🔹 Example 1: Display Command Line Argument
Java Code

class CommandLineExample {

public static void main(String[] args) {

[Link]("First Argument: " + args[0]);

NIS By Prof. Golandaj Sir’s ( NITCODE Academy, contact us: +91- 8180959594, and download APP NITCODE Academy)

You might also like