0% found this document useful (0 votes)
19 views36 pages

Krishna Report

I feel glad to inform you that it is a internship report on Core JAVA. i have covered all the necessary concepts here to make you comfortable about knowing all the basic concepts about so. Enjoy it...!
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)
19 views36 pages

Krishna Report

I feel glad to inform you that it is a internship report on Core JAVA. i have covered all the necessary concepts here to make you comfortable about knowing all the basic concepts about so. Enjoy it...!
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/ 36

A

Training Seminar Report on

CORE JAVA
Submitted
In partial fulfillment
For award of degree of
Bachelor of Technology
In Department of COMPUTER SCIENCE ENGINEERING

SESSION: 2022-2026

Submitted to: Submitted by:


Miss. Heena Bano Krishna
Mahawar
Asst. Prof. (CSE) 22ECACS018
3rd SEM. (CSE)

Department of Computer Science & Engineering Chartered


Institute of Technology, Abu Road
An Initiative by Gyan Raman Charitable Trust
[Approved by AICTE and Affiliated by Bikaner Technical University, Bikaner]
CHARTERED INSTITUE OF TECHNOLOGY, ABUROAD
SESSION 2022-2023

CERTIFICATE
This is to certify that the work which is begin presented in the B.Tech seminar report entitled
“CORE JAVA” has been submitted on the Chartered Institute of Technology, Aburoad
fulfilment of the requirement for the award of degree of Bachelor of technology in Computer
Science & Engineering.

Miss Heena Bano Date:05/12/2023


(Seminar Supervisor)

HOD PRINCIPAL
Computer Science & Engineering Department Chartered Institute of technology
Chartered Institute of technology Abu Road, Rajasthan

i
DECLARATION
In accordance with the requirements for the degree of Bachelor of Technology in
Computer Science & Engineering, in Faculty of Engineering & technology, I present this
Seminar report is completed under the Supervision of Ms. Heena Bano.
I declare that the work presented in the report is my own work except as acknowledged
in the text and footnotes, and that to my knowledge this material has been submitted
either in whole or in part, for a degree at this university or at any other such Institution.

Date: 05/12/2023 Krishna Mahawar

ii
iii
CONTENTS
TITLE ...................................................................................................................... Page No.
CERTIFICATE ..................................................................................................................... i
DECLARATION ...................................................................................................................ii
CONTENTS ........................................................................................................................ iii
LIST OF FIGURES .............................................................................................................. v
Chapter:1 INTRODUCTION.................................................................................................1
1.1 What is java......................................................................................................1
1.2 Why use java ...................................................................................................1
1.3 Why java is so important today.? ................................................................... 2
Chapter: 2 BUILDING STRONG FOUNDATIONS ........................................................... 3
2.1 Primitive data type ......................................................................................... 3
2.2 Data types and variables in java ..................................................................... 3
2.3 Strings in java ................................................................................................ 3
2.4 Using indexes with strings ............................................................................. 4
Chapter: 3 CONTROL FLOW ............................................................................................. 5
3.1 Mapping out program control flow ................................................................ 5
3.2 Operators in java ............................................................................................ 6
3.3 Decision-making with if in java ..................................................................... 6
3.4 Understanding scope in java .......................................................................... 6
3.5 While loops .................................................................................................... 8
Chapter: 4 DEBUGGING IN JAVA ..................................................................................... 9
4.1 Debugging syntax and logical errors ............................................................. 9
4.2 Debugging with an IDE ................................................................................. 9
Chapter: 5 FUNCTION IN JAVA ........................................................................................ 10
5.1 What are function .......................................................................................... 10
5.2 Return types in java ....................................................................................... 10
5.3 Using built-in functions in java...................................................................... 10
Chapter: 6 CLASSES IN JAVA ......................................................................................... 12
6.1 Classes in java ............................................................................................. 12
6.2 Constructors in java ...................................................................................... 13

