{{theTime}}
Search This Blog
Total Pageviews
java.util.MissingFormatArgumentException: Format specifier '%s'
Java 8 HashMap Streaming Example
IdentityHashMap Implementation
assertThat(T, Matcher super T>) in the type Assert is not applicable for the arguments (long, Matcher)
-- Change the expected value to be long.


java.util.regex.PatternSyntaxException: Dangling meta character '*' near index 0
Useful Java Run time Options
How to Print Garbage Collection Output with Time Stamp?
set -XX:PrintGCCompilation
How to use Performance tuning flags to optimize throughput Faster?
java -d64 -server -XX:+AggressiveOpts -XX:+UseLargePages -Xmn10g -Xms26g -Xmx26g
How to use Performance tuning flags to optimize throughput Lower?
java -d64 -XX:+UseG1GC -Xms26g Xmx26g -XX:MaxGCPauseMillis=500 -XX:+PrintGCTimeStamps
How to get Stack Trace of all Java Threads?
bin>jstack.exe -l PID
-- Used to troubleshoot hangs and crashes
How to connect to a Hung Process?
bin> jstack.exe -F -m -l <PID>
How to use Java VisualVM to find Memory Leaks
Command : jdk\bin\jvisualvm.exe
What is java.util.concurrent.ExecutionException?
Java 8 is Here! - Last Call to REGISTER for the Webcast
![]() | ||||||||||||||||
Join Oracle and 9 Million Developers Java 8 is a revolutionary release of the world's #1 development platform. It is the single largest upgrade ever to the programming model, with coordinated core code evolution of the virtual machine, core language, and libraries. With Java 8, developers are uniquely positioned to extend innovation through the largest, open, standards-based, community-driven platform. | ||||||||||||||||
Featured Presenters
Community Members
Oracle Partner
| ||||||||||||||||
![]() | ||||||||||||||||
Launch Webcast: Create the Future with Java 8 Tuesday, March 25, 2014 10 a.m. PT / 1 p.m. ET
Get in on the conversation: #Java8 | ||||||||||||||||
Join Oracle and participants from the Java community to learn how Java 8 can help you:
Register now for the Java 8 keynote address and more than 35 deep-dive technical sessions. Use #Java8QA to tweet questions for the Oracle Java Architect Team in advance of and during the webcast. Join the discussion on the OTN Java 8 Forums. | ||||||||||||||||
![]()
|
Oracle Corporation - Worldwide Headquarters, 500 Oracle Parkway, OPL - E-mail Services, Redwood Shores, CA 94065, United States |
Fibonacci Series Java Program
* Print first 10 Fibonacci numbers.
* --The sequence has been used in the design of a building
* -- Used in Sprint Planning in Agile Practice
*
*/
public class TestFibonacci
{
public static void main(String[] args) {
int fib = 0, nextFib = 1;
for (int i = 1; i <= 10; i++) {
fib = fib + nextFib;
nextFib = fib - nextFib;
System.out.println(fib);
}
}
}
File to File Copy Using Java Streams
- package com.dev.concurrent;
- import java.io.FileInputStream;
- import java.io.FileOutputStream;
- import java.io.IOException;
- /**
- * File to File Copy using Java Streams.
- *
- */
- public class StreamExample
- {
- public void byteStreamExample() {
- try(FileInputStream in = new FileInputStream("samplein.txt")) {
- try (FileOutputStream out = new FileOutputStream("sampleout.txt")) {
- int c;
- while ((c = in.read()) != -1) {
- out.write(c);
- }
- }catch (IOException e) {
- e.printStackTrace();
- }
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
- public static void main(String[] args)
- {
- StreamExample se = new StreamExample() ;
- se.byteStreamExample() ;
- }
- }
Immutable Objects in Java
- Objects consider immutable if its state cannot change after it is constructed.
- Don't provide "setter" methods — methods that modify fields or objects referred to by fields.
- Make all fields final and private.
- Don't allow subclasses to override methods. The simplest way to do this is to declare the class as final. A more sophisticated approach is to make the constructor private and construct instances in factory methods.
- If the instance fields include references to mutable objects, don't allow those objects to be changed:
- Don't provide methods that modify the mutable objects.
- Don't share references to the mutable objects.
- Never store references to external, mutable objects passed to the constructor; if necessary, create copies, and store references to the copies. Similarly, create copies of your internal mutable objects when necessary to avoid returning the originals in your methods.
How to filter the file names in a directory using Java.
public String[] filterFileNames() throws IOException
String pattern = "Today";
final Pattern p = Pattern.compile(pattern);
FilenameFilter filter = new FilenameFilter() {
public boolean accept(File fdir, String fname)
{
Matcher m = p.matcher(fname);
return m.matches();
}};
File dirFile = new File( "directory path" );
String[] filteredFiles = dirFile.list(filter);
return filteredFiles ;
}
How to thread safe public static methods using locks
If any third party public methods which are not thread safe, create global locks.
Sample Code:
static Object internalLock = new Object() ;
synchronize(internalLock){
call public API;
}
String.split(String regex, int limit)
split
public String[] split(String regex, int limit)
- Splits this string around matches of the given regular expression.The array returned by this method contains each substring of this string that is terminated by another substring that matches the given expression or is terminated by the end of the string. The substrings in the array are in the order in which they occur in this string. If the expression does not match any part of the input then the resulting array has just one element, namely this string.
The limit parameter controls the number of times the pattern is applied and therefore affects the length of the resulting array. If the limit n is greater than zero then the pattern will be applied at mostn - 1 times, the array's length will be no greater than n, and the array's last entry will contain all input beyond the last matched delimiter. If n is non-positive then the pattern will be applied as many times as possible and the array can have any length. If n is zero then the pattern will be applied as many times as possible, the array can have any length, and trailing empty strings will be discarded.
The string "boo:and:foo", for example, yields the following results with these parameters:
Regex Limit Result : 2 { "boo", "and:foo" } : 5 { "boo", "and", "foo" } : -2 { "boo", "and", "foo" } o 5 { "b", "", ":and:f", "", "" } o -2 { "b", "", ":and:f", "", "" } o 0 { "b", "", ":and:f" }
It is equal asPattern
.compile
(regex).split
(str, n)
Optimizing Java Applications for Low-Latency Microservices
Introduction Microservices architecture has become a go-to for building scalable, modular systems, but achieving low latency in Java-based...