Java | Garbage Collection

Hi,

  • 1. The process of disposing of dead objects is called garbage collection.

2. Encouraging the Java Virtual Machine (JVM) to do some garbage collecting and recover the memory.

Example:

class MyClass{
  double var; // Radius of a sphere

  MyClass() {

  }

  // Class constructor
  MyClass(double x) {
    var= x; // Set the radius
  }
}
public class MainClass {
  public static void main(String[] arg){
    MyClasss myClass= new MyClass();
    System.gc(); // Direct order to garbage collection
  }

}

Life cycle: http://chaoticjava.com/posts/how-does-garbage-collection-work/

מאת chenreuven פורסם ב-Java

JAVA| Get List of All Available Locale

Hi All,

Locale is important Class that help to developer to get the current local of the computer and then customize his code.

Here is a trick how to get list of all available locales:\

Example:

 Locale[] locales = Locale.getAvailableLocales();

    for (int i = 0; i < locales.length; i++) {

      // Get the 2-letter language code

      String language = locales[i].getLanguage();

    }

מאת chenreuven פורסם ב-General

JavaScript Tip| Get All Arguments on Java Function

Hi,
i handle in the past with issue , that when i function called the user can't see all the variable in the input signiture of the function. the solution is just print it to console or alert it, and all variables show to user 🙂
<head>
<script type="text/javascript">
function displaymessage()
{
alert(arguments);
console.log(arguments);
}
</script>
</head>
<body>
<form>
<input type="button" value="Click me!" onclick="displaymessage('1','2','3','4')" />
</form>
</body>
</html>

Sorting On Array , The Easy Way

Hi,

I see developer that use some alghorithms for sorting on array and it fine. but there is another way that it more useful.

import java.util.Arrays;

Arrays.sort (int [])
Arrays.sort (String [])
Arrays.sort (float [])
Arrays.sort (double [])
Arrays.sort (long [])
Arrays.sort (Object [])
Sort in Ascending, example:
//Sort array in ascending order
String [] stringArray = {"ab", "aB", "c", "0", "2", "1Ad", "a10"}
Arrays.sort(stringArray);
System.out.println("****** Sorted String Array *******");
for (String str : stringArray) {
System.out.println(str);
}
Output:
****** unsorted string *******
ab
aB
c
0
2
1Ad
a10
Sort in Decending, example:
Arrays.sort (Object [], Comparator)
example:
//Sort array in reverse order
Arrays.sort(stringArray, Collections.reverseOrder());
System.out.println("****** Reverse Sorted String Array *******");
for (String str : stringArray) {
System.out.println(str);
}
Output:
****** Reverse Sorted String Array *******
c
ab
aB
a10
2
1Ad
0
Selective Sorting
Arrays.sort (Object [], int startIndex, int endIndex)
Example:
//Sorting array starting from index 3 till 6
Arrays.sort(stringArray, 3, 6);
System.out.println("****** Selective Sort String Array *******");
for (String str : stringArray) {
System.out.println(str);
}
Output:
****** Selective Sort String Array *******
ab
aB
c
0
1Ad
2
a10
One more thing important.
if u Sort Object, u MUST overide the function compareTo…
Enjoy From Sorting


מאת chenreuven פורסם ב-Java

TIP| Debugger Logical Structure

The logical structure is very handy for examining things like maps and other java collections classes, instead of showing the full detail of all the internal variables the view will only show the “logical” pieces. It is activated/deactivated from “Variables” view using logical structure toggle button.

Hope u learn From That 🙂

מאת chenreuven פורסם ב-General

UML| UMLET Plugin For Java

UMLET is a tool to   simplification  the process of building software.

It came with to variation: plugin on eclipse or stand alone software.

i recommended to use this software before u strat to write any line code in java. all the basic UML component exist in the software.

 

Link: http://www.umlet.com/

Have Fun

מאת chenreuven פורסם ב-General