iv
6.3 Instance methods vs. class methods ............................................................... 14
6.4 Class variable in java................................................................................... 15
6.5 Review: Classes vs. instance ...................................................................... 15
PROJECT
CONCLUSION
REFERENCES

v
LIST OF FIGURES
Fig. 3.1: Pick number ........................................................................................................... 5
Fig. 3.5: while loop .............................................................................................................. 8
Fig. 3.5: Condition true ......................................................................................................... 8

vi
INTRODUCTION
CHAPTER 1
Java is a popular programming language, created in 1995.
It is owned by Oracle, and more than 3 billion devices run java.
It is used for:
• Mobile applications
• Desktop applications
• Web applications
• Web servers and applications servers
• Game
• Database connection
• And more…
1.1 What is java
• Java is a high level object oriented programming language as well as platform.
• Java was developed by a team led by James Gosling at sun Microsystems and released
in 1995.
• Java runs on a variety of platforms such as Windows, Mac os and the various version of
UNIX.

1.2 Why use java


• Java works on different platforms (Windows, Mac, Linux etc.) • It is one of the most
popular programming language in the world.
• It has a large demand in the current job market.
• It is easy to learn and simple to use.
• It is case sensitive language.
• It is secure, fast and powerful.
• It has a huge community support (tens of millions of developers).

• Java is an object oriented language which gives a clear structure to programs and allows
code to be reused, lowering development costs.

• As Java is close to C++ and C#.


1.3 Why java is so important today…?

1
• The Java platform has attracted more than 6.5 million software developers.
• 1.1 billion desktops run Java.
• 930 million Java Runtime Environment downloads each year.
• 3 billion mobile phones run Java.
• 31 times more Java phones ship every year than Apple and Android combined.

2
BUILDING STRONG FOUNDATIONS

CHAPTER 2
2.1 Primitive data type
Primitive data type:- int, char, double, long, Boolean, byte.

• int:- represents a whole number (for example, number of sibling)


• char:- represents a single letter or symbol (for example, your first initial)
• double:- represents a decimal number (for example, your GPA)
• Boolean:- represents a true or false value (for example, Is a light on or off?)

2.2 Data types and variables in java


• Student’s age will be represented with an int.
• Student’s GPA will be represented with a double.
• Student’s first initial will be represented with a char.
• Student’s last initial will be represented with a char.
• Whether the student has perfect attendance so far will be represented with a
Boolean.

2.3 String in java


• Strings, which are used in Java programming, are a sequence of characters. In the
java programming language, string are objects.
• The Java platform provides the String class to create and manipulate strings.
 String: “speaker”
 String variable: string myFavoriteWord =”speaker”;
 Order of letters matters: “desserts” does not have the same value
as “stressed” because the characters are in a different order.

3
2.4 Using indexes with strings

• The ordering of letters in a string matters.


• Consider the string “bharat”, ’b’ is at index 0, ‘h’ is at index 1, ‘a’ is at index 2, ‘r’
is at index 3, ‘a’ is at index 4, ‘t’ is at index 5.

• Index: 0 1 2 3 4 5
• String: b h a r a t

4
CONTROL FLOW
CHAPTER 3
3.1 Mapping out program control flow
• A program’s control flow is the order in which the program’s instructions or code
statements are executed.
• All of the programs we’ve looked at so far execute one statement after another,
sequentially.
• Here is where explanations or definitions can go; try and keep each built two or three
lines max.
• We can manipulate which line of code is executed with special control flow statements
and conditions.
• A line of code might never be executed, be executed once, or multiple times.
• The conditions determine how many times a given line of code is executed.

Program:
• Let’s map out the control flow of a virtual fortune teller program.
• The user will pick a number.
• Depending on the number picked, the user receives a fortune.

Fig. 3.1: Pick number

