You are reading the article How To Create Packages In Java? updated in December 2023 on the website Minhminhbmm.com. We hope that the information we have shared is helpful to you. If you find the content interesting and meaningful, please share it with your friends and continue to follow and support us for the latest updates. Suggested January 2024 How To Create Packages In Java?
Introduction to Java PackagesStart Your Free Software Development Course
Web development, programming languages, Software testing & others
Working of Packages
Directories mirror packages; now, questions are how Java runtime knows where to look for the packages the user has created.
By default, java runtime uses the current work directory as its start point, and your user created a package in a sub-directory to the leading directory; it will be found.
Another way is to specify the directory path by setting the CLASSPATH environment variable.
And the last way is to use the CLASSPATH option with Java and javac to specify the path to the classes.
The java compiler must always be aware of the location of a base directory for locating the classes; for this reason, we need to set environment variables in the system.
If we take an example of two packages awtand java.awt.event, the latter is a sub-package. Hence the directory structure of later shall contain the event directory inside awt, “$BASE_DIRjavaawt” is the address for the parent package, and “$BASE_DIRjavaawtevent” is the address for the sub-package.
Types of Packages
Java offers the flexibility to use built-in Java packages or user-created packages based on the use case.
The built-in packages are always crucial while coding, as they offer a lot; the chúng tôi file carries multiple functionality definitions, which appear in the java.util.* like packages.
Now let us see built-in and user-defined packages in detail –
1. Built-in PackagesBuilt-in packages contain a large number of Java classes, and it contains the following packages –
lang – This package automatically imports and encapsulates the primary classes, including the Object class.
Utilise – this is a crucial package and contains many classes related to collections like ArrayList, HashMap, etc. All the data structure implementations are in this class, and you need to use them by incorporating them abstractly.
This package is where the input-output stream handling and processing-related classes are placed. Some examples of such classes include InputStreamReader, FileReader, and so on.
net – This contains the classes used for performing certain networking-related operations; the example classes are Socket and SocketAddress.
beans – Contains classes related to bean development and components based on Java beans architecture.
2. User-Defined Packages
A user always has the privilege to enclose his created classes into some package; the user can only define that package’s name and directory structure in his custom way.
When a package is not assigned to any class, programmers place it in the default package.
package com.supplychains class SupplyChainManagement { public void getPrompt() { System.out.println(“Welcome to SCM”); } }Other classes can now access this class by simply importing the “com.supplychains” package. Once the package is imported, you can access the class “SupplyChainManagement” and its member functions and variables.
How to Create Packages in Java?First, you should have a class; let us consider only the abovementioned class structure.
package com.supplychains class SupplyChainManagement { public void getPrompt() { System.out.println(“Welcome to SCM”); } }
Now compile this file with a javac compiler, which can be done by writing javac SupplyChainManagement.java; this will create a .class file in the same directory.
Now we can use the command, “javac -d. SupplyChainManagement.java”, this command will result in package formation, now directory structure is a thing we have to be keen about; the “.” placed after -d in the above command represents the current working directory. The program will create a folder in the selected directory, form a package within that folder, and place the class file created in Step 2 within this package.
The next step is to compile the package; this can be done with the following command –
“javac -d .. SupplyChainManagement.java. “.. represents the parent directory (like C drive or D drive).
Hence, you can organize and bundle multiple classes in a directory structure, ensuring you can only access them in the corresponding order.
Now you need to use an import statement to incorporate this package in any Java classes; note that Java runtime will refer to it concerning the path set in the environment variable, which contains the root directory only.
ConclusionHence, we read a little about packages in Java, their creation, their working, and how we can create and import our packages from anywhere to any other classes. Packages can encapsulate the interfaces and classes. A wide variety of built-in packages are already available to exploit the data structure and algorithms; Java provides a wide variety and supports multithreading through multiple concurrency packages.
Recommended ArticlesThis is a guide to Java Packages. Here we discuss the introduction, working, and types of the package, which include built-in and user-defined packages and the creation of packages in Java. You may also look at the following articles to learn more –
You're reading How To Create Packages In Java?
How To Draw A Polygon Using Gui In Java
How to draw a polygon using GUI in Java
Problem DescriptionHow to draw a polygon using GUI?
SolutionFollowing example demonstrates how to draw a polygon by creating Polygon() object. addPoint() & drawPolygon() method is used to draw the Polygon.
import java.awt.*; import java.awt.event.*; import javax.swing.*; public class Main extends JPanel { public void paintComponent(Graphics g) { super.paintComponent(g); Polygon p = new Polygon(); for (int i = 0; i < 5; i++) p.addPoint((int) ( 100 + 50 * Math.cos(i * 2 * chúng tôi / 5)),(int) (100 + 50 * Math.sin( i * 2 * chúng tôi / 5))); g.drawPolygon(p); } public static void main(String[] args) { JFrame frame = new JFrame(); frame.setTitle("Polygon"); frame.setSize(350, 250); frame.addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent e) { System.exit(0); } }); Container contentPane = frame.getContentPane(); contentPane.add(new Main()); frame.setVisible(true); } } ResultThe above code sample will produce the following result.
Polygon is displayed in a frame.The following is an another sample example to draw a polygon using GUI.
import java.awt.Color; import java.awt.Container; import java.awt.Graphics; import java.awt.Polygon; import java.awt.event.WindowAdapter; import java.awt.event.WindowEvent; import javax.swing.JFrame; import javax.swing.JPanel; public class Panel extends JPanel { public void paintComponent(Graphics g) { super.paintComponent(g); Polygon p = new Polygon(); for (int i = 0; i < 5; i++) p.addPoint((int) ( 100 + 50 * Math.cos(i * 2 * chúng tôi / 5)),(int) ( 100 + 50 * Math.sin(i * 2 * chúng tôi / 5))); g.drawPolygon(p); } public static void main(String[] args) { JFrame frame = new JFrame(); frame.getContentPane().setBackground(Color.YELLOW); frame.setTitle("DrawPoly"); frame.setSize(350, 250); frame.addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent e) { System.exit(0); } }); Container contentPane = frame.getContentPane(); contentPane.add(new Panel()); frame.show(); } }The above code sample will produce the following result.
Polygon is displayed in a frame.java_simple_gui.htm
Advertisements
How To Create Custom Gifs In Whatsapp
A GIF, which is an acronym for Graphics Interchange Format, is a lossless format for image files that support both static and animated images. It is called a lossless format because it does not degrade the quality of the image. GIF is an image format meant for sharing on the Internet. GIFs store image data using indexed colour, meaning a standard GIF image can include a maximum of 256 colours. Though they can theoretically store more than 250 colours, such GIFs will have a file size almost same with JPEG and hence they are rarely used.
GIFs are not ideal for storing digital images like those captured using digital or smartphone cameras since GIFs contain a limited number of colours. GIFs are most suitable for web buttons and banners since these typically do not require many colours.
WhatsApp supports GIF and it does have its vast collection of GIFs we can choose from. Most times the GIFs provided by WhatsApp are appropriate to express what we want and hence we do pick from the WhatsApp collection. However, there are unique ideas or expressions we can’t accurately communicate with the WhatsApp inbuilt GIFs. It then becomes necessary to create our custom GIFs. WhatsApp allows its users to create their custom GIFs in the WhatsApp app. The process is simple. It is similar to sending a video to someone, with just a little tweak and WhatsApp converts the video to GIF for you. The two methods explained below are for iPhone, iPad and Android.
Creating custom GIFs in WhatsApp on iPhone Step One:Open the WhatsApp messenger on your iPhone or iPad. It can be found on your home screen or in your App folder.
Step Two:Scroll to the chat you want to send the GIF to. Tap on the chat to open the conversation.
Step Three:Tap on the Attachment icon, which will open the attachment options in a new pop-up. The attachment icon is a “+” icon on the left-hand side of the conversation.
Step Four:Select the Photo and Video Library from the pop-up menu. It will open your phone’s photo and video gallery.
Step Five:Look for the video you want to convert to GIF and tap on it. WhatsApp will open the video in the WhatsApp’s video editor.
Step Six:Tap the GIF button on the top right of the editor. The GIF icon is next to the Video icon beside the video you have uploaded. Note that the GIF icon will look white on a blue background when selected. Once the GIF is selected, the video will automatically turn to GIF.
You can trim the length of the GIF in the timeline. Simply drag the line demarcating the length of the video to your desired length. Note also that GIFs are usually small in size so if the video is large, above 850kb, the GIF icon will disappear, meaning that the size of the video is too large. You can reduce the size of the video by trimming the video in the timeline until the GIF icon appears beneath the timeline. To send the GIF, simply tap the send icon.
Creating Custom GIFs in WhatsApp on Android Step One:Open WhatsApp messenger on your Android phone. You can find WhatsApp on the home screen or in the Apps section. Tap the WhatsApp icon to open it.
Step Two:Scroll to the chat you want to send the GIF to. Tap on the chat to open the conversation
Step Three:Tap on the Attachment icon, which will open the attachment options in a new pop-up. The attachment icon is a paperclip icon on the right-hand side of the text area.
Step Four:Select the Gallery icon from the pop-up menu. It will open your phone’s photo and video gallery.
Step Five:Look for the video you want to convert to GIF and tap on it. WhatsApp will open the video in the WhatsApp’s video editor.
Step Six:
Tap the GIF button on the top right of the editor. The GIF icon is next to the Video icon beside the video you have uploaded. Note that the GIF icon will look white on the light-green background when selected. Once the GIF is selected, the video will automatically turn to GIF.
You can trim the length of the GIF in the timeline. Simply drag the line demarcating the length of the video to your desired length. Note also that GIFs are usually small in size so if the video is large, above 850kb, the GIF icon will disappear, meaning that the size of the video is too large. You can reduce the size of the video by trimming the video in the timeline until the GIF icon appears beneath the timeline. To send the GIF, simply tap the send icon.
How To Create Heat Map In Excel?
Heat Map in Excel
Heat Map in Excel is used to show data in different color patterns. In Heat Map, data is shown in a different color pattern to see which data point is below the limit and which is above the limit. In addition, we can use two or more two colors to see the data pattern.
This helps in judging whether the data target is achieved or not.
Start Your Free Excel Course
Excel functions, formula, charts, formatting creating excel dashboard & others
How to Create a Heat Map in Excel?Let’s understand how to Create a Heat Map in Excel by using some examples.
You can download this Heat Map Excel Template here – Heat Map Excel Template
Example #1Here we got the sales data of some part numbers. Where we have the sales numbers in Columns G and H for two months. Now we want to apply Heat maps to the data shown below.
For that, first, select both columns, G and H. Now go to the Home menu and select Conditional Formatting, as shown below.
Once we do that, we will get a drop-down menu list, as shown below. Now from Color Scales, select any color pattern. We have selected the second option, the Red-Yellow-Green color pattern, as shown below.
Once we do that, we will see the heat pattern for all selected color scales, as shown below. This shows that the value less than 50 is in green color shades. The mid-value, near to 50, is in yellow shades, and the value, near to 100, is in red shades.
Values closer to the limit have dark shades, and the values far from the limit have light shades. Let’s see a small patch of data and measure the different color scale values, as shown below.
So this is how the color scaling can be done for Heat maps in any data. We can choose different color scaling as well as per our color choice.
Example #2
For the selected data set, let’s create a new rule for the heat map. We can create a new rule or go ahead with existing rules. As we can see, in Edit the Rule Description box, a Format Style tab is available with a drop-down button. Select the 3 Color Scale as shown below.
Once we do that, we will see the 3 different color scales with a value range, as shown below. Here, all 3 colors have the default value set in them.
Note: We can change the color from the below color tab and check the preview for the color scaling.
As we can see above, with the help of selected color scaling, we got the Heat Map created, which shows higher the data, the dark will be the red color, and the lower the data, the more light will be the green color. And Midpoint data is also showing the color change concerning the defined or selected value range. Here for the selected Midpoint value 50, data is changing color to and fro.
Pros
For a huge set of data where applying a filter will not give the actual picture of data changes. If we create Heat Map, we can see the change in value without applying the filters.
For the data where we need to see the area (Region, Country, City, etc.) wise changes, in this case, using Heat Map gives high and safe points in the selected color scale.
It is always recommended to use Heat Map when the data size is huge and the data pattern fluctuates at some specific points.
ConsThings to Remember About Heat Map in Excel
Always clear the conditional formatting rule once its use is done. Or else save the rule so that it can be used later.
Choose color scales with Heat pattern that are easy to show and measure.
Measure the range before selecting, and fix the scaling points so that colors and data points can be fixed above and below those values.
Recommended ArticlesThis has been a guide to Heat Map in Excel. Here we discussed How to create Heat Map, practical examples, and a downloadable Excel template. You can also go through our other suggested articles–
Learn How To Create Vaporwave In Photoshop
Introduction to Vaporwave Photoshop
Photoshop is raster image editing software which has different technique through which we can make some old visual effects. Vaporwave is a late 1990s visual effect which was inporatated with glitch art, music videos, and different type of artwork. We can create this effect in present on our image with the help of different features of Photoshop software. In this article, we will learn how we can create vaporwave in this software by using its features and also analyze different parameters of these features. So let us start our discussion about the Vaporwave Photoshop topic in this software.
How to Create Vaporwave in Photoshop?We should follow some simple steps for applying this effect on our image but I think before starting our learning about this topic we should have look at the working screen of this software so that we can better understand this topic throughout this article.
Start Your Free Design Course
3D animation, modelling, simulation, game development & others
At the top, we have a Menu bar that has different menus such as File, Edit, Image, and some others. These menus helps us in the management of different parameters of this software during our working in this software. Below this menu bar, we have a bar of Properties of active tool or image through which we can manage parameters of those tools or images. Below this bar, we have tool panel a left side which has a different type of tool for making our work easy in this software, at the center we have display window in which we can see our work, at the right side we have some panels which helps in the management of different features of this software. You can reset all the sections at a different place as per your choice.
Now press Ctrl + J button for making a copy of this layer.
Now it will look like this.
Choose Red in the Output Channel option of the opened box and make the red value as 0 and blue value as 100.
Choose Blue in the Output Channel option of the opened box.
And make the red value as 100 and blue value as 0.
Now choose the Reds option from the list in Hue/Saturation box.
Decrease the value of Hue of Reds up to -40. You can see the effect on your image.
Decrease the value of Hue of Yellows up to -45. You can see the effect on your image.
Now choose Blues option from the list in Hue/Saturation box.
Decrease the value of Hue of Blues up to -60. You can see the effect on your image.
Now place an image of old television effect in this software. I have downloaded it from the internet.
Adjust the size of this image as it covers your background image like this and press Enter button.
Decrease the opacity of this layer up to 45 %.
Now a dialog box of liquify option will be open. Adjust the size of the brush according to you.
Now choose 50 % Gray option from the list of Fill box and press Ok button of this dialog box.
Set the value of noise up to 70 % in the Add Noise box and press the Ok button of this box.
Choose the Soft Light option from the mode option of this layer.
Decrease the opacity of this layer up to 53 %.
This is the final result of your Vaporwave effect.
ConclusionNow you can understand the Vaporwave effect in Photoshop after this article and can easily use this effect on your image for getting an old visual effect of the 1990s. You can have a good command of it by spending more and more time practicing this feature.
Recommended ArticlesThis is a guide to Vaporwave Photoshop. Here we discuss how to create Vaporwave in Photoshop by using its features and also analyze different parameters of these features. You may also have a look at the following articles to learn more –
How To Find The Surface Area Of Hemisphere In Java?
A hemisphere refers to the exact half of a sphere. Means if we divide a sphere in two equal parts then we will get two hemispheres. Hemisphere is a three-dimensional geometrical shape which has one flat face.
There are many practical examples of hemispheres. The earth divided into 2 equal parts results 2 hemispheres i.e. Northern hemisphere and Southern hemisphere.
The area occupied by the outer surface of a three-dimensional object is called the surface area.
Formula to calculate surface area of hemisphere −
Mathematically it can be represented as
$$mathrm{Surface :Area := :2pi:r^2}$$
$$mathrm{Surface :Area := :2pi:r^2}$$
Mathematically it can be represented as
Volume = 2 * pi * r * rWhere, ‘r’ refers to the radius of the hemisphere
In this article we will see how we can find the surface area of the hemisphere by using Java programming language.
To show you some instances Instance-1Suppose radius(r) of hemisphere is 4.5.
Then by using surface area formula of hemisphere.
surface area = 127.234Hence, the surface area of hemisphere is 127.234
Instance-2Suppose radius(r) of hemisphere is 3.5
Then by using surface area formula of hemisphere
surface area = 76.96Hence, the surface area of hemisphere is 76.96
Instance-3Suppose radius(r) of hemisphere is 5
Then by using surface area formula of hemisphere
surface area = 157.07Hence, the surface area of hemisphere is 157.07
SyntaxIn Java we have a predefined constant in Math class of chúng tôi package i.e. chúng tôi which gives us the pie value which is approximately equal to 3.14159265359.
Following is the syntax for that
Math.PITo get the power of any number raised to the power of another number in Java we have inbuilt java.lang.Math.pow() method.
Following is the syntax to get power of 2 by using the method −
double power = chúng tôi (inputValue,2) Algorithm
Step 1 − Get the radius of the hemisphere either by initialization or by user input.
Step 2 − Find the surface area of the hemisphere by using the surface area formula.
Step 3 − Print the result.
Multiple ApproachesWe have provided the solution in different approaches.
By Using Static Input
By Using User Input
By Using User Defined Method
Let’s see the program along with its output one by one.
Approach-1: By Using Static InputIn this approach, the radius value of the hemisphere will be initialized in the program. Then by using the algorithm we will find the surface area.
Examplepublic
static
void
main
(
String
[
]
args
)
{
double
radius
=
10
;
System
.
out
.
println
(
“Given radius of hemisphere : “
+
radius
)
;
double
surfaceArea
=
2
*
Math
.
PI
*
radius
*
radius
;
System
.
out
.
println
(
“Surface area of hemisphere is : “
+
surfaceArea
)
;
}
}
Output Given radius of hemisphere : 10.0 Surface area of hemisphere is : 628.3185307179587 Approach-2: By Using User Input ValueIn this approach, the user will be asked to take the input of the radius value of the cone. Then by using the surface area formula of the cone, find the surface area. Here we will make use of the Java inbuilt pow() method.
Examplepublic
static
void
main
(
String
[
]
args
)
{
double
radius
=
6
;
System
.
out
.
println
(
“Given radius of hemisphere : “
+
radius
)
;
double
surfaceArea
=
2
*
Math
.
PI
*
Math
.
pow
(
radius
,
2
)
;
System
.
out
.
println
(
“Surface area of hemisphere is : “
+
surfaceArea
)
;
}
}
Output Given radius of hemisphere : 6.0 Surface area of hemisphere is : 226.1946710584651 Approach-3: By Using User Defined MethodIn this approach, the radius value of the hemisphere will be initialized in the program. Then we call a user defined method to find the volume by passing the radius value of the hemisphere as a parameter. Then inside the method by using the surface area formula, find the surface area of the hemisphere.
Examplepublic
static
void
main
(
String
[
]
args
)
{
double
radius
=
5.5
;
System
.
out
.
println
(
“Given radius of hemisphere : “
+
radius
)
;
findSurfaceArea
(
radius
)
;
}
public
static
void
findSurfaceArea
(
double
radius
)
{
double
surfaceArea
=
2
*
Math
.
PI
*
Math
.
pow
(
radius
,
2
)
;
System
.
out
.
println
(
“Surface area of Hemisphere is : “
+
surfaceArea
)
;
}
}
Output Given radius of hemisphere : 5.5 Surface area of Hemisphere is : 190.0663555421825In this article, we explored how to find the surface area of a hemisphere in Java by using different approaches.
Update the detailed information about How To Create Packages In Java? on the Minhminhbmm.com website. We hope the article's content will meet your needs, and we will regularly update the information to provide you with the fastest and most accurate information. Have a great day!