GTU OOP Program - 1

1. Write a program that displays Welcome to Java, Learning Java is fun.

//program that every developer loves to execute
class Practical_01 {
    public static void main(String args[]) {
        System.out.println("Welcome to Java, Learning Java is fun.");
    }
}
Output
cse gtu, gtu study material for computer engineering students gujarat technological university oop lab manual solution

When you compile and run your program you will get the output as 

Welcome to Java, Learning Java is fun.
//program that every developer loves to execute

This is a comment. Like most other programming language java also allows us to write comment which will not be executed while running the program.

Java supports three types of comments single line comment, multiline comments and documentation comment. Above comment is single line comment.

class Practical_01 {

Here,
➡ class is a keyword which declares the new class.
➡ Practical_01 is the name of class which is also known as identifier.
➡ The entire class definition, including all of its members, will be between the curly braces {}.

public static void main(String args[]){

This is the line at which the program will begin executing

All java applications begin execution by calling main()

The public keyword is an access specifier, which allows the programmer to control the visibility of class member.
➡ class preceded by public keyword can by accessed by the code outside the class in which it is declared.

The keyword static indicates that the particular member belongs to a type itself, rather than to an instance of that type.
➡ Means only one instance of main() is created which is shared across all instances of the class.

The void keyword tells the compiler that main() does not return any value.

main() is the method called when a Java application begins.

String args[] declares a parameter named args, which is an array of instance of the class String. args receives any command-line arguments present when the program is executed.

System.out.println("Welcome to Java, Learning Java is fun.");

this line outputs the string "Welcome to Java, Learning Java is fun." followed by a new line on the screen.

In System.out System is predefined class that provides access to the system, and out is the output stream that is connected to the console.

println()displays the string which is passed to it. It can also be used to display other types of information too on the output console.

println() statment ends with a semicolon. All statements in java ends with a semicolon. The above program only has one statement. 

A block of code is written inside curly braces {}.



Comments

YouTube

Popular posts from this blog

GTU OOP Programs - 11

Mini project ideas for Operating System

GTU OS Program - 9