5
3.2 Operator in Java
• Relational operators: >, <, ==, >=, <=, !=
• input Num <= 5  less than or equal to 5.
• input Num >=8  greater than or equal to 8.
• input Num == 8  equal to 8.
• input Num != 3  not equal to 3.
3.3Decision-making with if in Java
If statement
• An if statement is a control flow statement, where if the condition is true, it
performs some kind of action.
• Condition: input Num < 5
• Action: print out “Enjoy the good luck a friend brings you”. If (inputtedNum <
5) {
// print out “Enjoy the good luck a friend brings you”
}

If-else statement
• Condition: input Num < 5
• If block action: print out “enjoy the good luck a friend brings you”.
• Else block action: print “your shoe selection … today”.
If (inputtedNum <5) {
// print out “Enjoy the good luck a friend brings you”
} else {
// print out “your shoe selection will make you happy today”
}

3.4 Understanding scope in java


Code visibility
• Only the if block or the else block are executed.
• The if block didn’t know about the code in the else block. • The else block
didn’t know about the code in the if block.

6
• All of this has to do with a topic called scope.
Scope
• The scope of a variable is the part of the program where a piece of code is
accessible or in which it can be used.

• Curly braces create different blocks or regions in java.


• The if block and the else block are separate because they are in different sets
of curly brackets.

Scope with an If-Else Statement

If (inputtedNum<100) { int
favouriteNumber =5;
System.out.println(favoriteNumber);
favouriteNumber = 10;
System.out.println(favoriteNumber);
// In scope (accessible) for favoriteNumber
} else {
// Out of scope (not accessible) for favoriteNumber
}
// Out of scope (not accessible) for favoriteNumber
3.5 While loops
• A loop allows code to be executed repeatedly based on a Boolean condition.
While loop control flow

If true
START Condition
Statements
Checking

If false

7
Fig. 3.5: while loop

“Song on Repeat” with a while loop


• On your smartphone, you’ve probably listened to music and if you find a song you
like, you put the song on repeat.
• When a song is on repeat, it plays over and over again, until you take it off repeat.

If true
Is Current
START print(“playing same song
Song On
Repeat again”);

If false

Print(“playing next song”);

FIG. 3.5: CONDITION TRUE

8
DEBUGGING IN JAVA
CHAPTER 4
4.1 Debugging syntax and logical errors
Debugging
• Debugging involves locating and fixing a program’s errors.
• These errors are often called bugs.
• In this chapter, we’ll look at some debugging strategies.
Debugging with print statement
• Before we can solve errors, we need to understand what our program is doing.
• A print statement is one tool that can often help us locate errors.
• We can use print statements to print the value of a given variable and follow the
control flow of our code.

Syntax Errors
• Syntax errors can cause your program to fail before it is run.
• Your code must be in the right format for a computer to read.
• Some common syntax errors are a misspelled variable or missing semicolon.
4.2 Debugging with an IDE
IDE: The Ultimate Tool
• An IDE helps us compiler and run our Java programs.
• An IDE can also help us debug our Java programs.
• We’ve already seen it detect and reveal syntax errors
Breakpoints
• A breakpoint is an intentional stopping point put into a program for debugging
purposes.
• With a breakpoint, we can temporarily halt a program in order to inspect its
internal state.
• Internal state: variable values, the result of certain lines if code, whether or not
a FUNCTIONS IN JAVA certain line of code is executed.

9
FUNCTIONS IN JAVA
CHAPTER 5
5.1 What is a function
A function is a series of finite steps that accomplish some task.
Example: make a PB&J
• Step 1: Gather Ingredients
• Step 2: Spread peanut butter on the other slice • Step 3: Combine two
slices and place on plate Using a function
• Task: Make a PB&J labeled makePB&JSandwich
• To use a function, we can just use its name or label, such as
makePB&&JSandwich.
• makePB&&JSandwich();
• makePB&&JSandwich();
• makePB&&JSandwich();
Defining and Using functions
• In order to use a function, we must define it first.
• We have to write code that defines the name of the function (for example, task)
as well as all of the steps needed to complete the task.
• Once the task and its steps are defined, we can use the function throughout our
program.

