Samual Sam has Published 2492 Articles

Java Program to remove path information from a filename returning only its file component

Samual Sam

Samual Sam

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

1K+ Views

The method fileCompinent() is used to remove the path information from a filename and return only its file component. This method requires a single parameter i.e. the file name and it returns the file component only of the file name.A program that demonstrates this is given as follows −Example Live Demoimport ... Read More

Java Program to display hour and minute in AM or PM

Samual Sam

Samual Sam

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

239 Views

Firstly, create a Formatter and a Calendar object.Formatter f = new Formatter(); Calendar c = Calendar.getInstance();For AM/ PM marker, use the following conversion character −pHere, you can see AM/ PM marker −f = new Formatter(); System.out.println(f.format("Hour: %tl %1$Tp", c));The following is an example −Example Live Demoimport java.util.Calendar; import java.util.Formatter; public class ... Read More

Remove an element from a Stack in Java

Samual Sam

Samual Sam

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

5K+ Views

An element can be removed from a stack using the java.util.Stack.pop() method. This method requires no parameters and it removes the element at the top of the stack. It returns the element that was removed.A program that demonstrates this is given as follows −Example Live Demoimport java.util.Stack; public class Demo { ... Read More

ftp_nlist() function in PHP

Samual Sam

Samual Sam

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

41 Views

The ftp_nlist() function returns a list of files in the specified directory on the FTP server.Syntaxftp_nlist(con, dir);Parameterscon − The FTP connectiondir − The directory to be listedReturnThe ftp_nlist() function returns an array of file names on success or FALSE on failure.ExampleThe following is an example wherein we are getting the ... Read More

Java Program to display date and time information in uppercase

Samual Sam

Samual Sam

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

353 Views

Firstly, create a formatter and a Calendar object.Formatter f = new Formatter(); Calendar c = Calendar.getInstance();To display complete date and time information uses the ‘c’ conversion character. However, to display it in uppercase, use ‘Tc’.f = new Formatter(); System.out.println(f.format("Date and Time (uppercase): %Tc", cal));The following is an example −Example Live Demoimport ... Read More

Add a single element to a LinkedList in Java

Samual Sam

Samual Sam

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

268 Views

A single element can be added to a LinkedList by using the java.util.LinkedList.add() method. This method has one parameter parameters i.e. the element that is to be inserted in the LinkedList.A program that demonstrates this is given as follows −Example Live Demoimport java.util.LinkedList; public class Demo { public ... Read More

Create directories recursively in Java

Samual Sam

Samual Sam

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

105 Views

The method java.io.File.mkdirs() is used to create the specified directories, including the necessary parent directories. This method requires no parameters and it returns true on the success of the directories creation or false otherwise.A program that demonstrates this is given as follows −Example Live Demoimport java.io.File; public class Demo {   ... Read More

ftp_put() function in PHP

Samual Sam

Samual Sam

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

226 Views

The ftp_put() function uploads a file to the FTP server.Syntaxftp_put(con, remote_file, local_file, mode, beg_pos);Parameterscon − The FTP connectionremote_file − The file path to upload tolocal_fil − The path of the file to uploadmode − The transfer mode. The following are the possible value −FTP_ASCII, orFTP_BINARYbeg_pos − The position to start ... Read More

Display hour with SimpleDateFormat(“hh”) in Java

Samual Sam

Samual Sam

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

199 Views

To work with SimpleDateFormat class in Java, import the following package.import java.text.SimpleDateFormat;Now, set the format with SimpleDateFormat(“hh”) to display hour −Format f = new SimpleDateFormat("hh");Now, get the hour in a string −String strHour = f.format(new 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 ... Read More

Traverse a collection of objects using the Enumeration Interface in Java

Samual Sam

Samual Sam

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

1K+ Views

All the elements in a collection of objects can be traversed using the Enumeration interface. The method hasMoreElements( ) returns true if there are more elements to be enumerated and false if there are no more elements to be enumerated. The method nextElement( ) returns the next object in the ... Read More

Advertisements