Posts

Java Data Time Format made simple

/** * Format a time from a given format to given target format * * @param inputFormat * @param inputTimeStamp * @param outputFormat * @return * @throws ParseException */ private static String TimeStampConverter ( final String inputFormat , String inputTimeStamp , final String outputFormat ) throws ParseException { return new SimpleDateFormat ( outputFormat ). format ( new SimpleDateFormat ( inputFormat ). parse ( inputTimeStamp )); } Sample Usage is as Following: try { String inputTimeStamp = "Tue Feb 05 13:59:44 IST 2013" ; final String inputFormat = "EEE MMM dd HH:mm:ss z yyyy" ; final String outputFormat = "yyyy.MM.dd GGG hh:mm aaa" ; System . out . println ( TimeStampConverter ( inputFormat , inputTimeStamp , outputFormat )); } catch ( ParseException e ) {...

How and When, does finally block get executed in java - deep thinking from C++ concepts RAI Resource Allocation is Initializtion

Does finally block runs even after block/object/function get returned? Yes. Even if there was an  Exception  within  catch  block,  finally  will be executed. If you are familiar with C++, just think  finally  as the  destructor  of an  object . What ever the state of a statement within the object,  ~Destructor  will be executed. But you cant put  return  within finally [some compilers allow though]. See the code below: See how global variable  y  been changed. Also see how  Exception1  been covered by  Exception2 . using System ; using System . Collections . Generic ; using System . Linq ; using System . Text ; namespace finallyTest { class Program { static int y = 0 ; static int testFinally () { int x = 0 ; try { x = 1 ; throw new Exception ( "Exc...

Creating and using own jsp Tag Library

Creating and Using Your Own JSP Tag Library Java Server Pages (JSP) is a well-established technology for implementing the View layer in web applications using the MVC (Model-View-Controller) pattern. JSP makes it easy to embed HTML and Java logic together, offering a standardized and streamlined approach to building dynamic web interfaces. JSP also supports custom tag libraries , allowing developers to create reusable components that encapsulate presentation logic. This leads to cleaner, more maintainable code. In this article, we'll explore how to create and use a custom JSP tag library, as well as review the JSP life cycle. Why Use Custom JSP Tags? JSP provides standard tags such as <jsp:include> and <jsp:useBean> , but sometimes, application-specific logic needs to be reused across multiple pages. Custom tags help you: Encapsulate and reuse complex logic Write cleaner JSP pages with less embedded Java code Separate business logic from view code...

Day 1 Keynote - Bjarne Stroustrup: C++11 Style

const Vs constexpr

With C++11, WG21  comity introduced generalized constant expression to be able to use in C++ as compile time evaluated constants, and only be used on where its value is evaluated to a const expression. It should have the following requirements: As a Variable: it must be immediately constructed or assigned a value. the constructor parameters or the value to be assigned must contain only literal values,  constexpr  variables and functions. the constructor used to construct the object (either implicit or explicit) must satisfy the requirements of  constexpr  constructor. In the case of explicit constructor, it must have  constexpr  specified. As a Function: it must not be virtual its return type must be  LiteralType each of its parameters must be literal type the function body must be either deleted or defaulted or contain only the following: null statements static_assert  declarations typedef  declarations and...

Memory leak detection in C,C++ codes and Apps

On of the major part of C/C++ native application development is the memory management.Allocation and Deallocation of memory on runtime and cleaning memory before exit is hard to keep in touch while development. If OOP is in the best use this can be minimized but still can be a issue. Specially while loading and using 3rd party dll and libraries can cause unknown issues. Detection of leaks can be done in many ways, code level using detection tools. Code level memory detection is supported by most compilers and there are many libraries to do so. This is almost done in debug mode. _CRT library example of memory detection. This is a set of libraries given my Microsoft to monitor memory status in the application: Before using this you have to include following lines of codes: #ifndef _CRTDBG_MAP_ALLOC #define _CRTDBG_MAP_ALLOC #endif _CRTDBG_MAP_ALLOC #include #include Then after you have to go to a certain function call and check whether there was a m...

Apache Bar Camp- Colombo 2012

Image
Today sri lankan techies had a wonderful time with apache at UCSC on  with the help of WSO2 and commitment of special apache people here at colombo. The session was with 3 keynote speakers, started by Dr.sanjeewa weerawarna, CEO of WSO2. He was giving his valuable time for the newbees and followups with great information of his lifetime story with FOSS. "The Apache Way" could bring the audience to the interesting of being part of the apache comminuty for the community in more long term basis. The simplest form of "Just F***** Do It" [JFDI] was introduced and mentored on the apache community. Meritocracy vs Democracy was a key on the success of apache, and was only used in case of a evading. Otherwise every individual was the key node on the apache community, not either a big part of huge business could break that synopsis. Subversion system is the first time machine developed[only usable by committees], which make you secu...