5.2 Return types in Java


Input and Output for Functions
• Gather input from the user: Scanner
• Output to the user: System.out.println();
• Input data into a function: Parameters
• Output data from a function: ???-> Return types
5.3 Using built-in functions in Java
• We’ve been creating our functions from scratch.
• All of the functions we defined are user-defined functions.

10
Built-In Functions
• There are many common functions that developers want to use, but don’t want
to define every time.
• Java has defined some functions for us.
• We can just call a built-in function because it’s already defined.
• System.out.println() is an example of a built-in function.
Operations
• Many of these operations on specific data types are built-in.
• .equals for Strings is built-in.
• “res” .equals(“blue”); Dot Operator
• We use the dot operator to get access to many of these built-in functions.
• System.out.println();
• “red” .equals(“blue”);
• Sometimes we’ll define our own functions and sometimes we’ll use built-in
functions.

Benefit of Using Built-In Functions


• You don’t have to define the function yourself; you can just call it.
• All you have to know is the function’s inputs and output as well as the gist of
what the function does.
• Built-in functions have been well tested so they are guaranteed to do what they
are described to do.

11
CLASSES IN JAVA
CHAPTER 6
6.1 Classes in Java
Classes
• One way to make our programs easier to read is with classes.
• All of the code we’ve written so far was contained in the Main class.
• Everything we see and hear in everyday life can be represented in code.
• Example: “on-repeat” on a music player, restaurant receipt totals.
• How well something is represented is up to us.
• Classes often act as blueprints for these things.
• A class is a user defined blueprint that has a set of attributes and behaviors that
define the item that it is supposed to represent.

• Let’s create a blueprint for a triangle.


• A triangle has a base, height, three sides, etc. Attributes of a Class
• What are the properties of a triangle?
• double base; double height;
• double sideLenOne; double sideLenTwo; double sideLenThree;
• Every triangle has these attributes even though the value of each attribute may
be different.

Behaviors of a Class
• Attributes/properties: base, height, sideLenOne, sideLenTwo, sideLenThree.
• Behaviors: functions that are related to (and located inside) the class.
• The findArea() function can use the base and height attributes to calculate the
area of the triangle.
• We can organize our code by adding this function as a behavior to our Triangle
class.
• Attributes/properties: base, height, sideLenOne, sideLenTwo, sideLenThree.
• Behaviors/methods: findArea(), calculateTriangleType().
• The calculateTriangleType() function can use the side lengths to decide the
triangle is equilateral, isosceles, or scalene.

12
• There are a bunch of different ways you can represent a triangle in a program;
this is just one way.

• The behaviors we’ve talked about so far use or manipulate attributes of the class.

• Although this is often the case, it doesn’t have to be. • We add the keyword static
if the function does not use the attributes of a class, but still relates to the overall
theme or idea of the class.
6.2 Constructors in Java
How Do We Make Individual Triangles
• We had to define functions before we could call them; we have to define classes
before we can use them.
• Defining a Triangle class does not create any triangles.
• In this video, we are going to learn how to make individual triangle instances in
our program.

What is an Instance?
• An instance is an object created from a class blueprint.
• Just like we make buildings from blueprints, we can use a class to create an
object in code.
• The Triangle class defines base, height, sideLenOne, sideLenTwo, and
sideLenThree as attributes. Triangle Instances
• An instance is an object created from a class blueprint.
• The Triangle class defines base, height, sideLenOne, sideLenTwo, and
sideLenThree as attributes.
• Example Instance One: triangleA: base = 15, height = 8, sideLenOne = 15,
sideLenTwo = 8, sideLenThree = 17.
• Example Instance Two: triangleB: base = 3, height = 2.598, sideLenOne = 3,
sideLenTwo = 3, sideLenThree = 3.

How Do We Create Triangles?


• A constructor is a special method or behavior inside every class that creates and
initializes instances.

