0% found this document useful (0 votes)
65 views10 pages

Harsh Java

The document discusses features of the Java programming language including: - Java is simple, secure, portable, object-oriented, and robust. - Byte code is machine code representation of Java code that allows for platform independence. - Inheritance in Java allows new classes to extend existing classes to inherit their fields and methods. Subclasses can override methods to provide specific behaviors. - DataInputStream and DataOutputStream classes provide methods for reading and writing primitive data types and strings from/to streams in a platform-independent way, such as readBoolean(), writeInt(), etc. - Assertions in Java allow adding validation checks during development and testing by specifying conditions that should be true, throwing AssertionError if not met.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
65 views10 pages

Harsh Java

The document discusses features of the Java programming language including: - Java is simple, secure, portable, object-oriented, and robust. - Byte code is machine code representation of Java code that allows for platform independence. - Inheritance in Java allows new classes to extend existing classes to inherit their fields and methods. Subclasses can override methods to provide specific behaviors. - DataInputStream and DataOutputStream classes provide methods for reading and writing primitive data types and strings from/to streams in a platform-independent way, such as readBoolean(), writeInt(), etc. - Assertions in Java allow adding validation checks during development and testing by specifying conditions that should be true, throwing AssertionError if not met.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 10

PROGRAM BACHELOR of COMPUTER APPLICATION (BCA)

Roll No 2114505854

course CODE & NAME DCA2202 – PROGRAMNING IN JAVA

Name Harsh Agarwal

1) Explain any five features of Java.


B. What is Byte code? Explain in brief.
Features of Java:
The essential goal of Java programming language creation was to make it versatile, basic and
secure programming language. Aside from this, there are likewise a few magnificent
highlights which assume a significant part in the prevalence of this language. The highlights
of Java are otherwise called Java trendy expressions.
o Simple
o Secure
o Portable
o Object-Oriented
o Robust

o Simple:
Java is easy for the professional programmers to learn and use effectively. For an experienced
C++ programmers, learning java will require very little effort because java inherits the C/C++
Syntax and many of the object features of C++. Expressiveness is more in java.
o Secure:
Java forces you to handle expected errors. This ensures that java program are robust, bug free
and do not crash. Due to strong type checking done in java on the user’s machine, any changes
to the program are tagged as error and the program will not excute. Therefore java is secured.
The fact that a java program is interpreted also helps to make it secure.
o Portable:
The key factor that allow java to solve the both security and the portability problem is that
the output of a java compiler is not executable code. Rather, it is byte code. The fact that a
java program is executed by the JVM helps to solve the major problem associated with the
portability over the internet.
o Object Oriented:
Java is an object oriented programming language. All that in Java is an article. Object-Oriented
implies we put together our product as a mix of various sorts of items that consolidate the
two information and conduct.
o Robust:
The English mining of Robust is solid. Java is Robust in light of the fact that: It utilizes solid
memory the board. There is an absence of pointers that evades security issues. Java gives
programmed trash assortment which runs on the Java Virtual Machine to dispose of items
which are not being utilized by a Java application any longer
 Byte code
Java byte code is the guidance set for the Java Virtual Machine. It acts like a constructing agent
which is a nom de plume portrayal of a C++ code. When a java program is incorporated, java
byte code is created. In additional able terms, java byte code is the machine code as a .class
record. With the assistance of java byte code we accomplish stage autonomy in java. Byte
code is basically the machine level language which runs on the Java Virtual Machine.
Whenever a class is stacked, it gets a surge of byte code per strategy for the class. At the point
when that strategy is called during the execution of a program, the byte code for that
technique gets invoked.Javac incorporates the program as well as produces the byte code for
the program.

2) How do you implement inheritance in Java?


Inheritance is an essential idea in object-situated programming, and Java upholds it through
class Inheritance. Inheritance permits you to make another class that is a changed form of a
current class, acquiring its fields and techniques. In Java, you can carry out Inheritance
utilizing the broadens catchphrase. This is the way you can make it happen:

Make a Parent Class (Superclass):


You start by characterizing a class that will act as the parent class (otherwise called the
superclass). This class contains normal ascribes and strategies that you need to reuse in the
kid classes.
java
Duplicate code
public class Creature {
String name;
int age;

public Animal(String name, int age) {


this.name = name;
this.age = age;
}
public void talk() {
System.out.println("Animal speaks!");
}
// Different techniques and qualities intended for Creature class
}
Make Kid Classes (Subclasses):
Then, you can make kid classes (otherwise called subclasses) that acquire from the parent
class. You utilize the stretches out catchphrase to determine the parent class from which the
kid class acquires.
Java
Duplicate code
Public class Canine broadens Creature {
Public Dog (String name, int age) {
Super (name, age); //Call the constructor of the parent class
}

@Abrogate
Public void talk () {
System.out.println("Dog barks!");
}

// Different techniques and qualities intended for Canine class


}

public class Feline expands Creature {


public Cat(String name, int age) {
Super (name, age); //Call the constructor of the parent class
}
@Supersede
Public void talk () {
System.out.println ("Cat meows!");
}
// Different strategies and characteristics intended for Feline class
}
Utilizing Acquired Classes:
You can now make objects of the kid classes and use them. The kid classes acquire the
properties and techniques for the parent class, and you can likewise supersede strategies to
give specific way of behaving.
Java
Duplicate code
Public class Fundamental {
Public static void main (String[] args) {
Canine my Dog = new Dog ("Buddy", 3);
Feline my Cat = new Cat ("Whiskers", 5);

myDog.speak();//This will call the Canine's talk() strategy


myCat.speak (); //This will call the Feline's talk () strategy
}
}
3) What are the different methods under Data Input Stream and Data Output
Stream?
In Java, DataInputStream and DataOutputStream are classes that give techniques to perusing
and composing crude information types (like int, twofold, boolean, and so forth) and strings
in a versatile way. These classes are essential for the java.io bundle and are commonly utilized
for parallel I/O activities. Here are a portion of the normally utilized strategies given by
DataInputStream and DataOutputStream:
DataInputStream Strategies:
 ReadBoolean (): Peruses a Boolean worth from the info stream.
 ReadByte (): Peruses a byte from the info stream.
 readChar (): Peruses a person from the information stream.
 ReadShort (): Peruses a short number from the info stream.
 ReadInt (): Peruses a number from the info stream.
 ReadLong (): Peruses a long number from the info stream.
 ReadFloat (): Peruses a drifting point number from the info stream.
 ReadDouble (): Peruses a twofold accuracy drifting point number from the info stream.
 ReadUTF (): Peruses an UTF-8 encoded string from the info stream.
Java DataOutputStream class techniques
 Int size ():
It is utilized to return the quantity of bytes kept in touch with the information yield stream.
 Void write (int b):
it is utilized to compose the predefined byte to the fundamental result stream.
 Void write (byte [] b, int off, int len):
It is utilized to compose len bytes of information to the result stream.
 Void writeBoolean (Boolean v):
it is utilized to compose Boolean to the result stream as a 1-byte esteem.
 Void writeChar (int v):
It is utilized to compose singe to the result stream as a 2-byte esteem.
 Void writeChars (String s):
It is utilized to compose string to the result stream as a grouping of characters.
 Void writeByte (int v):
It is utilized to compose a byte to the result stream as a 1-byte esteem.
 Void writeBytes (String s):
It is utilized to compose string to the result stream as a succession of bytes.
 Void writeInt (int v)
It is utilized to compose an int to the result stream
 Void writeShort (int v):
It is utilized to compose a short to the result stream.

4) a. How to use assertion in Java?


