-
Scala OO programming by example
Scala both support OO and functional programming. Scala OO support builds on Java but with below differences:
No public class , so you can have more than one public class in a single file No file naming convention No static member but you can use companion objects as your static objects different way to declare constructors and interfaces Define class class someClass{ private var somePrivateVariable =0 def increment(){ somePrivateVariable+=1} def balance() = somePrivateVariable var someFields =0 } Call class var some = new someClass() some.
-
Scala basic syntax by example
All data types are objects and there are no primitives and you can call methods on an Int or a Long.
Scala Data Types Boolean Byte, Short, Int, Long Float, Double Char, String Unit(the 'void' type) Scala Variables Compiler can infer type, so if you does not assign type to variable it will automatically set it according to the value.
val n = 5 // type is int var f = 3.
-
Scala Language by example
What is Scala? it is a language that is invented by Martin Odersky and runs on the JVM (Java Virtual Machine) and helps you to write beautiful and powerful code in type-safe way.
Why Scala? It has Flexible syntax with Unified type system (no primitive). It has Type inference which automatically assign right value type to an expression.
It has extended OO support by adding trait and case classes to it.
-
Java RESTful service using jersey by example
What is jersey ? Jersey is an implementation of JAX-RS specification or in other words its java implementation of REST. Its use as service with REST pattern.
What is REST? REST build on the HTTP verbs such as POST, GET, PUT, DELETE. It can transfer data in a plain text, XML, JSON or binary octet such as pdf and images content.
RESTFul urls urls are heart of restful services and we always concentrate around nouns rather than verbs.
-
read property files in Spring
What are properties files ? Properties files help us to abstract out values from our project e.g. url , passwords. Moving away from hardcoding these values in the source code can help us to move our code easily between different environments.
how to read property file from Spring xml configuration create a property file make a file and name it anything e.g. app.someProperties and put your key value pairs there
-
Spring singleton vs prototype scope
What is singleton scope? Singleton is a default scope in spring application so its means that there is only one instance of our bean is available through the project by default.
You might still have more than 1 instance per jvm if you are running more than 1 project with your jvm.
How to do it ? To setting it up in a java project its really straightforward all you need to do is adding the annotation scope to your config file.
-
12 good points in code review
What is review? It is a visual inspection of (typically) source code by someone other than the author, in order to identify defects with the intention of rectifying those defects.
Why we need review ? find issues and fix them early in the software life cycle. early fixes helps us to save time and cost. it will improve code quality , code clarity , verification and validation of your product.
-
spring Java AutoWiring
You can automatically wiring interfaces with their implementation with java annotation in Spring. This way of auto wiring giving you a better understanding of how beans are wired together.
Wiring beans in configs appConfig
@Configuration @ComponentScan({"com.inadram"}) public class AppConfig { @Bean(name = "customerService") public CustomerService getCustomerService() { return new CustomerServiceImplementation(); } @Bean(name = "customerRepository") public CustomerRepository getCustomerRepository() { return new hibernateRepositoryImplementation(); } } @ComponentScan Add it to top of your configuration file to mark the start point of your app for looking for the beans.
-
Spring configuration using Java
What is it ? It is easier for developers to bind java beans with pure java and avoiding from using xml config files.
From Spring 3.0 onward most features of Spring can be configure just with Java.
How to use it ? It is looking for the files that have @configuration annotation rather than xml config files. @Bean will be used for method level annotation. Spring does not care for the class or method names and they can be anything.
-
Spring annotation using XML example
What is it ? It is another way to wire up beans in java application.
How is it works? setup applicationContext.xml similar to Spring XML configuration, we need to create our main xml config file.
applicationContext.xml
<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd"> </beans> Component Scanner We need to edit our applicationContext.xml file and specify the context of it.
context of xml file