13
• We will use a constructor in the Triangle class to construct and initialize Triangle
instances
• In order to create a Triangle instance in our code, we just have to call the
constructor method of the Triangle class.

What Does a Constructor Look Like?


• The constructor may or may not take inputs
• A constructor always returns an instance of the class it’s in (that is, a constructor
in the Triangle class returns a triangle).
Public Triangle () {
}

Creating a Constructor
• A constructor is a special method or behavior inside every class that creates and
initializes instances.

• In constructing a Triangle instance or Triangle object, we’ll want to initialize its


attributes with values.
• We could set these to any default value to each of these attributes, but ideally,
this constructor would be dynamic and on the fly decide what values to give
these attributes.

What Does a Constructor Look Like?


• We can add parameters to give a dynamic value for each attribute.
• The parameter name can be different than the attribute name.
public Triangle (double base, double height, double
sideLenOne, double sideLenTwo, double sideLenThree)
{ }
• To access the attribute for the Triangle instance we are trying to construct, we
use the this keyword and the dot operator. public Triangle ( double base, double
height, double sideLenOne, double sideLenTwo, double sideLenThree ) {

this. base = base;


this.height = height;

14
this.sideLenOne = sideLenOne;
this.sideLenTwo = sideLenTwo;
this.sideLenThree = sideLenThree;

}
• The this keyword helps our program make a distinction between the attribute
variable.
• When used with the this keyword, the dot operator allows us to access the new
Triangle’s attribute variables.

How Do We Use a Constructor?


• We call it like any other function.
• The only difference is that because we are creating a new Triangle instance, we
have to use the new keyword.
Triangle triangleA = new Triangle ( 15, 8, 15, 8, 17 );
Triangle triangleB = new Triangle ( 3, 2.598, 3, 3, 3 );

Creating New Types of Data


• Triangle is now a data type? Yes

• It’s a particular way we’ve decided to store and organize data about a triangle.
Triangle triangleA = new Triangle ( 15, 8, 15, 8, 17 );
Triangle triangleB = new Triangle ( 3, 2.598, 3, 3, 3 );

6.3 Instance Methods vs. Class Methods


Instance Methods
• The implementation of the findArea function in the Triangle class relies on the
attribute values of a given triangle.

• findArea() is an instance method, so we call it with a Triangle instance, for


example, triangleA.findArea();
public double findArea() {
return ( this.base * this.height ) / 2;
}

Static Methods
• we did not need to create an instance of Math to use the pow methods.
15
• Pow() is a static method (also called class methods ) so we call them using the class
name.
int expNum = Math.pow ( 2, 3 );

Instance Methods vs. Class Methods


• Instance methods are also referred to as non-static methods since you need an
instance to use them.
• Class methods are referred to as static methods because you do not need an
instance to use them.

Instance Method or Class Method?


• We used .charAt() method in a previous chapter with a string.
• To access the .charAt, we used dot operator on a String instance ( “Kayla” )
saved in a variable (studentFristName).
• Since we access the method through an instance, .charAt is an instance
(nonstatic) method instead of a class (static) method.
String studentFristName = “kayla”;
Char firstInitial = studentFirstName.charAt(0);

Non-Static vs. Static Variables


• Base and height are non-static instance variables: their values are not the same
for every triangle; their values change depending on the triangle instance.
• Static class variable do not change per instance; they hold a value for the
whole class to use.

6.4 Class Variable in Java


Accessing Static Class Variables
• We access a static class variable using the class name (in this case, Triangle).
• A static variable’s value belongs to the class rather than a particular instance.
Triangle.numOfSides

16
6.5 Review: Classes vs. Instances
Review: Classes
• Classes help organize our code; they contain attributes ( also referred to as
properties) and behavior (also referred to as methods).

• Every class contains a constructor that can create instances.


Instance Variables and Methods
• Some attributes are associated with each individual instance and we call these
instance variables.

• Non-static instance methods access the instance variables in their


