Some question regarding java core
Question 1. Explain Scoping Rules in Java Programming.
Answer Scope: the region of program text in
which a binding holds.
It has some rule which is…
• Static binding is prevalent in most modern PLs (Programming Language Concepts)
• New scope in each function.
• Activate bindings for parameters and locals.
• Deactivate bindings of global obscured by locals.
• Deactivate bindings upon function return.
Question 2. Explains in brief Casting in Java
Programming.
Answer It is sometimes necessary to convert
a data item of one type to another type. Conversion of data from one type to
another type is known as type casting. In java one object reference can be type
cast into another object reference. This casting may be of its own type or to
one of its subclass or superclass types or interfaces. Some compile time or
runtime type casting rules are there in java.
Java performs automatic type conversion and supports two types of casting…
• Upcasting
• Downcasting
Upcasting
Casting a reference with the class hierarchy in a direction from the sub classes
towards the root then this type of casting is termed as upcasting. Upcasting
does not require a cast operator.
DownCasting
On the other hand, casting a reference with hierarchal class order in a
direction from the root class towards the children or subclasses, then it is
known as down casting.
* Automatic type casting does work in case of narrowing i.e. when a data type
requiring more storage is converted into a data type that requires less storage
Question 3. What is concept behind Object-Oriented
Programming?
Answer OOPs use three basic concepts as the
fundamentals for the programming language: classes, objects and methods.
Additionally, Inheritance, Abstraction, Polymorphism, Event Handling and
Encapsulation are also significant concepts within object-oriented programming
languages.
Question 4. Explain in detail Methods, and Object
Interaction.
Answer A Method provides information about,
and access to, a single method on a class or interface. The reflected method may
be a class method or an instance method (including an abstract method). A Method
permits widening conversions to occur when matching the actual parameters to
invoke with the underlying method's formal parameters, but it throws an
IllegalArgumentException if a narrowing conversion would occur.
More generally, method declarations have six components, in order:
• Modifiers—such as public, private, and others you will learn about later.
• The return type—the data type of the value returned by the method or void if
the method does not return a value.
• The method name—the rules for field names apply to method names as well, but
the convention is a little different.
• The parameter list in parenthesis—a comma-delimited list of input parameters,
preceded by their data types, enclosed by parentheses, (). If there are no
parameters, you must use empty parentheses.
• An exception list-use in Core Java.
• The method body, enclosed between braces—the method's code, including the
declaration of local variables, goes here.
Object interaction patterns may be used to define a thread concept, placed in
two broad categories, differing with respect to the roles played by the
participants:
• An event producer object and one or more event consumer objects
Producer-consumer interaction involves only unidirectional (``one-way'')
communication. Examples include a user selecting a menu item, a buyer sending a
purchase order to a supplier, and a report generator sending a report to a
printer. An event may have multiple consumers.
• A client object and a server object.
Client-server interaction involves bidirectional synchronized communication. A
client requests that an operation be performed by a server, and waits for a
reply. Both the request and the reply may contain other transmitted data. This
pattern is seen in common service'' procedure or function invocations.
Tolal:0 Click:
Show All Comments