Get the Name of the File and Path in Java

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

7K+ Views

The name of the file and the name of the path can be obtained using the methods java.io.File.getName() and java.io.File.getPath() respectively. The getName() returns the name of the file or the directory. The getPath() returns the abstract pathname in the form of a pathname string.A program that demonstrates this is given as follows −Example Live Demoimport java.io.File; public class Demo {    public static void main(String[] args) {       File file = new File("C:" + File.separator + "jdk11.0.2" + File.separator, "demo1.java");       System.out.println("File name: " + file.getName());       System.out.println("Path name: " + file.getPath());    } ... Read More

Storing Money Amounts in MySQL

George John
Updated on 30-Jul-2019 22:30:24

8K+ Views

To store money amounts in MySQL, the best choice is to use DECIMAL data type or NUMERIC type. Float data type is not a good choice for money amounts. It gives some rounding errors. Therefore, avoid float for money amounts.Let us first create a table with data type DECIMAL. The following is the query to create a table −mysql> create table MoneyStorageDemo -> ( -> Amount DECIMAL(4, 2) -> ); Query OK, 0 rows affected (0.44 sec)Inserting some values into the table with the help of insert command. The query is ... Read More

Delimiters in MySQL

Anvi Jain
Updated on 30-Jul-2019 22:30:24

7K+ Views

Delimiters can be used when you need to define the stored procedures, function as well as to create triggers. The default delimiter is semicolon.You can change the delimiters to create procedures and so on. However, but if you are considering multiple statements, then you need to use different delimiters like $$ or //.Here we have a table “GetRecordFromNow” wherein the following are the records −+---------------------+ | YourDateTime | +---------------------+ | 2018-12-07 22:30:18 | | 2018-12-03 22:30:31 | | 2018-12-02 22:30:41 | | 2018-12-01 22:30:56 | | 2018-12-03 22:31:04 | +---------------------+ 5 rows in ... Read More

Get the Element Ordered Last in Java TreeSet

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

217 Views

To get the element ordered last i.e. the last element in TreeSet, use the last() method.Create a TreeSet and add elements to itTreeSet set = new TreeSet (); set.add("65"); set.add("45"); set.add("19"); set.add("27"); set.add("89"); set.add("57");Now, get the last elementset.last()The following is an example to get the element ordered last in TreeStExample Live Demoimport java.util.*; public class Demo { public static void main(String args[]){ TreeSet set = new TreeSet (); set.add("65"); set.add("45"); set.add("19"); ... Read More

Check if a Key Exists in TreeMap in Java

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

197 Views

To check if a particular key exists in TreeMap, use the containsKey() method.Create a TreeMap first and add some elements −TreeMap m = new TreeMap(); m.put(1, "PHP"); m.put(2, "jQuery"); m.put(3, "JavaScript"); m.put(4, "Ruby"); m.put(5, "Java"); m.put(6, "AngularJS"); m.put(7, "ExpressJS");Now, let’s say we need to check that key 5 exists or not. For that, set the containsKey() method like this −m.containsKey(5)The following is an example to check if a particular key exists in TreeMap −Example Live Demoimport java.util.*; public class Demo {    public static void main(String args[]) {       TreeMap m = new TreeMap();       m.put(1, "PHP"); ... Read More

Difference Between Hastily and Quickly

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

729 Views

Ideally speaking, there is no major difference between the words "hastily " and "quickly". Both come from the verbs' Haste' and 'Quick' and are used here as adverbs to qualify the verbs.Hastily: It refers to a work done hurriedly.Quickly: It can refer to both, work is done hurriedly or something indicative of speed.Thus, when one needs to denote the meaning of being in a hurry, with no time even to sit, relax and breathe, one uses 'Hastily'. But when one uses the word in a sense to indicate speedily, say 'Wait, I will quickly prepare Maggi for you.' Here, 'hastily' ... Read More

Check If File Object Refers to Absolute Pathname in Java

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

541 Views

The method java.io.File.isAbsolute() is used to check if the file object refers to an absolute pathname. This method returns true if the abstract path name is absolute and false if the abstract path name is not absolute.A program that demonstrates this is given as follows −Example Live Demoimport java.io.File; public class Demo {    public static void main(String[] args) {       File file = new File("C:" + File.separator + "jdk11.0.2" + File.separator, "demo1.java");       System.out.println(file.isAbsolute());    } }The output of the above program is as follows −OutputfalseNow let us understand the above program.The isAbsolute() method is used ... Read More

Know Your Current Username in MySQL

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

9K+ Views

Yes, you can use the method CURRENT_USER() to know the current username in MySQL.The above method returns the username that can be used to authenticate the client connection.The query is as follows −mysql> select CURRENT_USER();The following is the output −+----------------+ | CURRENT_USER() | +----------------+ | root@% | +----------------+ 1 row in set (0.00 sec)Or you can use USER() method from MySQL. The query is as follows −mysql> select user();Here is the output −+----------------+ | user() | +----------------+ | root@localhost | +----------------+ 1 row in set (0.00 sec)

Get Primary Key of a Table in MySQL

Jennifer Nicholas
Updated on 30-Jul-2019 22:30:24

4K+ Views

To get the primary key of a table, you can use the show command. The syntax is as follows −SHOW INDEX FROM yourDatebaseName.yourTableName WHERE Key_name = 'PRIMARY';Suppose, we have a table with two primary keys; one of them is “Id” and second is “RollNum". The query for a table is as follows −mysql> create table TwoOrMorePrimary    −> (    −> Id int,    −> Name varchar(200),    −> RollNum int    −> ,    −> Primary key(Id, Age)    −> ); Query OK, 0 rows affected (0.85 sec)Apply the above syntax to get primary key of a table. ... Read More

Frame the Report of an Event Conducted in College

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

417 Views

Report writing is a part of academic writing. It is an informational work, such as writing, speech, made with the intention of providing information or recounting events in a presentable form, such that it can be published in a magazine or newspaper.Steps to Write A Report for A College Event Held PreviouslyGather Facts - This is the most extensive and the laborious part. You must know the inside-out phenomena, e.g. who was the chief guest, what was the exact time when the valediction ceremony was conducted. Never keep the facts in your mind, as you might forget in stress and ... Read More

Advertisements