implementation.
Triangle triangleA = new Triangle (15, 8, 15, 8, 17);
System.out.println( triangleA.height );
Triangle triangleB = new Triangle(3, 2.598, 3, 3, 3);
System.out.println( triangleB.getArea );

Class Variables and Methods


• Some attributes are associated with the whole class and call these class
variables.
• Static class methods do not need an instance in order to be used; we just use
the class name.
System.out.println( Triangle.numOfSides );
System.out.println( Math.pow ( 5, 8) );
System.out.println( Math.abs (-100) );

17
PROJECT
We can create a Desktop application called “ Temperature Convertor Tool”
using a feature of Java
called “JavaFX”.

• What is JavaFX?
JavaFX is a set of graphics and media packages that enables developers to
design, create, test, debug, and deploy rich client applications that operate
consistently across diverse platforms.

Here, we use three basic files:


1. Main.java : It is used to write Source code for application.
2. Controller.java : It is used to associate different files in app.
3. App_layout.fxml : It is used to give design to app.

• Code in Main.Java :

package com.internshala.javafx;

import javafx.application.Application;
import javafx.application.Platform;
import javafx.fxml.FXMLLoader;
import javafx.scene.Scene;
import javafx.scene.control.Alert;
import javafx.scene.control.ButtonType;
import javafx.scene.control.Menu;
import javafx.scene.control.MenuBar;
import javafx.scene.control.MenuItem;
import javafx.scene.control.SeparatorMenuItem;
import javafx.scene.layout.VBox;
import javafx.stage.Stage;

import java.io.IOException;
import java.util.Optional;

