Page 139 - Computer science 868 Class 12
P. 139
public static void main(String[] args)
{
// Output
System.out.println(“Hello, World! This is a basic output example.”);
}
}
//OUTPUT
Hello, World! This is a basic output example.
You can use various other classes for more sophisticated output, such as PrintWriter for writing formatted text to an
output stream.
Here’s an example using PrintWriter:
import java.io.PrintWriter;
public class PrintWriterExample {
public static void main(String[] args) {
// Output
try {
PrintWriter writer = new PrintWriter(System.out);
writer.println(“Hello, World! This is a PrintWriter example.”);
writer.close();
} catch (Exception e) {
e.printStackTrace();
}
}
}
//OUTPUT
Hello, World! This is a PrintWriter example.
Note: Make sure to handle any exceptions that might be thrown while working with I/O operations.
Let’s Revisit
♦ Procedural Programming follows the top-down approach.
♦ Object-Oriented Programming follows the bottom-up approach.
♦ An object is a unique entity that contains properties, methods and events together in an Object-Oriented Programming
Language.
♦ The classes in Java are non-primitive/user-defined data types that act as a blueprint for creating objects of the same type.
♦ Class is a factory of objects.
♦ Object is an instance of a class.
♦ Class is a user–defined data type.
♦ A superclass is a class from where features are inherited to another class. It is also known as the base class or the parent class.
♦ A subclass is a class that inherits the features of another class. It is also called the derived class or the extended class or the
child class.
♦ Java uses the principle of WORA , i.e., Write Once, Run Anywhere.
♦ Java is a platform-independent programming language.
♦ Libraries in Java consist of different built-in methods which help the programmer to write the code.
♦ Reserved words of Java are known as keywords.
♦ Comments are the statements in the program code which are non-executable.
137
Programming in Java 137