In Java, statements are a method for adding second looks just in case to your code during
improvement and testing. They permit you to determine conditions that should be valid at
explicit places in your program, and in the event that these circumstances are not met, an
AssertionError is tossed. Assertions are normally used to find programming blunders right off
the bat in the improvement cycle.
To involve statements in Java, follow these means:
 Enable Assertion:
As a matter of course, statements are impaired at runtime. To empower them, you want to
run your Java program with the - ea. (or - enableassertions) order line choice. You can
empower declarations for your whole program or explicit bundles and classes. This is the way
to empower declarations:
 For the whole program:
Java - ea YourMainClass
 For explicit bundles:
Java - ea: com.example.YourPackage YourMainClass
 For a particular class:
Java - ea: com.example.YourPackage.YourClass YourMainClass

 Compose Assertion:
You can compose declarations utilizing the state catchphrase followed by a Boolean
articulation. In the event that the articulation assesses to misleading, an AssertionError is
tossed. Here is the essential sentence structure:
Java
State booleanExpression;
For instance:
Java
Int age = 25;
Declare age >= 18: "Age should be something like 18";
In this model, in the event that age is under 18, an AssertionError with the predefined
message will be tossed.
 Assemble with Assertion Backing:
Guarantee that your Java source code is gathered with declaration support. This implies
utilizing the - source and - target banners while incorporating your code. For instance:
‘Java - source 1.7 - target 1.7 YourSourceFile.java’
 Run the Program:
Execute your Java program with statement support empowered, as referenced in sync 1.
Taking care of AssertionError:
You can get AssertionError special cases to deal with them smoothly in your code. Be that as
it may, it's more considered normal to allow them to spread during advancement and testing
to distinguish issues rapidly. Underway code, Assertions are normally incapacitated, so these
exemptions will not be tossed.
This is an illustration of the way declarations may be utilized in a Java program:
Java
Duplicate code
Public class AssertionExample {
Public static void main (String [] args) {
Int x = 5;
State x > 0: "x should be more prominent than 0";

System.out.println ("Program go on after assertion.");


}
}
b. What is Autoboxing and Unboxing in Java?
In Java, crude information types are dealt with contrastingly so do there comes the
presentation of covering classes where two parts assume a part specifically Autoboxing and
Unboxing. Autoboxing alludes to the transformation of a crude worth into an object of the
relating covering class is called autoboxing. For instance, changing over int to Whole number
class. The Java compiler applies autoboxing when a crude worth is passed as a boundary to a
strategy that expects an object of the relating covering class. Relegated to a variable of the
comparing covering class.
Unboxing then again alludes to changing over an object of a covering type to its comparing
crude worth. For instance transformation of Whole number to int. The Java compiler applies
to unpack when an object of a covering class is passed as a boundary to a strategy that
anticipates a worth of the relating crude sort. Relegated to a variable of the comparing crude
sort.

5) Draw and explain the JDBC Application Architecture?


JAVA

JDBC API

JDBC DRIVER
Management

JDBC DRIVERS

MySQL Any Other


Oracle
data source

