0% found this document useful (0 votes)
5 views4 pages

Java Basic Concepts and Program1

Uploaded by

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

Java Basic Concepts and Program1

Uploaded by

amit.cs
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

Java Basic Concepts and Programs

Java program structure-

Documentation Section-
You can write a comment in this section. Comments are beneficial for
the programmer because they help them understand the code. These
are optional.
Example –comment
//addition of two no
Package Statement-
You can create a package with any name. A package is a group of
classes that are defined by a name.
Example-
package student;
import statement-
An import statement is always written after the package statement but
it has to be before any class declaration.
Many predefined classes are stored in packages in Java, an import
statement is used to refer to the classes stored in other packages.
import java.util.Date;
interface statement-
This section is used to specify an interface in Java. It is an optional
section which is mainly used to implement multiple inheritance in
Java. An interface is a lot similar to a class in Java but it contains only
constants and method declarations.
interface stack
{
int x;
void pop();
}
Example-
//this is documentation to understand program
package student; //package
import java.util.*; //import
public class Hello //main class
{
public static void main(String[] args) //main
method
{
System.out.println("Hello Java"); //print
statement
}
}

public static void main-


 When the main method is declared public, it means that it can also be used by
code outside of its class, due to which the main method is declared public.
You should make sure that the class name starts with a capital letter, and the
public word means it is accessible from any other classes.
 The word static used when we want to access a method without creating its
object, as we call the main method, before creating any class objects.
 The word void indicates that a method does not return a value. main() is
declared as void because it does not return a value.
 main is a method; this is a starting point of a Java program.

String[] args-
It is an array where each element of it is a string, which has been
named as "args". If your Java program is run through the console, you
can pass the input parameter, and main() method takes it as input.
System.out.println();-
This statement is used to print text on the screen as output, where the
system is a predefined class, and out is an object of the PrintWriter
class defined in the system. The method println prints the text on the
screen with a new line. You can also use print() method instead of
println() method. All Java statement ends with a semicolon.

Basic programs-
https://www.w3schools.com/java/java_examples.asp
https://www.programiz.com/java-programming/examples
https://www.javatpoint.com/java-programs
https://javatutoring.com/java-programs/

You might also like