DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

The Latest Coding Topics

article thumbnail
Spring Security 4: JDBC Authentication and Authorization in MySQL
I am going to explain how to use Spring Security in a Spring MVC Application to authenticate and authorize users against user details stored in a MySQL Database.
September 18, 2015
by Priyadarshini Balachandran
· 192,687 Views · 10 Likes
article thumbnail
Velocity Momentum: How to Make It Work for Project Planning and Management
Insights on how to make an average velocity concept a powerful tool for your Agile team.
September 17, 2015
by Darya Korsak
· 4,998 Views · 1 Like
article thumbnail
STRUTS 2 vs SPRINGMVC: Know the Difference & Choose the Best One Based On Your Requirements
Apache Struts 2 and SpringMVC, these two are the most popular and much talked about Java web frameworks today. Many of you might have worked with both of these frameworks, but which is one is better to use? What are the basic differences between both of these frameworks? Well, Apache Struts 2 is an elegant and extensible framework that is used for creating enterprise-level Java web applications. It is designed to streamline the development cycle, starting from building to deployment and maintenance of the application. In Struts, the object that is taking care of a request and routes it for further processing is known as “Action”. On the other hand, Spring MVC is a part of a huge Spring framework stack containing other Spring modules. This means that it doesn’t allow developers to run it without Spring, but the developers can run the Spring Core without Spring MVC. The Spring MVC (Model View Controller) is designed around a DispatcherServlet, which dispatches the requests to handler with configurable handler mappings, view resolution and theme resolution. While the objects responsible for handling requests and routing for processing in Struts called an Action, the same object is referred as Controller in Spring Web MVC framework. This is one of the very first differences between Spring MVC and Struts2. Struts 2 Actions are initiated every time when a request is made, whereas in Spring MVC the Controllers are created only once, stored in memory and shared among all the requests. So, Spring Web MVC framework is far efficient to handle the requests than Struts 2. If we talk about the features, Struts 2 and Spring MVC framework caters different level of business requirements. Let’s take a look at features offered by both of these frameworks. Struts 2 features Configurable MVC components, which are stored in struts.xml file. If you want to change anything, you can easily do it in the xml file. POJO based actions. Struts 2 action class is Plain Old Java Object, which prevents developers to implement any interface or inherit any class. Support for Ajax, which is used to make asynchronous request. It only sends needed field data rather than providing unnecessary information, which at the end improves the performance. Support for integration with Hibernate, Spring, Tiles and so on. Whether you want to use JSP, freemarker, velocity or anything else, you can use different kinds of result types in Struts 2. You can also leverage from various tags like UI tags, Data tags, control tags and more. Brings ample support for theme and template. Struts 2 supports three different kinds of themes including xhtml, simple and css_xhtml. On the other hand, Spring MVC framework brings totally different set of features. Spring MVC features Neat and clear separation of roles. Whether it is controller, command object, form object or anything else, it can be easily fulfilled with the help of a specialized object. Leverage from the adaptability, non-intrusiveness and flexibility with the help of controller method signature. Now use existing business objects as command or form object rather than duplicating them to extend the specific framework base class. Customizable binding and validation will enable manual parsing and conversion to business objects rather than using conventional string. Flexible mode transfer enables easy integration with the latest technology. Customizable locale and theme resolution, support for JSPs with or without Spring tag library for JSTL and so on. Leverage from the simple, but powerful JSP tag library known as Spring tag library. It provides support for various features like data binding and themes. Of course, Struts is one of the most powerful Java application frameworks that can be used in a variety of Java applications. It brings a gamut of services that includes enterprise level services to the POJO. On the other hand, Spring utilizes the dependency injection to achieve the simplification and enhance the testability. Both of these frameworks have their own set of pros and cons associated with it. Struts framework brings a whole host of benefits including: Simplified design Ease of using plug-in Simplified ActionForm & annotations Far better tag features OGNL integration AJAX Support Multiple view options and more However, the only drawback with Struts 2 framework is that it has compatibility issues and poor documentation. On the other hand, Spring MVC provides benefits like: Clear separation between controllers, JavaBeans models and views that is not possible in Struts. Spring MVC is more flexible as compared to the Struts. Spring can be used with different platforms like Velocity, XLST or various other view technologies. There is nothing like ActionForm in Spring, but binds directly to the domain objects. Code is also more testable as compared to the Struts. It is a complete J2EE framework comprising of seven independent layers, which simplifies integration with other frameworks. It doesn’t provide a framework for implementing the business domain and logic, which helps developers create a controller and a view for the application. However, like any other technologies or platforms, Spring MVC too suffers from several criticisms related to the complexity of the Spring framework. Final Verdict Either framework is a great choice. However, if you’re looking for the stable framework, Struts 2 is the right choice for you. On the other hand, if you’re looking for something robust, SpringMVC is perfect. Ensure that you review your exact requirements before choosing the framework!
September 15, 2015
by Manmay Mehta
· 32,362 Views · 4 Likes
article thumbnail
Why Many Return Statements Are a Bad Idea in OOP
Multiple return statements in a method will cause your code not to be purely object-oriented. Here you'll find an example where you can use a clean OOP approach instead of using multiple returns.
September 15, 2015
by Yegor Bugayenko
· 47,170 Views · 7 Likes
article thumbnail
Data Conversion for SQL Server Integration Services (SSIS)
In the series of step by step lessons of SSIS (SQL Server Integration Services), this is part six in which we are going to learn a new control: Data Conversion.
September 15, 2015
by Rajat Jaiswal
· 18,152 Views · 1 Like
article thumbnail
Integrate Redis Into a Node.js Project
The Redis client for Node.js is pretty straightforward and easy to get up and running. Here are a few code snippets that might save you some time.
September 14, 2015
by Emmanouil Gkatziouras DZone Core CORE
· 10,681 Views · 2 Likes
article thumbnail
Configuring Spring Boot for Oracle
Spring Framework is the most popular Java framework used for building enterprise class applications. Oracle is the most popular database used in the enterprise. Let's put these two together!
September 14, 2015
by John Thompson
· 185,519 Views · 12 Likes
article thumbnail
Stored Functions as Stored Procedures in PostgreSQL PL/pgSQL
In this post, I look at a few tactics that can make the use of a stored function in PostgreSQL feel like using a stored procedure.
September 14, 2015
by Dustin Marx
· 68,786 Views · 2 Likes
article thumbnail
A Swift Node Based User Interface Component for iOS
This post looks at how you could implement ShinpuruNodeUI in your own app.
September 14, 2015
by Simon Gladman
· 8,043 Views · 2 Likes
article thumbnail
Use MTOM to Efficiently Transmit Binary Content in SOAP
JSON-based REST services are en vogue, but when it comes to integrating enterprise services, SOAP is still widely used.
September 13, 2015
by Ralf Stuckert
· 62,694 Views · 3 Likes
article thumbnail
From JSON Web Token to Single Sign-On Part 1: Creating the Token
This is the first entry in a series of articles that offer a solution to Single Sign-on using the JSON Web Token (JWT) standard.
September 13, 2015
by Basel Almustafa
· 51,020 Views · 6 Likes
article thumbnail
MySQL is a Great NoSQL Database
At Wix engineering, we’ve found that in most cases we don’t need a NoSQL database, and that MySQL is a great NoSQL database if it’s used appropriately.
September 12, 2015
by Aviran Mordo
· 19,626 Views · 6 Likes
article thumbnail
Angular 2 vs. Angular 1: Key Differences
Recently, the Developer Preview of Angular 2 was released. This has some essential changes compared to Angular 1.
September 11, 2015
by Eelco Muller
· 436,837 Views · 17 Likes
article thumbnail
Java 8 Stream Performance Benchmarks
Learn all about Java stream performance with benchmarking and awesome metrics.
September 11, 2015
by Nicolai Parlog
· 14,436 Views · 4 Likes
article thumbnail
How to Set Up a Private Maven Repository in Amazon S3
Learn how to use Amazon S3 to keep private Maven artifacts to ensure your .jar files are visible only by your team.
September 9, 2015
by Yegor Bugayenko
· 9,615 Views · 3 Likes
article thumbnail
What is NW.js?
NW.js is a framework for building desktop applications with HTML, CSS, and JavaScript. It was created by Roger Wang at Intel’s Open Source Technology Center in China, and worked by combining the Node.js programming framework with Chromium’s (then) browser engine - Webkit, hence the original name Node Webkit. By combining Node.js with Chromium, Roger found a way to create applications that could not only load a local web site within an application window, but also could interact with the Operating System via a JavaScript API. This JavaScript API could control visual aspects like window dimensions, toolbar and menu items, as well as provide access to local files on the desktop. These are things that can’t be done with a hosted web site, or even a locally hosted web site. Below is an example of how an example application works. In the example illustrated above, the application’s files resemble those of a simple web site. The index.html web page is like most other web pages that you’ve seen - there is some HTML code for the page’s content, a link tag for the CSS stylesheet, and a script tag for the JavaScript. At this stage it’s identical to a website, and if you were to open it in a web browser it would work the same as it would in NW.js. There is also a CSS stylesheet for styling the contents of the index.html file, and an app.js file for executing JavaScript, in this case calling a simple dialog box with the text “from NW.js” inside of it. You’ll also notice a package.json file as well. This is the manifest file used by Node.js to load applications and libraries, and NW.js uses it to store configuration information about the desktop application. It is required by NW.js for the application to load. The NW.js application is able to load an application with a given path of the folder where the files live. It looks for the package.json file, which points to the index.html file to load, and thus loads the web page into what looks like a web browser embedded inside of an application window. This is what you can expect to see: The example application above could load inside of a web browser without any modifications, but where NW.js differs from a web browser is that where an app.js file could only interact with the index.html’s contents in the context of a web browser, NW.js allows the app.js file to interact with the Operating System through a custom JavaScript API, as well as through Node.js. This is unlike web frameworks where the front-end code and the back-end code traditionally exist and execute in separate places. The idea of front-end and back-end code existing and executing in the same place is the key concept to grasp here. In web applications, the back-end code is running from a server, and the page that is delivered to the browser on the user’s computer is limited as to what it can do on a user’s computer, due to the browser’s content security policy. With an NW.js desktop app, because the user has explicitly executed the application and it is running in a local context, then the content security does not apply. Also, the application has access to both the page as well as the computer’s resources, through an API to interact with the Operating System, allowing the code to interact not only with the front-end part of the application, but also the back-end part of the application (the computer in this case as no external server serves the desktop app). In the next section we’ll explore how this works in a bit more detail. Interacting with the Operating System NW.js provides a JavaScript API for interacting with the Operating System, so that you can do the following: Control the size and behavior of the application’s window Display a native toolbar on the application window, with menu items Add context menus in the application window area on right-click Add a tray application item in the Operating System’s tray menu Access the Operating System clipboard; read the contents and even set the contents as well Open file, folders and URLs on the computer using their default applications Insert notifications via the Operating System’s notification system. As you can see from the list, there are a lot of things that you can do within NW.js that web browsers cannot do. For example, web browsers do not have direct access to files on the desktop or the contents of the clipboard, due to security restrictions that web browsers implement to protect users from sites with malicious intent. In the case of NW.js, because the application runs on the user’s computer, it is granted a level of access where the user trusts the application, and therefore it can do a lot more things[p1] .These features allow the developer to create desktop applications that fit well into how the user’s Operating System works, and don’t stick out like a sore thumb to the user.You can think of NW.js as being like an application with an embedded web browser, that allows the contents of the site to also have access to the computer. Below is a diagram illustrating this: The JavaScript API for these features provided by NW.js can be accessed by the same JavaScript file that is interacting with the front-end web page inside of the application, again blurring the lines between front-end and back-end code, a concept that is unusual for those who are used to building web applications. The JavaScript API for the Operating System isn’t the only back-end API exposed to the developer, it can also use Node.js. Using Node.js with the application Node.js is a server-side programming framework that was created by Ryan Dahl back in 2009. It uses the V8 JavaScript engine used by the Google Chrome web browser along with some other components to let developers write server-side programs using JavaScript. Since its creation, Node.js has become a very popular programming framework, spawning a number of web frameworks, robotics tools, and in the case of NW.js, desktop application frameworks. The popularity of Node.js is down to a number of factors; JavaScript as a programming language is very common among web developers, and that lowers the barrier for developers to pick it up and work with it. Secondly, the package manager for Node.js (NPM) has made it easy for users to create modules that can be easily installed and loaded into applications. Thirdly, the evented architecture of Node.js makes it fast and well suited for particular kinds of applications. NW.js provides access to Node.js’ API in the application, as well as leveraging modules that are installed with NPM. By doing this, not only can developers use a server-side programming framework that uses the same language as the front-end, but they can also leverage the huge and growing ecosystem of modules that exist in NPM. What is most interesting is that the Node.js code can be called in the same place as the JavaScript code that is interacting with the front-end of the application. This is a unique aspect of the way that NW.js combines Node.js with Chromium, and something that you’ll want to keep in mind when you’re working with NW.js applications. Building the application for multiple OSes One of the most useful features of NW.js is that you can build native executable applications for Windows, Mac OS X, and Linux using a single codebase for your desktop application. This is a time saver when trying to develop an application that has to work across multiple platforms. This also means that you can have greater control over how the application looks and feels, more so than you can when trying to support a website for multiple web browsers. The native executable is able to run on its own, and does not require the user to have any other software installed on his or her computer. This makes it easy to distribute the application to users, including on App Stores where some NW.js apps are sold. The process of building an application for a specific operating system involves a few command line arguments, but there are some tools that simplify the process for you, such as the node-webkit-buildertool, illustrated in the example below: Using the hello worldexample app shown in Fig 1, we’re able to use nodewebkit-builder’s nwbuild command to automate the steps of building the application for both Mac OS X and Windows. This can save a lot of time (especially if you’re having to make both 32-bit and 64-bit builds of the application), and prevent mistakes from being made when building the application. There is also the ability to build the application so that the source code is compiled. This protects the source code so that other developers can’t inspect the code and reverse-engineer it. If you have an application and you’re concerned that other developers might try to copy it, then this option offers the ability to protect your application. With features like this, NW.js is a sophisticated tool for creating desktop applications, and knowing how it works under the hood helps you to understand what kind of applications you can build with it.
September 8, 2015
by Paul Jensen
· 37,986 Views · 5 Likes
article thumbnail
JDBI, a Nice Spring JDBC Alternative
If you’re looking into doing plain JDBC work and need something different than JDBC template, have a look at JDBI. Here's how you can use it as a JDBC alternative.
September 6, 2015
by Lieven Doclo
· 29,311 Views · 7 Likes
article thumbnail
Selenium: Design Patterns
Selenium WebDriver is widely used as a first-choice framework when it comes to testing web applications. In this article I would like to introduce you to two design patterns, that work great with selenium tests. In this post we will dig into Page Object pattern and combine it with Page Factory. As always, whole code for project is available on my github. Page Object Pattern Page Object is a concept that helps to reduce the number of duplicated code, and helps with test maintenance, resulting from changes in the structure and functionality of the web application. The main idea behind page object is to place the code relating to the functionality of subpages in separate classes. In a very simplified way, if your web application includes pages: home about contact We should create three separate page object classes: Home.java About.java Contact.java Each class should contain only those methods that support functionality for the corresponding subpage, and define selectors only for this subpage. We should also remember, that public methods in page object class are only those, that represents user’s workflow. One important point is that each public method in page object class should return object of page that user is on. For example, if a button on the page does not gets you to different subpage, this method should return this. Moreover, if a button is a link to another page, the method should return page object class of this subpage. Here is a code snippet of this approach using an example from previous article, where we wrote tests for Facebook login: public class LoginPage { private static By userEmailLoginInput = By.id("email"); private static By userPasswordLoginInput = By.id("pass"); private static By loginSubmitBtn = By.id("u_0_n"); private WebDriver driver; public LoginPage(WebDriver driver) { this.driver = driver; driver.get("http://facebook.com"); } public LoginPage enterUserLogin(String login) { WebElement emailBox = driver.findElement(userEmailLoginInput); emailBox.click(); emailBox.sendKeys(login); return this; } public LoginPage enterUserPassword(String password) { WebElement passwordBox = driver.findElement(userPasswordLoginInput); passwordBox.click(); passwordBox.sendKeys(password); return this; } public HomePage submitLoginCredentials() { WebElement submitBtn = driver.findElement(loginSubmitBtn); submitBtn.click(); return new HomePage(driver); } } In above example, methods enterUserLogin() and enterUserPassword() don’t transfer user to another subpage, but perform activities on the login page, so return type is object of LoginPage class (this). On the other hand, submitLoginCredentials() method moves user to home page (or to the page informing about the login failure), so it returns home page class object. In real life example, in HomePage.class we would have had methods that perform actions on the home page, but since it’s only an example code demonstrating pattern usage, we have only checkIfLoginSucceed() method here: public class HomePage { private WebDriver driver; public HomePage(WebDriver driver) { this.driver = driver; } public boolean checkIfLoginSucceed() { return driver.getPageSource().contains("fbxWelcomeBoxName"); } } …and test looks as follows: @Test public void shouldNotLoginWithIncorrectCreds() { LoginPage loginPage = new LoginPage(driver); loginPage.enterUserLogin("[email protected]"); loginPage.enterUserPassword("wrongPassword"); HomePage homePage = loginPage.submitLoginCredentials(); assert (!homePage.checkIfLoginSucceed()); } Page Factory pattern The main idea behind this pattern is to support page object classes, and to allow better page selectors management. Page Factory provide us with a set of annotations, which work great with selectors and enhance code readability. To understand this, let’s look at a standard initialization webelement through the selector: private static By email = By.id(“email”); WebElement emailBox = driver.findElement(email); Unfortunately, the readability leaves much to be desired. The problem is also that variable with selector and web element object require a separate initialization. Along with Page Factory, this is greatly simplified: private WebElement email; That’s all! Page Factory search page source code for element with id=”email” by default and assigns it to declared webelement. Of course, this minimalism can introduce some confusion, and therefore I recommend the use of @FindBy annotation: @FindBy(id = “email”) private WebElement userEmailLoginInput; We can also search selectors by other attributes, such as xpath, name, className, etc. Everything we have to do to use this pattern, is to initialize PageFactory in the page object class constructor: PageFactory.initElements(driver, this); Our LoginPage.class with page factory pattern will look like this: public class LoginPage { @FindBy(id = "email") private WebElement userEmailLoginInput; @FindBy(id = "pass") private WebElement userPasswordLoginInput; @FindBy(id = "u_0_n") private WebElement loginSubmitBtn; private WebDriver driver; public LoginPage(WebDriver driver) { this.driver = driver; driver.get("http://facebook.com"); PageFactory.initElements(driver, this); } public LoginPage enterUserLogin(String login) { userEmailLoginInput.click(); userEmailLoginInput.sendKeys(login); return this; } public LoginPage enterUserPassword(String password) { userPasswordLoginInput.click(); userPasswordLoginInput.sendKeys(password); return this; } public HomePage submitLoginCredentials() { loginSubmitBtn.click(); return new HomePage(driver); } } Important thing to notice is that every time we call a method on web element, page factory search for our element all over again through page sources. If page isn’t AJAX-based, we can use page factory cache to search an element only with page factory initialization, and then retrieve it from cache: @FindBy(id = “email”) @CacheLookup private WebElement userEmailLoginInput; Summary As in every aspect of software development, design patterns in test automations help us to develop tests faster and more efficient. Page Object and Page Factory are two simple patterns, that significantly improve maintenance and readability of selenium tests. For complete sources of examples in this article please visit my github. If you have any questions, feel free to leave a comment!
September 5, 2015
by Łukasz Rosłonek
· 10,254 Views · 5 Likes
article thumbnail
Going to Mars: Building a DIY Eclipse IDE for ARM Embedded Microcontrollers
Using the latest Eclipse IDE to work with ARM Cortex M based devices
September 5, 2015
by Erich Styger
· 4,298 Views · 1 Like
article thumbnail
Using JAX-RS With Spring Boot Instead of MVC
It’s easy to integrate JAX-RS into Spring applications, but why would you do this? Spring MVC should be enough, right?
September 4, 2015
by Lieven Doclo
· 103,652 Views · 13 Likes
  • Previous
  • ...
  • 779
  • 780
  • 781
  • 782
  • 783
  • 784
  • 785
  • 786
  • 787
  • 788
  • ...
  • Next
  • RSS
  • X
  • Facebook

ABOUT US

  • About DZone
  • Support and feedback
  • Community research

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 215
  • Nashville, TN 37211
  • [email protected]

Let's be friends:

  • RSS
  • X
  • Facebook
×