Friday, February 18, 2011

C Program without Main ( or Hidden Main ) - A step Ahead Compiler

How to write a C program without a main function?. Is it possible to do that. Yes there can be a C program without a main function. Here’s the code of the program without a main function…
 
 
#include<stdio.h>
#define decode(s,t,u,m,p,e,d) m##s##u##t
#define begin decode(a,n,i,m,a,t,e) int begin()
{
printf(” hello “);
}
 
Does the above program run without the main function? Yes, the above program runs perfectly fine even without a main function. But how, whats the logic behind it? How can we have a C program working without main?
Here we are using preprocessor directive #define with arguments to give an impression that the program runs without main. But in reality it runs with a hidden main function.
The ‘##‘ operator is called the token pasting or token merging operator. That is we can merge two or more characters with it.
NOTE: A Preprocessor is program which processess the source code before compilation.
 
Look at the 2nd line of program -
#define decode(s,t,u,m,p,e,d) m##s##u##t
 
What is the preprocessor doing here. The macro decode(s,t,u,m,p,e,d) is being expanded as “msut” (The ## operator merges m,s,u & t into msut). The logic is when you pass (s,t,u,m,p,e,d) as argument it merges the 4th,1st,3rd & the 2nd characters(tokens).
 
Now look at the third line of the program -
#define begin decode(a,n,i,m,a,t,e)
 
Here the preprocessor replaces the macro “begin” with the expansion decode(a,n,i,m,a,t,e). According to the macro definition in the previous line the argument must be expanded so that the 4th,1st,3rd & the 2nd characters must be merged. In the argument (a,n,i,m,a,t,e) 4th,1st,3rd & the 2nd characters are ‘m’,'a’,'i’ & ‘n’.
So the third line “int begin” is replaced by “int main” by the preprocessor before the program is passed on for the compiler. That’s it…
The bottom line is there can never exist a C program without a main function. Here we are just playing a gimmick that makes us beleive the program runs without main function, but actually there exists a hidden main function in the program. Here we are using the proprocessor directive to intelligently replace the word begin” by “main”. In simple words int begin=int main.

Wednesday, February 2, 2011

JSF (Java Server Faces)

What is JSF?
JSF is new standard framework, developed through Java Community Process (JCP), that makes it easy to build user interfaces for java web applications  by assembling reusable components in a page. You can think of  JSF framework as a toolbox  that is full of  ready to use components where you can quickly  and easily add and reuse  these components many times in a page and capture events generated by actions on these components. So JSF applications are event driven. You typically embed components in a jsp page using custom tags defined by JSF technology and use the framework to handle navigation from one page to another. Components can be nested within another component , for example, input box, button in a form.
JSF is based on well established Model-View-Controller (MVC) design pattern. Applications developed using JSF frameworks are well designed and easy to maintain then any other applications developed in JSP and Servlets.
JSF eases the development of web applications based on Java technologies. Here are some of benefits of using JSF:
  • JSF provides standard, reusable components for creating user interfaces for web applications.
  • JSF provides many tag libraries for accessing and manipulating the components.
  • It automatically saves the form data and repopulates the form when it is displayed at client side.
  • JSF encapsulates the event handling and component rendering logic from programmers, programmers just use the custom components.
  • JSF is a specification and vendors can develop the implementations for JSF.
  • There are many GUIs available these days to simplify the development of web based application based on JSF framework.
JSF Components
JSF  includes mainly:
  1. Set of APIs to represent and manage state of components that helps server side validation, event handling, page navigation, data conversion etc.
  2. JSP custom tag library to create UI components in a view page.
The UI (user interface) created using JSF technology runs on server and  output is shown to the client. Goal of JSF  is to create web applications faster and easier. Developers can focus on UI components, events handling, backing beans and their interactions rather than request, response and markup. JSF hides complexities to enable developers to focus on their own specific work.

Tuesday, February 1, 2011

Java's role in integrated and distributed ERP applications

Rapid application development (RAD) and enterprise resource planning (ERP) are necessary bedfellows. The sheer scope of ERP requires that the developer develop applications as quickly as possible, given that a typical ERP implementation will not only involve myriad applications but will also require that many of those applications be reengineered or extended to encompass systems of partner companies.

The prudent developer, then, must be equipped with tools that facilitate RAD but that can also meet the challenge of ERP. These tools must be able to deftly interface with and extend distributed systems, be integration-friendly, and offer a robust and flexible platform for interface development. Java not only meets these criteria but also may be persuasively defended as the most capable contender in this area.

Why the choice is important
Selecting an interface development platform for your ERP application design is not a trivial decision. The selection involves more than simply choosing a package that your people are currently using or going with whatever senior management has adopted as a buzzword. Consider the following points to help make an effective long-range choice that will serve your environment and settle in comfortably with your team:
  • Strong history in the field: ERP’s rapid expansion, particularly in the United States, has necessarily generated tremendous inertia in business process reengineering, with a specific spectrum of features that are common to most implementations. Application development tools that are specifically attuned to those popular features will be found in those platforms that are deeply invested in ERP technologies.
  • Flexibility in communications: The nature of communications in ERP systems requires great flexibility in communication protocols. Applications must often be transparent to internal/external interface considerations, accommodating all manner of routing and file transfer mechanisms. Any successful interface platform, therefore, must be equally robust in both synchronous and asynchronous protocols.
  • Elegant architecture: ERP applications differ from conventional business applications in two primary areas—they are integrated and/or distributed. Either of these by itself imposes an intimidating layer of complexity on application development; both at once can be daunting. Applications must have a clean, deft structure in order to function unambiguously and be maintainable and robust. So any ERP application development platform must inherently promote good design.
  • Robust performance: Both integrated and distributed applications require a high degree of fault tolerance because the nature of both distributed and integrated applications is that there are far more one-to-many and many-to-many relationships in the transfer of data. That is, there are usually many more points at which the system can break down. The only hedge against user frustration in the event of error is to design a system that can deliver all or part of what is required in spite of system faults. This requires an interface development package that facilitates such design.
  • Maintainability: Modification and repair are formidable tasks due to the complexity of integrated and distributed applications. Any interface development platform for ERP work needs to facilitate rapid intervention and friendly testing.
  • Well-developed tool suites: If there’s one thing ERP development doesn’t permit in sufficient measure, it’s time. That’s why project methodology, platform selection, and testing philosophy can’t simply be matters of personal preference. Whether you’re developing, testing, or fixing something, you simply don’t have time for do-it-yourself methods. You need tools that will give you every conceivable shortcut to get to a good result. The quality of the development package—its debug tools and testing utilities—is critical. Go with something that has wide implementation and a hefty user base.

Java in the ERP universe
Java meets these standards. It is the prominent platform for ERP application interface, often chosen over the in-house application development suites of the ERP vendor—and for good reason.

One of the first industry responses to the presence of European ERP technology in the United States was to mate the distributed application potential of ERP platforms to the already-developed potential of Internet applications. This was a match approached with some caution, due to flaccid standards and security concerns. But now that it’s working, it’s working big-time—and who’s the leader in Internet app development? It’s Java, the father of the applet. Java pioneered the Internet spot-job workhorse that enables multiplatform user interfaces capable of complex operation combined with extreme ease of use. This makes Java a natural bridge for the rapidly expanding universe of distributed applications that utilize the Internet, both as interface platform and portal tool.

Java has many strengths when applied to ERP. It is itself platform-independent; it is object-oriented, and thus it is flexible and modular while simultaneously promoting robust design structure; it accommodates both SAP-synchronous and SAP-asynchronous communications and so is appropriate for interfaces of varying types; and it facilitates the creation of secure applications that cannot be misappropriated to write data or connect to foreign servers indiscriminately—a key consideration in distributed apps, both in-house and across B2B interfaces.

Other ERP players
If you are making choices for use in your development department, Java merits your serious attention not only for its inherent qualities but also for the incredible suite of tools available that you can apply in ERP development.

The popular European ERP platform SAP (now also widely deployed in the United States and around the world) opened its doors to Java when it decentralized its product. Stand-alone SAP modules and the company’s Complimentary Software Program set up an ideal situation for application developers by providing gateway software into the SAP core system (i.e., the databases, which is what SAP and most ERP systems are mostly about), permitting third-party applications to then take the ball and run with it. Anyone who has worked with Java in Internet apps will quickly see that Java is ideal for such an environment; that’s what it was made for. To this end, SAP has created the JRFC package (Java Remote Function Calls), a powerful and diverse class library that gives programmers full access to an SAP system.

The other ERP superpower is Oracle, and here Java’s available resources are just unbeatable. Both companies have bent over backward to work well together, with the Java 2 Enterprise Edition standard serving as the basis for an Oracle development suite that is all Java, the Oracle Business Component for Java (with Oracle JDeveloper). In addition, Oracle offers Java Server Page Support, for developing DHTML clients (this is integrated with JDeveloper), and support of Business Components for Java (JavaBeans, JavaServlets, etc.) in Oracle Application Server.

In subsequent articles, we’ll look at some specific applications of Java in SAP and Oracle, with specific attention to distributed and integrated application development.

Disqus for yogi's talk

comments powered by Disqus