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

 ALL


  Hexadecimal and long in Java

Today I encountered a hexadecimal operation problem when I was implementing a bit reverse function for integer type. Basically in the implementation, there is an operation which is to do the bit operation & between one long integer and a hexadecimal number 0x00000000FFFFFFFFF. I was expecting that the high 32 bits of the long integer will be zeroed. But unfortunately I didn't get the expected result.The basic implementation is:long num=0x00F0_0000;num = (num>>16) | (num<<16); //Here the result will be 0x000000F0000000F0num = num & 0x00000000_FFFFFFFF;System.out.println("...

4,594 0       JAVA HEXADECIMAL LONG BITWISE OPERATION


  static nested and non-static nested class in Java

Nested classes are divided into two categories: static and non-static(inner). Nested classes that are declared static are simply called static nested classes. Non-static nested classes are called inner classes.Static class can be defined as :class OuterClass{ static class StaticNestedClass{ //OTHER STUFF }}Static nested classes are accessed using the enclosing class name:OuterClass.StaticNestedClassFor example, to create an object for the static nested class, use this syntax:OuterClass.StaticNestedClass nestedObject =new OuterClass.StaticNestedClass();The creation of an instance o...

4,377 0       JAVA STATIC NESTED CLASS INNER CLASS


  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,076 0       JAVA READABLE CHECK FILES


  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,795 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,539 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,648 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,718 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,951 0       JAVA CLEAR LIST DUPLICATE