public class Main extends Application {


public static void main(String[] args) {
launch();

18
}

public void init() throws Exception {


super.init();
System.out.println("Init");
}
@Override
public void start(Stage primaryStage) throws IOException {
System.out.println("Start");
FXMLLoader loader = new
FXMLLoader(getClass().getResource("app_layout.fxml"));
VBox rootNode = loader.load();
Scene scene = new Scene(rootNode);
primaryStage.setTitle("Temprature Converter Tool");
primaryStage.setScene(scene);

MenuBar menubar = createMenu();


rootNode.getChildren().add(0,menubar);
primaryStage.show();
}

public static MenuBar createMenu()


{
Menu fileMenu = new Menu("File");
MenuItem newMenuItem= new MenuItem("New");
newMenuItem.setOnAction(event -> System.out.println("New Menu
item clicked."));

SeparatorMenuItem sep =new SeparatorMenuItem();

MenuItem quitMenuItem = new MenuItem("Quit");

quitMenuItem.setOnAction(event -> {
Platform.exit();
System.exit(0);
});
fileMenu.getItems().addAll(newMenuItem,sep,quitMenuItem);

Menu helpMenu = new Menu("Help");


MenuItem aboutApp = new MenuItem("About");

aboutApp.setOnAction(event -> {

19
aboutApp();
});
helpMenu.getItems().addAll(aboutApp);

MenuBar menuBar = new MenuBar();


menuBar.getMenus().addAll(fileMenu,helpMenu);
return menuBar;

}
private static void aboutApp()
{
Alert alertDialog = new Alert(Alert.AlertType.INFORMATION);
alertDialog.setTitle("My First Desktop Application");
alertDialog.setHeaderText("Learning JavaFx");
alertDialog.setContentText("I am a beginner, but soon i will be pro.");

ButtonType yesBtn = new ButtonType("Yes");


ButtonType noBtn = new ButtonType("No");

alertDialog.getButtonTypes().setAll(yesBtn,noBtn);
Optional<ButtonType> clickedBtn = alertDialog.showAndWait();

if(clickedBtn.isPresent() && clickedBtn.get() == yesBtn)


{
System.out.println("YEs Button Clicked !");
}
else
{
System.out.println("No Button Clicked !");
}
}

@Override
public void stop() throws Exception {
super.stop();
System.out.println("Stop");
}
}

• Code in Controller.java :
package com.internshala.javafx;

20
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.*;

import java.net.URL;
import java.util.ResourceBundle;

public class Controller implements Initializable {

@FXML
public Label welcomeLabel;

@FXML
public ChoiceBox<String> choiceBox;

@FXML
public TextField userInputField;

@FXML
public Button convertButton;

private static final String C_TO_F_TEXT = "Celcius to Fehrenhite";


private static final String F_TO_C_TEXT = "Fehrenhite to Celcius";

private boolean isC_TO_F = true;

@Override
public void initialize(URL location, Resource Bundle resources) {

choiceBox.getItems().add(C_TO_F_TEXT);
choiceBox.getItems().add(F_TO_C_TEXT);

21
choiceBox.setValue(C_TO_F_TEXT); //to show the value as default.

choiceBox.getSelectionModel().selectedItemProperty().addListener((obs
ervable, oldValue, newValue) -> {
if(newValue.equals(C_TO_F_TEXT))
{
isC_TO_F = true;
} else{
isC_TO_F = false;
}
});

convertButton.setOnAction(event -> {
convert();
});
}
private void convert()
{
String input = userInputField.getText();
float enteredTemprature = 0.0f;
try{
enteredTemprature = Float.parseFloat(input);
}catch (Exception ex)
{
warnUser();
return;
}

float newTemprature = 0.0f;


if(isC_TO_F)
{
newTemprature = (enteredTemprature * 9/5) +32;

22
} else{
newTemprature = (enteredTemprature - 32) *5 /9;
}
display(newTemprature);
}

private void warnUser() { Alert alert = new


Alert(Alert.AlertType.ERROR);
alert.setTitle("Error occured");
alert.setHeaderText("Invalid Temprature Occured");
alert.setContentText("Please enter a valid temperature ");
alert.show();}

public void display(float newTemprature)


{
String unit = isC_TO_F? "F" : "C";
System.out.println("new temp. is " +newTemprature +unit);
Alert alert = new Alert(Alert.AlertType.INFORMATION);
alert.setTitle("Result");
alert.setContentText("new temp. is " +newTemprature +unit);
alert.show();
}
}

• Code in App_layout.fxml :
<?xml version="1.0" encoding="UTF-8"?>

<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?>
<?import javafx.scene.text.*?>

<VBox maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-


Infinity" minWidth="-Infinity" prefHeight="236.0" prefWidth="298.0"
xmlns="http://javafx.com/javafx/17.0.2-ea"
23
xmlns:fx="http://javafx.com/fxml/1"
fx:controller="com.internshala.javafx.MyController">
<children>
<Pane prefHeight="200.0" prefWidth="200.0">
<children>
<Label fx:id="welcomeLabel" alignment="CENTER"
layoutX="1.0" layoutY="28.0" prefHeight="27.0" prefWidth="298.0"
text="Welcome">
<font>
<Font name="System Bold" size="18.0" />
</font>
</Label>
<ChoiceBox fx:id="choiceBox" layoutX="75.0"
layoutY="69.0" prefWidth="150.0" />
<TextField fx:id="userInputField" layoutX="76.0"
layoutY="100.0" promptText="Enter Temperature" />
<Button fx:id="convertButton" layoutX="91.0"
layoutY="135.0" mnemonicParsing="false" prefHeight="25.0"
prefWidth="118.0" text="Convert" />
</children>
</Pane>
</children>
</VBox>

• Output :

24
Fig. Desktop application of Temperature Convertor Tool

CONCLUSION

25
• One of the most signification advantages of java is its ability to move easily from one
computer system to another.
• Java is platform-independent.
• Java can found everywhere from mobile phones to electronic gadgets.

26
REFERENCE
• Java Tutorial, https://www.tutorialspoint.com/java/index.htm
• Java (programming language) – Wikipedia
https://en.wikipedia.org/wiki/java_(programming_language)
• Java Tutorials, https://www.w3schools.com/java
• Java Tutorials , https://trainings.internshala.computer/java

27
28

You might also like