1. java.awt: This package provides classes for creating graphical user interfaces (GUI) in Java. It's core contains the classes for creating windows, frames, panels, buttons, and other UI components.
Example Code:
import java.awt.*; import javax.swing.*;
public class MyFrame extends JFrame { public MyFrame() { setSize(300, 200); setTitle("My First Frame"); setVisible(true); } public static void main(String args[]) { MyFrame mf = new MyFrame(); } }
In this example code, we import java.awt and javax.swing packages to create a frame class that extends the JFrame class. We then create an object of this class to display a window of size 300x200 with the title "My First Frame".
2. Math: This class is a part of the java.lang package and provides basic mathematical functions. These functions include exponentiation, logarithms, trigonometric functions, and rounding.
Example Code:
import java.lang.*;
public class MathFunctions { public static void main(String args[]) { double num = 4.5; double square = Math.pow(num, 2); double sqrt = Math.sqrt(num);
System.out.println("Square of " + num + " is " + square); System.out.println("Square root of " + num + " is " + sqrt); } }
In this example code, we import java.lang package and use the Math class to calculate the square and square root of a given number (4.5) using the Math.pow and Math.sqrt methods respectively. The output of these calculations is then displayed using the System.out.println statement.
Package library: java.lang
Java Math - 30 examples found. These are the top rated real world Java examples of java.awt.Math extracted from open source projects. You can rate examples to help us improve the quality of examples.