Skip to main content

Posts

Showing posts from 2017

Sorting Algorithms

Bubble Sort Named as sinking sort. Compare each pair of the adjacent items and swap them if they are in the wrong order. Worst case and average case time complexity both O(n^2)  and best case time complexity is O(n).

JDBC- Java

JDBC allows java applications to connect to relational databases. Database can be reside in local, network or cloud. JDBC Features Provide portable access to various databases Can build custom sql statements JDBC Supported Databases MySQL Oracle DB2 PostgreSQL Key Classes of JDBC java.sql.DriverManager java.sql.Connection java.sql.Statement java.sql.ResultSet java.sql.DataSource JDBC Development Process Get a connection to the database ex :  jdbc:<driver protocol>:<driver connection details> Create a statement object Execute the Query Process the result set

Object Oriented Programming (OOP)

Object Object is an entity that has state and behavior Class Collection of objects is known as class. There are four main types of OOP concepts Inheritance Object acquire all the properties and behavior of parent object Improve code re-usability Polymorphism One task is performed by different ways Use method overload and override Abstraction Hiding internal details and showing functionality Use abstract class and interfaces Encapsulation Binding code and data into a single unit

JEE

JEE stands for Java Enterprise Edition. JEE can use for business, web, client and information applications. JEE Applications Web components - JSP,Servlets Web services - JAX/WS, JAX/RS Data access in Java - JDBC/JPA Persist and entities and enterprise Java beans To create JEE project in Eclipse  Create Dynamic Web Project Under the web contents create your web pages (html files) You can use Apache Tomcat server to deploy your web application. To change URL  To change the URL of servlets that you have built, you have to configure web.xml file. As an example, you have to add following lines to your web.xml file   <servlet>   <servlet-name>helloworld</servlet-name>   <servlet-class>com.amali.surverlet.HelloWorld</servlet-class>   </servlet>   <servlet-mapping>   <servlet-name> helloworld</servlet-name>   <url-pattern>/hidden/hello.do...

Core Java Concepts

Java Applications  There are mainly four types of Java applications. Standalone Web  Enterprise  Mobile Java Features  There are several features in Java, but in here listed some important ones Platform independent Object oriented Multi threaded Distributed Robust (automatic garbage collection, exception handling, type checking) Java Security  Java has 3 built-in security components; Classloader: Separate class files packages from imported packages. BytecodeVerifier: check the illegal access to objects Security Manager: check what resources can access the object. C++ vs Java Methods Static - No need to create an object to invoke the static method. Constructor - use to initialize objects Constructor name must same as the class name Constructor has no return type There are two types of constructors Default - no parameter Parameterized If there is no constructor defined in the class, compiler aut...

Hibernate

Hibernate is an ORM (Object Relational Mapping) tool which is primarily used in the data layer. Object Relational Mappings Problems There are several problems can occur when you are trying to save objects in the database from the scratch without using Hibernate. Mapping member variables to columns Mapping relationships Handling data types Managing changes to an object Set Up the Development Environment  Following steps are briefly pointed out how to set up Hibernate on your local machine. Download the hibernate jar files Create a project in Eclipse Right click on the project name and go to properties Navigate to libraries tab Add library and import jar files (lib-> JPA/required) Add Postgres JDBC driver as jar file Configurations After you set up the Hibernate you have to create hiberante.cfg.xml file and do some configurations like setup database details, entity class, etc. Dialect: Define what kind of language should use to talk...

Java- Interview

Here are some popular tips in Java General Question JVM - Java Virtual Machine. Used to execute byte code. Platform dependent (but byte code is platform independent) JRE- Java Run time Environment. It provides run time environment and it's the implementation of JVM. It contains libraries and files that need to execute JVM.   JDK- Java Development Kit. It contains JRE and development tools. Why java doesn't support pointers: It's insecure and complex to understand We can save java file with another name if class is not defined as public Java use camalCase notation for objects naming (ex: firstName) OOP Concepts Related  Aggregation: weak relationship (bike has an indicator) Composition:  strong relationship (bike has an engine) GUI Java GUI - Install Window builder to create GUI using Eclipse IDE Code Related No issues when you write static public void instead of public static void We can execute program without main method : using static bloc...

Java-8

Java 8 New Features There are several new features added in Java 8 version. Some of the important new features are: Define methods inside the interface For each method Lambda Expression Stream API DateTime API 1) Define methods (default, static) inside the Interface After you published your interface, you can't change it by adding some abstract methods. But if you want to add methods you can define those methods inside the interface. Therefore Java 8 support default and static methods inside the interface. In Java 7 version interface only have abstract methods (no method implementation) and an abstract class can have both abstract and non-abstract methods. In Java 8 version you can add method implementation in the interface, but you have to declare that method as default method. ex: default void show(){............} To avoid diamond problem you have to override the method in implementation class if two interfaces have same default method ...

Model-View-Controller (MVC)

MVC(Model-View-Controller) is a software design pattern.It divided your applications into three components Model: Contain business rules and application Data View: Presentation layer (user interface) Controller: Handles the communication between view and model  Objectives of MVC Promote code usability Implement separation of concerns  Separate user interface and software logic Web Frameworks That Use MVC There are several web frameworks that use MVC design pattern.  Ruby On Rails (Ruby) Angular (JS) Django (Python) Express (JS) Flask (Python) Codeigniter (PHP) Simple UseCase for MVC In this use case scenario, Browser sends information that needs to create Employee Object, and Controller save that information in Model and Update the Employee View. Following Image shows the class diagram for above Scenario. Implementation:  https://github.com/kaosadi17/MVC

AngularJS

