Written by students who passed Immediately available after payment Read online or as PDF Wrong document? Swap it for free 4.6 TrustPilot
logo-home
Exam (elaborations)

Important question of java

Rating
-
Sold
-
Pages
8
Grade
A+
Uploaded on
31-05-2024
Written in
2023/2024

In this file you will get important questions of java programming , With the help of these notes you will be able to work with java programming.

Institution
Course

Content preview

Java introduction:- Java is a class-based, object-oriented programming language that is designed to have as few implementation
dependencies as possible. It is intended to let application developers write once, and run anywhere (WORA), meaning that
compiled Java code can run on all platforms that support Java without the need for recompilation. Java was first released in 1995
and is widely used for developing applications for desktop, web, and mobile devices. Java is known for its simplicity, robustness,
and security features, making it a popular choice for enterprise-level applications.
JAVA was developed by James Gosling at Sun Microsystems Inc in the year 1995 and later acquired by Oracle Corporation. It is a
simple programming language. Java makes writing, compiling, and debugging programming easy. It helps to create reusable code
and modular programs. Java is a class-based, object-oriented programming language and is designed to have as few
implementation dependencies as possible. A general-purpose programming language made for developers to write once run
anywhere that is compiled Java code can run on all platforms that support Java. Java applications are compiled to byte code that
can run on any Java Virtual Machine. The syntax of Java is similar to c/c++.
Implementation of a Java application program involves a following step. They include:
1. Creating the program
2. Compiling the program
3. Running the program• Creating Program
We can create a program using Text Editor (Notepad) or IDE (NetBeans)
class Test
{
public static void main(String []args)
{
System.out.println(“My First Java Program.”);
}
};
File -> Save -> d:\Test.java

• Compiling the program
To compile the program, we must run the Java compiler (javac), with the name of the source file on “command prompt” like as
follows
If everything is OK, the “javac” compiler creates a file called “Test.class” containing byte code of the program.
• Running the program
We need to use the Java Interpreter to run a program.
Primary/Main Features of Java
1. Platform Independent: Compiler converts source code to bytecode and then the JVM executes the bytecode generated by the
compiler. This bytecode can run on any platform be it Windows, Linux, or macOS which means if we compile a program on
Windows, then we can run it on Linux and vice versa.
2. Object-Oriented Programming Language: Organizing the program in the terms of a collection of objects is a way of object-
oriented programming, each of which represents an instance of the class.
The four main concepts of Object-Oriented programming are:
 Abstraction
 Encapsulation
 Inheritance
 Polymorphism
3. Simple: Java is one of the simple languages as it does not have complex features like pointers, operator overloading, multiple
inheritances, and Explicit memory allocation.
4. Robust: Java language is robust which means reliable. It is developed in such a way that it puts a lot of effort into checking
errors as early as possible, that is why the java compiler is able to detect even those errors that are not easy to detect by another
programming language. The main features of java that make it robust are garbage collection, Exception Handling, and memory
allocation.
5. Secure: In java, we don’t have pointers, so we cannot access out-of-bound arrays i.e it shows ArrayIndexOutOfBound
Exception if we try to do so.

6. Distributed: We can create distributed applications using the java programming language. Remote Method Invocation and
Enterprise Java Beans are used for creating distributed applications in java. 7. Multithreading: Java supports multithreading. It is
a Java feature that allows concurrent execution of two or more parts of a program for maximum utilization of the CPU.
8. Portable: As we know, java code written on one machine can be run on another machine.
9.Write Once Run Anywhere: As discussed above java application generates a ‘.class’ file that corresponds to our
applications(program) but contains code in binary format.

, Inheritance in Java:- Inheritance in Java is a mechanism in which one object acquires all the properties and behaviors of a parent object. It is an important part
of OOPs (Object Oriented programming system).The idea behind inheritance in Java is that you can create new classes that are built upon existing classes. When
you inherit from an existing class, you can reuse methods and fields of the parent class. Moreover, you can add new methods and fields in your current class
also.Inheritance represents the IS-A relationship which is also known as a parent-child relationship. Terms used in Inheritance

o Class: A class is a group of objects which have common properties. It is a template or blueprint from which objects are created.

o Sub Class/Child Class: Subclass is a class which inherits the other class. It is also called a derived class, extended class, or child class.

o Super Class/Parent Class: Superclass is the class from where a subclass inherits the features. It is also called a base class or a parent class.

o Reusability: As the name specifies, reusability is a mechanism which facilitates you to reuse the fields and methods of the existing class when you create a

new class. You can use the same fields and methods already defined in the previous class.



Syntax:- class Subclass-name extends Superclass-name

{

//methods and fields }


 Types of inheritance in java


Single Inheritance Example

When a class inherits another class, it is known as a single inheritance. In the example given below, Dog class inherits the Animal class, so there is the single
inheritance.

class Animal{

void eat(){System.out.println("eating...");}

}

class Dog extends Animal{

void bark(){System.out.println("barking...");} }



class TestInheritance{

public static void main(String args[]){

Dog d=new Dog();

d.bark();

d.eat();

}}


Multilevel Inheritance Example

When there is a chain of inheritance, it is known as multilevel inheritance. As you can see in the example given below, BabyDog class inherits the Dog class which
again inherits the Animal class, so there is a multilevel inheritance.

class Animal{

void eat(){System.out.println("eating...");} }

class Dog extends Animal{

Written for

Institution
Course

Document information

Uploaded on
May 31, 2024
Number of pages
8
Written in
2023/2024
Type
Exam (elaborations)
Contains
Questions & answers

Subjects

$9.99
Get access to the full document:

Wrong document? Swap it for free Within 14 days of purchase and before downloading, you can choose a different document. You can simply spend the amount again.
Written by students who passed
Immediately available after payment
Read online or as PDF

Get to know the seller
Seller avatar
vinitadahiya2712

Get to know the seller

Seller avatar
vinitadahiya2712 baba mastnath university
Follow You need to be logged in order to follow users or courses
Sold
-
Member since
1 year
Number of followers
0
Documents
2
Last sold
-

0.0

0 reviews

5
0
4
0
3
0
2
0
1
0

Recently viewed by you

Why students choose Stuvia

Created by fellow students, verified by reviews

Quality you can trust: written by students who passed their tests and reviewed by others who've used these notes.

Didn't get what you expected? Choose another document

No worries! You can instantly pick a different document that better fits what you're looking for.

Pay as you like, start learning right away

No subscription, no commitments. Pay the way you're used to via credit card and download your PDF document instantly.

Student with book image

“Bought, downloaded, and aced it. It really can be that simple.”

Alisha Student

Working on your references?

Create accurate citations in APA, MLA and Harvard with our free citation generator.

Working on your references?

Frequently asked questions