Core Java
Core Java
#Input stream output stream explanation what is the stream?=== An input stream is a sequence of
data that you read from, while an output stream is a sequence of data that you write to 1. The goal
of these streams is to abstract different ways to input and output, so that whether the stream is a
file, a web page, or the screen shouldn’t matter. All that matters is that you receive information
from the stream (or send information into that stream) 1.
For instance, an InputStream is used for reading from many things such as files, images, audio,
video, web pages, etc2. Similarly, an OutputStream is used for writing data to many things such as
files, images, audio, etc2.
#Byte input stream output stream? === A byte stream is a sequence of bytes that you read from or
write to 1. In Java, a ByteInputStream is used for reading data from a byte array, while
a ByteOutputStream is used for writing data to a byte array
#Try block and catch block? === Try block = In Java, a try block is used to enclose the code that
might throw an exception. It must be used within the method. If an exception occurs at the
particular statement in the try block, the rest of the block code will not execute 1. A try block must
be followed by either a catch or finally block 1.
Catch block =A catch block is used to handle the exception by declaring the type of exception
within the parameter. The declared exception must be the parent class exception (i.e., Exception)
or the generated exception type. However, it is recommended to declare the generated type of
exception 1. The catch block must be used after the try block only
#What is applet? === An applet is a small computer program that performs a specific task. It is
typically embedded within another larger app or software platform and has limited functionality.
This allows applets to run quickly and reliably without demanding a lot of system resources.
#What is construction write a type of construction? === A constructor is a special method in Java
that is invoked automatically at the time of object creation. It is used to initialize the data members
of new objects generally 1. The constructor in Java has the same name as the class or structure 1. It
constructs the values, i.e., provides data for the object, which is why it is known as a constructor
type= 1)Default constructor: A constructor that takes no arguments and initializes all data
members to their default values 1. 2)Parameterized constructor: A constructor that takes
one or more arguments and initializes data members with the given values 1. 3)Copy
constructor: A constructor that creates a new object by copying an existing object of the same
class 1. 4)Private constructor: A constructor that is declared private and can only
be accessed within the class
#Default Constructor === A default constructor is a constructor that can be called with no
arguments. It can either be defined with an empty parameter list or with default arguments
provided for every parameter 1. A type with a public default constructor is Default Constructible .
#Advantages and disadvantages of java?=== Advantages =1)Simple: Java is easy to learn and
understand, with a straightforward syntax 1.
2)Object-oriented: Java is an object-oriented programming language, which makes it more
practical 1. 3)Secure: Java is a secured programming language because it doesn’t use
explicit pointers, and programs run inside the virtual machine sandbox 1.
4)Robust: Java uses strong memory management and provides type checking to make code more
secure 1
2)Memory consumption: Java programs consume more memory since they run on top of the Java
virtual machine 2.
3)Cost: Java programming language is a bit costly due to its higher processing and memory
requirements 2.