AngularJS is a JavaScript framework that can be added to HTML page using <script> tag. AngularJS Usages Client side JavaScript Framework. Extend HTML so you can create more dynamic contents Declarative vs Imperative  There are two main programming paradigms used in programming as imperative programming and declarative programming. Declarative: Tells you what to do  You use the declared functions by someone for your needs Imperative: Tells you how to do You develop the functionalities for your needs AngularJS is both declarative and imperative language.  Scope A scope is an object and it stores all the variables and their values. Each time you create a new controller, Angular automatically create new scope object. Module A module is a collection of directives, controllers and other stuff. Create a module var myModule = angular.module("myMod",[]); array contain list of other modules that the defined module depend upon Use...

Apache Tomcat- Ubuntu

Tomcat is a web-container that allows to run servelet and Java Server Pages (JSP) based web applications. Tomcat Usages A container that allows running web applications. Can use as HTTP server(default port : 8080) Installation Follwing steps are described to install Tomcat7 in Ubuntu OS using terminal. sudo apt-get install tomcat7 sudo apt-get install tomcat7-admin sudo apt-get install tomcat7-docs sudo apt-get install tomcat7-examples Start/Stop Tomcat Server In Ubuntu after istalling Tomcat server it will start automaticaly. But if you want to restart the server you can use follwing command sudo /etc/init.d/tomcat7 restart If you want to stop the Tomcat Server you can issue following command. sudo /etc/init.d/tomcat7 stop Test The Server After starting the Tomcat server you can check it by entering the following URL in the brower http://localhost:8080 Admin Console  Tomcat provides a web based administrat...

Maven

Maven is a software project management and comprehension tool, based on the concept of project object model. Maven Usages Build the code in the development environment (compile the source code, run the test cases and packaging the project) Project management tool Generate reports Dependency management Installation Steps You can install Maven by following below steps .  Manual Installation Download Maven binary file Create some environment variables M2_HOME = environment point to maven directory PATH = append Maven path until bin to path variable Using Ubuntu Terminal sudo apt-get install maven To check Maven is successfully installed, issue the following command mvn --version To create a Maven project using Terminal use following steps mkdir myApp cd myApp/ mvn archetype:generate : choose archetype for the project  groupId: org.amali.myProject (like package name) artifactId: MavenTestApp (like class name) The...

Introduction to JQuery

JQuery Open source JavaScript library. Cross browser compatibility Include the JQuery code inside this function       $(document).ready(function(){             your code is here             }); Creating CSS element : nothing added (body{}) class name : added fullstop (.clzname{}) id : added slash (#idname{}) JQuery Methods  click(): can include actions when after clicking defined button $("button").click mouseover: can include actions when over the mouse on defined element $(button').mouseover hover : can include tow functions when the mouse is over it and not $("img").hover load : execute when complete page is fully loaded  $("img").load JQuery Actions hide() : hide the defined content $("#right").hide() html() : change the html element with defined content $("p").html("<p>My content<p>") text() :  change the content as define...

JavaScript Objects and Prototypes

Create Objects Using function Create Objects without duplication code: use functions Using constructors To indicate a function is a constructor:  append new keyword in front of the function name when executing it Call Property of function object foo.call() = foo() Call can bind different objects and can execute functions __proto__ Copy of prototype object If some property is not in the object itself, it then looks it in the prototype. If it finds it returns the value of that property All the new object instances of function point to same prototype object prototype.constructor: property that points to function  GitHub repo:  https://github.com/kaosadi17/JavaScript/blob/master/objects%26prototypes.js

JavaScript- Scopes and Closures

Scope The scope is the set of variables, objects, and functions you have access to. Create Scope  Use functions Declaring Variables  If you do write operation without declaring variable -> work fine foo = 10; console.log(foo);  -> 10 If you do read operation without declaring variable -> doesn't work fine console.log(foo) -> syntax error Window Object Inbuilt object provided by JavaScript itself Every global variable and functions are part of window object JavaScript is both compilations and interpreted language Compilation: register variables, method names, arguments in global scope Interpretation: assign values to global scope and execute the code global scope problem: undeclared function inside the variable it goes to global scope Hoisting It doesn't matter where you declare your variable (In the compilation step it include all variables automatically before the interpretation) Strict Mode To get stri...

Introduction To JavaScript

JavaScript Language has following characteristics: Lightweight: Small memory footprint, easy to implement Interpreted: No compilation, Instructions executed only Object Oriented: Modeled around objects First-class functions: Functions used as variables and parameters Scripting language: Writing instructions for runtime environment JavaScript is used for  Client side web development Frameworks: JQuery, AngularJs, React, EServer-side Server-side web development Frameworks: NodeJS, Express Variable declaration and definition Declaration: Give a name to a variable Definition: Assign a value to the variable Equal operations  =: assigning value to a variable (a=30) ==: check the values (doesn't consider types) ===: check the values and types Functions:  no overloading functions are objects functional expression : assign function to variable anonymous function: function with no name Array methods push(value): value is appe...

Developing Restful-API using JAX-RS

Web Services  Services that are exposed to the Internet for programmatic access.  Two main types of web services REST (Representational State Transfer) REST has no standard protocol (can use XML,JSON,etc) SOAP Web services use HTTP (Hyper Text Transfer Protocol) to send and receive messages. To include service definitions that offered from Web Service: WSDL URI Two main types of URI Resource Based URI Every resource must be identified by a single URI  Doesn't contain .do in URI ( /message/{message_Id}) Collection URI return collection of instances ex : /message/1/comments -> return all the comments relevant to message id=1 To create new resource you have to use collection URI Filtering   /messages?offset=30&limit=10 -> return 10 messages starting from message_Id=30 HTTP Methods  Four main types of HTTP methods: Get: To get the details of resource Put: To update resources Post: To create ...