Today's Question:  What does your personal desk look like?        GIVE A SHOUT

 JAVA


  Turn on SecurityManager in Java

SecurityManager in Java is to check whether the application codes can access some restricted resource such as file, socket etc. This can be used in applications which have high security requirements. With this feature turned on, our system resources can be secured with only permitted operations.When JVM starts, it will first check whether the SecurityManager is on by checking the system property java.security.manager, if it's on, then an instance of SecurityManager will be created and it can be used to check different permissions. By default the security manager is off, but there are a few way...

7,961 0       PROGRAM SECURITYMANAGER ENABLE


  Check file readability in Java

File operation is quite platform dependent. Although Java is a cross platform programming language, the file operation in Java is also platform dependent. The obvious evidence is the file permission check. In Java, we can call canRead(), canWrite() and canExecutable() to check whether the program can read, write or execute the file specified. However, on Windows, when we call canRead() on a File object, we may get unexpected result.Actually, on Windows, when we call canRead() on a File object, we will always get the true returned even if we have denied the read access to the file. There is als...

38,073 0       JAVA READABLE CHECK FILES


  Difference between ConcurrentHashMap and Hashtable

Both ConcurrentHashMap and Hashtable are Collection classes for storing key value pairs and they both provide fast element search with a supplied key. They have much in common. However, we will not discuss the similarities between them here, instead we will focus on the differences between them.ConcurrentHashMap and Hashtable are both thread safe. But the mechanism for thread safe is different between them. Hashtable is synchronized, it utilizes the synchronization mechanism; while ConcurrentHashMap uses segmentation to lock the data, it uses concurrent locks operations for thread safety inste...

40,418 3       CONCURRENTHASHMAP HASHTABLE


  Android socket programming example

Socket is a kind of interface for different sides t communicate, it usually identified by an IP and a port. There are many server side software on a server and they would provide different service. Each server many create some sockets and bind them to some ports so that clients can listen to.Software on the Internet will exchange data though a bidirectional connection established. Each end of the connection has a socket created. In Java, Socket and ServerSocket are in java.net package, ServerSocket is used for server side and Socket is used when establishing connection. Once a successful conne...

55,783 3       JAVA ANDROID SOCKET


  Use cases of Java enumeration

JDK 1.5 introduces a new type -- enumeration. In Java, it's just a small feature, but it can bring us much convenience.Here we summarize some use cases of Java enumeration.1. ConstantPrior to JDK 1.5, we can define constant as public static final..., now we can use enumeration to group all constants in one enum variable and it also provides some useful functions.public enum Color {    RED, GREEN, BLANK, YELLOW  }  2.In SwitchPrior to JDK 1.6, only int,char and enum are supported in switch statement, with enum, we can write more r...

3,536 0       JAVA ENUMERATION ENUM


  30 minutes to fix Java vulnerability

On September 25, Adam Gowdiak from the Polish security consulting firm Security Explorations submitted a Java security vulnerability to Oracle and provided a proof-of-concept. The vulnerability exists in Java 5 6,7, once the user accesses hosted malware site, an attacker can remotely control the infected machine.Gowdiak later got in touch again with Oracle and got the response that the fix has reached the final stage. He can expect the patch in four months later. He eventually unbearable Oracle's tedious development, testing processes, We should know that Oracle has to create 30 more patches f...

8,642 0       JAVA FIX VULNERABILITY


  Writing Java codes conforming to coding standard

Recently, I was doing some cleanup to one of my current Java project. I find there are many codes which are not conforming to the Java coding standard. So I list them here and hope that people can improve your codes and write maintainable codes.Format source code and manage imports in Eclipse Eclipse provides functions of auto-formatting and imports management, you can use following shortcuts to use these functions.Ctrl+Shift+F --> Format source codeCtrl+Shift+O -- Manage imports and remove unused import statementsIn addition to manually execute these two functions, you can also let Ec...

5,717 0       JAVA STYLE CODE STANDARD


  3 ways to remove duplicates in List

Frequently, we may have an ArrayList which stores many values, and we need to process the ArrayList and get what are the distinct values in the list, or we may want to count occurrence of each value in the ArrayList. We can remove the duplicates in a few ways. Here we propose 3 methods :    public static void main(String[] args){        //SuperClass sub=new SubClass();                String[] ar = { "dd", "c", "dd", "ff", "b", "e", "e" };        ArrayList list ...

8,949 0       JAVA CLEAR LIST DUPLICATE