OOP (LAB1) Solv
OOP (LAB1) Solv
Lab-01
/*
This is a simple Java program.
Call this file "Example.java".
*/
class Example {
// Your program begins with a call to main().
public static void main(String args[]) {
System.out.println("This is a simple Java program.");
}
}
javac YourJavaFile.java
Question 2: Which command is responsible for the compilation of the java
code?
The command responsible for compiling Java code is javac. The javac
command is part of the Java Development Kit (JDK) and is used to
translate Java source code.
Code:
javac YourJavaFile.java
After compilation, you can run the Java program using the java
command:
Code:
java YourJavaFile
Question 3: What will be the name and the type of the file which will be
created if the following command is executed:
javac MyClass.java
If you execute the command:
Code:
javac MyClass.java
After compilation, you can run the program using the java command:
Code:
java MyClass
Question 4: What will the following line of java code output?
System.out.print(“Pakistan is our country and we are are responsible for it”);
The provided Java code contains a string within double quotes and
is using System.out.print() to output that string. However, there is a
syntax error in the code due to the incorrect use of double quotes.
The quotes in the code snippet are formatted using curly double
quotes (“ ”) instead of straight double quotes (").
Code:
Now, when you run this corrected code, it will output the specified
string:
Code:
Hello, world!
println():
The println() method is used to display text and move the
cursor to the next line.
It appends a newline character ( \n) at the end of the output, so
the next output will start on a new line.
Example:
System.out.println("Hello,");
System.out.println("world!");
Output:
Hello,
world!
THE END