Display a Currency Value in Java

Samual Sam
Updated on 30-Jul-2019 22:30:24

218 Views

To display a currency in Java, use the following DecimalFormat −DecimalFormat decFormat = new DecimalFormat("\u00a4#, ##0.00");Since, we have used the DecimalFormat class, therefore do not forget to import the following package −import java.text.DecimalFormat;Now, let us learn how to display percentage −decFormat.format(877.80) decFormat.format(8.19) decFormat.format(9897.88)The above will be displayed as −$877.80 $8.19 $9, 897.88The following is the complete example −Example Live Demoimport java.text.DecimalFormat; public class Demo { public static void main(String[] argv) throws Exception { // for currency DecimalFormat decFormat = new DecimalFormat("\u00a4#, ##0.00"); ... Read More

Format Java Date with HH:MM:SS Z using SimpleDateFormat

karthikeya Boyini
Updated on 30-Jul-2019 22:30:24

2K+ Views

The Z means "zero hour offset", also known as "Zulu time" (UTC) in the ISO 8601 time representation. However, ACP 121 standard defines the list of military time zones and derives the "Zulu time" from theGreenwich Mean Time (GMT).Let us see the usage of SimpleDateFormat(“HH:mm:ss Z”) −Format f = new SimpleDateFormat("HH.mm.ss Z"); String strResult = f.format(new Date()); System.out.println("Time = "+strResult);The following is the complete example that displays time with offset (HH:mm:ss Z) −Example Live Demoimport java.text.Format; import java.text.SimpleDateFormat; import java.util.Date; import java.util.Calendar; public class Demo { public static void main(String[] args) throws Exception { ... Read More

Data Type for Unix Timestamp in MySQL

Arjun Thakur
Updated on 30-Jul-2019 22:30:24

2K+ Views

The best data type for unix_timestamp in MySQL is integer. The integer data type is as followsint(11);The integer data type is useful for condition checking like ( > , create table UnixTime -> ( -> DueTime datetime -> ); Query OK, 0 rows affected (0.55 sec)Insert records in the form of date using insert command. The query is as followsmysql> insert into UnixTime values(now()); Query OK, 1 row affected (0.15 sec) mysql> insert into UnixTime values('2010-10-14'); Query OK, 1 row affected (0.15 sec) mysql> insert into UnixTime values('2020-09-24'); Query ... Read More

Check If a String Contains Numbers in MySQL

Chandu yadav
Updated on 30-Jul-2019 22:30:24

3K+ Views

To check a string contains numbers, you can use regexp i.e. Regular Expressions. The syntax is as follows −SELECT *FROM yourTableName where yourColumnName REGEXP ‘[0-9]’;To understand the above syntax, let us create a table. The query to create a table is as follows −mysql> create table StringContainsNumber    -> (    -> Id int not null auto_increment,    -> Words text,    -> primary key(Id)    -> ); Query OK, 0 rows affected (0.53 sec)Insert some records in the table using insert command. The query is as follows −mysql> insert into StringContainsNumber(Words) values('He12345llo'); Query OK, 1 row affected (0.19 sec) ... Read More

Minimum and Maximum Priority Threads in Java

Arushi
Updated on 30-Jul-2019 22:30:24

4K+ Views

The thread priority determines when the processor is provided to the thread as well as other resources. It can be changed using the method setPriority() of class Thread.There are three static variables for thread priority in Java i.e. MIN_PRIORITY, MAX_PRIORITY and NORM_PRIORITY. The values of these variables are 1, 10 and 5 respectively.A program that demonstrates this is given as follows:Example Live Demopublic class ThreadDemo extends Thread {    public void run() {       System.out.println("Running...");    }    public static void main(String[] args) {       ThreadDemo thread1 = new ThreadDemo();       ThreadDemo thread2 = new ... Read More

DecimalFormat in Java: Formatting Numbers with Pattern 00.00E0

karthikeya Boyini
Updated on 30-Jul-2019 22:30:24

315 Views

DecimalFormat is a concrete subclass of NumberFormat that formats decimal numbers. Let us set DecimalFormat("00.00E0") and use the format() method as well.DecimalFormat decFormat = new DecimalFormat("00.00E0"); System.out.println(decFormat.format(-289.8787)); System.out.println(decFormat.format(8.19));Since, we have used DecimalFormat class in Java, therefore importing the following package is a must −import java.text.DecimalFormat;The following is the complete example −Example Live Demoimport java.text.DecimalFormat; public class Demo { public static void main(String[] argv) throws Exception { DecimalFormat decFormat = new DecimalFormat("00.00E0"); System.out.println(decFormat.format(-289.8787)); System.out.println(decFormat.format(8.19)); System.out.println(decFormat.format(9897.88)); ... Read More

Display Day Number with SimpleDateFormat 'd' in Java

Samual Sam
Updated on 30-Jul-2019 22:30:24

229 Views

To display the day number, use the SimpleDateFormat('d') as shown below −Format f = new SimpleDateFormat("d"); String strDay = f.format(new Date()); System.out.println("Day Number = "+strDay);Since, we have used the Format and SimpleDateFormat class above, therefore import the following packages. With that, we have also used the Date −import java.text.Format; import java.text.SimpleDateFormat; import java.util.Date;The following is an example −Example Live Demoimport java.text.Format; import java.text.SimpleDateFormat; import java.util.Date; import java.util.Calendar; public class Demo { public static void main(String[] args) throws Exception { // displaying current date and time Calendar ... Read More

What is a Deemed University?

Ridhi Arora
Updated on 30-Jul-2019 22:30:24

425 Views

Deemed university is the other name of Deemed-to-be-University, which is an accreditation of a university awarded to higher educational institutions in India by the Department of Higher education. So basically, any university which is ‘deemed to be a university’ by the UGC under Section 3 of the UGC Act of 1956, is called a deemed university.What is a Deemed University?The main feature of Deemed University is Autonomous Control. In a deemed college or university, the management has complete control over anything and everything ranging from the student curriculum to Examinations and issues related to administration and management.The setting of the ... Read More

Add UISegmentedControl to a Container View Programmatically

Rishi Rathor
Updated on 30-Jul-2019 22:30:24

2K+ Views

To add a UISegmentControl in iOS with swift we’ll have to first create a segment control and it’s controller function, i.e. it’s action. Let’s see those steps.Let’s create a function to add a segmented control.func addControl() {    let segmentItems = ["First", "Second"]    let control = UISegmentedControl(items: segmentItems) control.frame = CGRect(x: 10, y: 250, width: (self.view.frame.width - 20), height: 50) control.addTarget(self, action: #selector(segmentControl(_:)), for: .valueChanged) control.selectedSegmentIndex = 1 view.addSubview(control) }This function may be called in our view controller to add the segmented control, let’s add action for ... Read More

Use Boolean Value to Stop a Thread in Java

Vikyath Ram
Updated on 30-Jul-2019 22:30:24

950 Views

A thread can be created by implementing the Runnable interface and overriding the run() method. Then a Thread object can be created and the start() method called.A thread can be stopped using a boolean value in Java. The thread runs while the boolean value stop is false and it stops running when the boolean value stop becomes true.A program that demonstrates this is given as follows:Exampleclass ThreadDemo extends Thread {    public boolean stop = false;    int i = 1;    public void run() {       while (!stop) {          try {     ... Read More

Advertisements