Skip to main content

Posts

Showing posts from July, 2017

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 automatically create default construc

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 to database Ann

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 block 

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 the

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 administration console and you can acces

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) Then use default suggestions and

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 defined text $("p")

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 strict mode: &q