JDBC (Java Data set Network) is a Java-based Programming interface that permits Java
applications to cooperate with social data sets. It gives a standard point of interaction to
interfacing with information bases, executing SQL inquiries, and handling the outcomes. The
JDBC application design comprises of a few key parts, each with its particular job. Underneath,
I'll draw and make sense of the JDBC application engineering:
Java Application: This is the high level part of the design, addressing your Java program. It
very well may be an independent application, a web application, or some other sort of Java
application that necessities to communicate with a data set.
JDBC Programming interface: The JDBC Programming interface is a bunch of Java classes and
connection points furnished by Java to collaborate with data sets. It's essential for the Java
Standard Library, so you don't have to introduce any extra libraries to utilize it.
JDBC Drivers: JDBC drivers are stage explicit executions that go about as an extension
between the Java application and the data set. Every data set seller commonly gives its JDBC
driver, and you really want to remember the proper driver for your undertaking to associate
with that particular information base.
JDBC DriverManager: The DriverManager is a class in the JDBC Programming interface
answerable for dealing with a rundown of data set drivers. It keeps a data set association pool
and helps in laying out an association with the data set utilizing a URL. You utilize the
DriverManager to get an association with the information base.
Data set Association: An information base association is a meeting with the data set server.
It permits you to send SQL inquiries to the information base and recover results. You ordinarily
make an association utilizing the DriverManager and give the vital association subtleties like
the URL, username, and secret phrase.
SQL Proclamations: SQL explanations are utilized to connect with the information base. You
can make SQL articulations for errands like questioning information, embedding records,
refreshing records, or erasing records from the data set.
ResultSet: When you execute a SELECT question, the information base returns a ResultSet
object, which addresses the outcome set of the inquiry. You can repeat through the ResultSet
to recover information from the data set.
PreparedStatement: PreparedStatement is a sub interface of Proclamation in JDBC that
permits you to execute precompiled SQL questions with placeholders for boundaries. It is
more effective and secure than ordinary Proclamations as it forestalls SQL infusion.
CallableStatement: CallableStatement is another sub interface of Articulation that is utilized
to execute information base put away techniques.

6) What are the important steps required to create a JavaFX FXML Application
Making a JavaFX application utilizing FXML includes a few significant stages. FXML is a XML-
based language that is utilized to characterize the UI of JavaFX applications. Here are the
vital stages to make a JavaFX FXML application:
Set Up Your Advancement Climate:
 Introduce Java: Ensure you have Java Advancement Pack (JDK) introduced on your
framework.
 Introduce an Incorporated Improvement Climate (IDE) like Overshadowing, IntelliJ
Thought, or NetBeans, which gives instruments and backing to JavaFX advancement.
Make Another JavaFX Undertaking:
 Make another JavaFX project in your IDE or set up another Java venture and add the
JavaFX library to it.
Plan the UI:
 Use Scene Developer: Scene Manufacturer is a visual format instrument that makes
it simpler to plan the UI of your JavaFX application utilizing FXML. You can move UI
components onto the scene and organize them depending on the situation.
 Physically Compose FXML: On the other hand, you can physically compose the FXML
code to depict your application's UI utilizing a word processor or your IDE's FXML
supervisor.
Characterize the Regulator Class:
 Make a Java class that will act as the regulator for your FXML document. This class
ought to broaden ‘javafx.fxml.Initializable’ and carry out the instate strategy.
Associate FXML and Regulator:
 In your FXML record, determine the regulator class by adding a ‘FX: controller’ trait
to the root component and giving the completely qualified name of your regulator
class.
 Use ‘fx:id’ qualities to give each UI component in your FXML document a remarkable
identifier that can be utilized to reference them in your regulator class.
Execute Regulator Rationale:
 In your regulator class, characterize techniques that will deal with occasions and
rationale related with the UI components.
 Utilize the @FXML comment to check fields and techniques that should be infused
from the FXML document.
 For instance, on the off chance that you have a button in your FXML record, you can
characterize a @FXML-clarified technique to deal with the button click occasion.
Load FXML in Your Application:
 In your Java application code, you want to stack the FXML record and set it as the
base of a ‘javafx.scene.Scene object’.
 Make an example of ‘javafx.fxml.FXMLLoader’ to stack the FXML document and
recover the root hub.
Send off the JavaFX Application:
 In your fundamental application class, make a ‘javafx.application.Application’
subclass and supersede the beginning strategy.
 In the beginning technique, make a ‘javafx.stage.Stage’ and set everything up you
made in the past step as the stage's scene.
 At last, call the ‘stage.show’ strategy to show the application window.
Fabricate and Run:
 Fabricate your JavaFX application and run it. You ought to see the UI made in your
FXML record, and it ought to answer client collaborations as characterized in your
regulator class.
Test and Investigate:
 Test your application completely and investigate any issues that might emerge
during improvement.

You might also like