How to make hidden files in Java Program with Example
How to find hidden file with Example
You can check hidden files from Java program by using File API and isHidden()method of Java class.
Java File I/O Basics
Java 7 introduced the java.nio.file package to provide comprehensive support for file I/O. Besides a lot of other functionality this package includes the Files class (if you already use this class you can stop reading here). Files contains a lot of static methods that can be used to accomplish common tasks when working with files. Unfortunately it looks to me that still a lot of newer (Java 7+) code is written using old (pre Java 7) ways of working with files. This does not have to be bad, but it can make things more complex than needed.
How to Use Locks in Multi-threaded Java Program
Many Java programmers confused themselves like hell while writing multi-threaded Java programs e.g. where to synchronized? Which Lock to use? What Lock to use etc. I often receive request to explain about how to use Locks in Java, so I thought to write a simple Java program, which is multi-threaded and uses rather new Lock interface. Remember Lock is your tool to guard shared resource which can be anything e.g. database, File system, a Prime number Generator or a Message processor. Before using Locks in Java program...
Loading Java Properties Files
Java Properties files are amazing resources to add information in Java. Generally these files are used to store static information in key and value pair. Things that you do not want to hard code in your Java code goes into properties files.
Although there are multiple ways of loading properties file, I will be focusing on loading the resource bundle files from class path resources. There are advantages of adding properties files in the classpath:
How to read Environment Variables
There are two ways to get environment variable in Java, by using System properties or by using System.getEnv(). System properties provides only limited set of predefined environment variables like java.classpath, for retriving Java Classpath or java.username to get User Id which is used to run Java program etc but a more robust and platform independent way of getting environment variable in Java program on the other hand Sytem.getEnv() method provide access to all environment variables inside Java program but subject to introduce platform dependency if program relies on a particular environment variable.
Introduction – java.lang package
A package is a collection of predefined classes and interfaces, generally, having some common functionality (purpose). A package of Java is equivalent to a header file of C/C++. All the packages put together, that comes with JDK software, are known as Java API. The most important package of Java API is java.lang because without it no Java program with some functionality cannot be developed; it may be an application or applet. As this package is inevitable for each and every Java program you write, the package is implicitly imported if the programmer does not import himself; this automatic importing facility exist only for java.lang package and not for other packages.
How to Set Path for Java in Windows
In this Java PATH tutorial we will see what is PATH for Java, How to Set Path for Java and how to troubleshoot PATH related issues.
PATH is one of fundamental Environment variable on shell or DOS but it’s commonly associated with Java mainly because if we try to run a java program which doesn't include Java executable in PATH then we say PATH is not set for Java and we need to set path for Java. I have also seen developer getting confused over path and classpath in java.
How to use Memory Mapped File
Memory Mapped File in Java are special files which allows java program to read and write directly to memory which is extremely fast compare to stream based IO and allows programmer to code high performance java application.
Explore the JDK 8 API
Java Package Tutorial
Many times when we get a chance to work on a small project, one thing we intend to do is to put all java files into one single directory. It is quick, easy and harmless. However if our small project gets bigger, and the number of files is increasing, putting all these files into the same directory would be a nightmare for us. In java we can avoid this sort of problem by using Packages.
Simple Java Configuration Files and no XML in Sight
The last time I discussed Java configuration files it was from the point of locating them on the disk the right way. This time I want to comment on the content of configuration files. There seems to be an obsession with XML in the modern world. Some people seem to think that shoe-horning XML into their applications will somehow magically make them great. I don’t want to completely put down XML because it most certainly has its uses.
How to connect MySQL database with Example
When you start learning JDBC in Java, first program you want to execute is connect to database from Java and get some result back by executing some SELECT queries. In this Java program we will learn How to connect to MySQL database from Java program and execute query against it. I choose MySQL database because its free and and easy to install and setup. If you are using Netbeans IDE than you can connect MySQL Server directly from Netbeans, Which means in one window you could be writing Java code and other you can write SQL queries. Another advantage of using MySQL database is that it provides type 4 JDBC driver bundled in:
How to find IP address
Java networking API provides method to find IP address of localhost from Java program by using java.net. InetAddress class. It’s rare when you need IP address for localhost in Java program. Mostly I used Unix command to find IP address of localhost. For all practical purpose where program doesn’t need IP address but you need to troubleshoot any networking issues, Use DOS or windows command or Use Linux commands.
Retrieving Files Recursively
Sometimes I need to read recursively all the files from a directory. I kept using DirectoryScanner class from the Apache(located in ant.jar in my case). It has the advantage that it can filter through files based on the well-known asterisk matching. Recently I had to look-up in a directory containing lots and lots of files and it proved DirectoryScanner tended to be quite slow. So I used plain java for that(using java.io.File and java.io.FilenameFilter classes), for 2 reasons. First is that the speed can be improved quite easy. The second reason is that reporting progress in command line give the impression it takes less time.
Setting a database - MySQL
In almost every good Java program, data storage is used. Have you ever wondered how this is done? If yes, you'll be satisfied, beacause this tutorial will cover databases in Java: how to set up one, access it, modify data... A database is 100 times faster than using plain text files to manage your data, and it allows to search and order the results using SQL syntax (don't worry if it is unknown to you, it will be covered later). First of all, we need to set up your database. You need to have some basic knowledge about Java and packages to be able to follow.
MS Access Database Connectivity in Java
It is quiet easy to connect MS Access database through java program. Before proceeding with the program, let me explain some basic concepts used in this program. This causes the driver class to dynamically load at runtime and it causes the driver to get initialized and returns the class object associated with it.
Java structure and syntax
Get the List of Files in a Directory
This Java tutorial shows how to get the list of files that are in a specific directory using Java. This tutorial will also show you how to filter the files to get only the files you are interested in.
Does 'static' cause Memory Leak in Java?
What's memory leak? In simple terms, it's unused but referenced (somehow because the programmer probably unintentionally forgot to remove the references once the use of the object was over) part of the memory. Before we start discussing if 'static' can cause memory leak in Java, let me assure you that whatever you've read about Garbage Collectors in Java, is still valid and it certainly takes care of most (almost all) of the memory allocation/reclamation of Java objects. But, that alone doesn't remove the possibility of the presence of memory leak in a Java program - just for example, you might not only be using only Java objects in your Java program. Putting it differently, what if you have used some native objects and forgot to reclaim the memory explicitly because that's anyway not going to be taken care by the GC (which takes care of heap memory management only)... right?
Love and hate for Java 8
Java 8 may be the most anticipated version of Java ever. Originally slated for release in September, Java 8 has been delayed until March of next year, supposedly to buy time to make security fixes aimed mainly at client-side Java (JavaFX/Swing).