Showing posts with label Face Interview. Show all posts
Showing posts with label Face Interview. Show all posts

Wednesday, August 5, 2015

Parameters File in Oracle

A Parameter is a key Value Pair
i.e db_block_size, db_name each contain a value in a files.

Types of parameter:

tns.ora parameter files: There are some parameters related to network. This file maps the net services to connect with network.

Listener.ora Parameter: is a file tells on which port to be connected for accessing DB.

Database parameters: its known as init.ora. It consists the parameters that required to start the database. Normally init.ora file reside with the name concating with the Site Identifier Name(SID). If the database SID is XE. then the init file name is initXE.ora. If we check this file we will get some parameters which suggest how the database will be configured.[Its like the blueprint of a home]. It contains some default parameters. But there parameters are the basic parameters must be in this file is Control File, DB_BLOCK_SIZE, DB_NAME. As this file is needed for the start of the database, we can use it as:

startup pfile=initXE.ora


We can change the name of the init.ora file for different types of requirements. Sometimes it makes confusion for multiple existence of the same file. Another problem is as this file is editable using text editor, for any unwanted mistake file may not be  updated with the correct value. Then for the corrupted file, DB wont start up properly. To get rid from such type of problem, starting from the Oracle 9i, Oracle introduces another file called SP file[System Parameter]. It may reside only one copy and another things its a binary file. And you are not able to change it manually. Only oracle can modify it. and for modifying it we next execute command for it. All the parameters are saved in a dynamic performance table named v$parameter. To get the value of a parameter, after connecting to DB through sqlplus, we can execute


desc v$parameter;

in this file we will get more than 250 parameters.

Select value from v$parameter where name='sql_trace'; || or || show parameter sql_trace


We can modify the value of parameter. And for the effecting it we can follow two steps:

alter system set sql_trace=true scope=memory;

using the above query, we are changing the parameter value until the running the database.

scope memory: until the instance will be shutdown
scope sp file: it will preserve the value in the SP file. It will be effected after restartigng the database
scope both: it will effect the change immediately in all places


In two ways we can get back after corruption of SP file. By using the unix command strings, we can get all those key value pairs those can be stored init.ora file. We can start database through it. And after that we can create SP file from it.

Whenever a database start all the non default parameter are put into a file named alert.log From that file we can check those. From that file we can create a (anyname.)ora file, and after starting using this file we can create SP fiel from the init file.

Tuesday, August 4, 2015

File system in Oracle Database

Different types of database files.

1.Parameter Files:  It tells how the instance is configured that how big the SGA. at the start up data base, it uses the parameter file for  configurations. It also tells how my Database process in the DB writer.

2. Data files: This stores all of the data of user. Such as tables, table data are being consisted by Data files. Its a operating system file. Each database must contain at least one datafile.

3. Redo log files:  Its the transaction log of database. When any operation is being performed at database, then a transaction is being created at Redo log files. Using Redo log files we can recover the Database for instance or media failure. It contains all the information for revert back of database.

4. Control Files: It tells the instance where the datafiles and redo log files exist. Instance read the control files information to locate where those files. For the importance of its role, 4 copy of control files are saved. Its called Multiplexing of control files.

5.Temp Files:  For
 the temporary requirement of some operation, instance need some temporary storage. Temp files arrange that space. i.e for order by query processing purpose, it might be needed.


6. Password Files: its used to authenticate users performing administrative [Start up/ Shut down Database]task over network.

7. Trace Files/Alert Log: There are many background process running behind the database. For various purpose to get the status of those process, we can take help of trace files. As for unexpected error or failure, trace file contain the status of those services.

Wednesday, June 17, 2015

CORS : Cross-Origin Resource Sharing

The future of the web is cross-domain, not same-origin. As CORS continues the spirit of the open web by bringing API access to all.


The same-origin policy is an important security concept implemented by web browsers to prevent Javascript code from making requests against a different origin (e.g., different domain) than the one from which it was served.


Cross-Origin Resource Sharing (CORS) is a specification that enables truly open access across domain-boundaries. The spec defines a set of headers that allow the browser and server to communicate about which requests are (and are not) allowed. CORS is a technique for relaxing the same-origin policy, allowing Javascript on a web page to consume a REST API served from a different origin.

Simple implementation:


In the simplest scenario, cross-origin communications starts with a client making a GET, POST, or HEAD request against a resource on the server. In this scenario, the content type of a POST request is limited to application/x-www-form-urlencoded, multipart/form-data, or text/plain. The request includes an Origin header that indicates the origin of the client code.


The server will consider the request's Origin and either allow or disallow the request. If the server allows the request, then it will respond with the requested resource and an Access-Control-Allow-Origin header in the response. This header will indicate to the client which client origins will be allowed to access the resource. Assuming that the Access-Control-Allow-Origin header matches the request's Origin, the browser will allow the request.

On the other hand, if Access-Control-Allow-Origin is missing in the response or if it doesn't match the request's Origin, the browser will disallow the request.

For simple CORS requests, the server only needs to add the following header to its response:

Access-Control-Allow-Origin: *

It differs to implement CORS for specific platforms. Suppose for tomcat a minimal CORS configuration as:


<filter>
  <filter-name>CorsFilter</filter-name>
  <filter-class>org.apache.catalina.filters.CorsFilter</filter-class>
</filter>
<filter-mapping>
  <filter-name>CorsFilter</filter-name>
  <url-pattern>/*</url-pattern>
</filter-mapping>




N.B: Bear in mind that CORS is not about providing server-side security. The Origin request header is produced by the browser and the server has no direct means to verify it.



Tuesday, June 16, 2015

Concurrency &. Parallelism

For the case of multi threaded programs we often use these terms, concurrency and parallelism.

Multiple tasks are in progress at the same time refers to concurrency. An application may process one task at at time (sequentially) or work on multiple tasks at the same time (concurrently).

Each task is broken in to sub tasks which can be processed in parallel. It is related to how an application handles each individual task. An application may process the task serially from start to end, or split the task up into subtasks which can be completed in parallel.

  • An application can be concurrent, but not parallel. This means that it processes more than one task at the same time, but the tasks are not broken down into subtasks.
  • An application can also be parallel but not concurrent. This means that the application only works on one task at a time, and this task is broken down into subtasks which can be processed in parallel.
  • Additionally, an application can be neither concurrent nor parallel. This means that it works on only one task at a time, and the task is never broken down into subtasks for parallel execution.
  • Finally, an application can also be both concurrent and parallel, in that it both works on multiple tasks at the same time, and also breaks each task down into subtasks for parallel execution. However, some of the benefits of concurrency and parallelism may be lost in this scenario, as the CPUs in the computer are already kept reasonably busy with either concurrency or parallelism alone. Combining it may lead to only a small performance gain or even performance loss. We should analyze and measure deeply before we adopt a concurrent parallel model blindly.

Friday, June 12, 2015

Cloud: IaaS, PaaS, SaaS

Cloud computing is the phrase used to describe different scenarios in which computing resource is delivered as a service over a network connection (usually, this is the internet). Cloud computing is therefore a type of computing that relies on sharing a pool of physical and/or virtual resources, rather than deploying local or personal hardware and software.

IaaS:

Infrastructure as a Service (IaaS) is one of the three fundamental service models of cloud computing alongside Platform as a Service (PaaS) and Software as a Service (SaaS). As with all cloud computing services it provides access to computing resource in a virtualised environment, “the Cloud”, across a public connection, usually the internet. In the case of IaaS the computing resource provided is specifically that of virtualised hardware, in other words, computing infrastructure. The definition includes such offerings as virtual server space, network connections, bandwidth, IP addresses and load balancers. Physically, the pool of hardware resource is pulled from a multitude of servers and networks usually distributed across numerous data centers, all of which the cloud provider is responsible for maintaining. The client, on the other hand, is given access to the virtualised components in order to build their own IT platforms.
In common with the other two forms of cloud hosting, IaaS can be utilised by enterprise customers to create cost effective and easily scalable IT solutions where the complexities and expenses of managing the underlying hardware are outsourced to the cloud provider. If the scale of a business customer’s operations fluctuate, or they are looking to expand, they can tap into the cloud resource as and when they need it rather than purchase, install and integrate hardware themselves.


PaaS:

Platform as a Service, often simply referred to as PaaS, is a category of cloud computing that provides a platform and environment to allow developers to build applications and services over the internet. PaaS services are hosted in the cloud and accessed by users simply via their web browser. 
Platform as a Service allows users to create software applications using tools supplied by the provider. PaaS services can consist of preconfigured features that customers can subscribe to; they can choose to include the features that meet their requirements while discarding those that do not. Consequently, packages can vary from offering simple point-and-click frameworks where no client side hosting expertise is required to supplying the infrastructure options for advanced development.
The infrastructure and applications are managed for customers and support is available. Services are constantly updated, with existing features upgraded and additional features added. PaaS providers can assist developers from the conception of their original ideas to the creation of applications, and through to testing and deployment. This is all achieved in a managed mechanism.
As with most cloud offerings, PaaS services are generally paid for on a subscription basis with clients ultimately paying just for what they use. Clients also benefit from the economies of scale that arise from the sharing of the underlying physical infrastructure between users, and that results in lower costs.
Below are some of the features that can be included with a PaaS offering:
  • Operating system
  • Server-side scripting environment
  • Database management system
  • Server Software
  • Support
  • Storage
  • Network access
  • Tools for design and development
  • Hosting
Software developers, web developers and businesses can benefit from PaaS. Whether building an application which they are planning to offer over the internet or software to be sold out of the box, software developers may take advantage of a PaaS solution. For example, web developers can use individual PaaS environments at every stage of the process to develop, test and ultimately host their websites. However, businesses that are developing their own internal software can also utilise Platform as a Service, particularly to create distinct ring-fenced development and testing environments.

SaaS?

SaaS, or Software as a Service, describes any cloud service where consumers are able to access software applications over the internet. The applications are hosted in “the cloud” and can be used for a wide range of tasks for both individuals and organisations. Google, Twitter, Facebook and Flickr are all examples of SaaS, with users able to access the services via any internet enabled device. Enterprise users are able to use applications for a range of needs, including accounting and invoicing, tracking sales, planning, performance monitoring and communications (including webmail and instant messaging).
SaaS is often referred to as software-on-demand and utilising it is akin to renting software rather than buying it. With traditional software applications you would purchase the software upfront as a package and then install it onto your computer. The software’s licence may also limit the number of users and/or devices where the software can be deployed. Software as a Service users, however, subscribe to the software rather than purchase it, usually on a monthly basis. Applications are purchased and used online with files saved in the cloud rather than on individual computers.

Sunday, April 19, 2015

Classification of Design Pattern in Software Development

Classification of  Software Design Pattern
Purpose
[reflects what a pattern does]
Creational
[concern the process of object creation]
Structural
[deal with the composition of classes or objects]
Behavioral
[characterize the ways in which classes or objects interact and distribute responsibility]
Scope
[specifies whether the pattern applies
primarily to classes or to objects]
Class
[deal with relationships between classes and their subclasses. These relationships are established through inheritance, so they are static—fixed at compile-time
]
Factory Method

[Class-creational patterns deal with Class-instantiation. They defer their object creation to subclasses.]
Adapter

[The Structural class
patterns use inheritance to compose classes]
Interpreter
Template Method

[Behavioral class patterns use inheritance to describe algorithms and flow of control]
Object
[Object patterns deal with object relationships, which can be changed at run-time and are more dynamic]
Abstract Factory
Builder
Prototype
Singleton

[Object-creational patterns deal with Object creation. They defer the part of their object creation to another object]
Adapter
Bridge
Composite
Decorator
Facade
Flyweight
Proxy

[the Structural object patterns describe ways to assemble objects]
Chain of Responsibility
Command
Iterator
Mediator
Memento
Observer
State
Strategy
Visitor
[the Behavioral object patterns describe how a group of objects cooperate to perform a task that no single object can carry out alone]

Thursday, April 16, 2015

Design Patterns

Design patterns are useful because they provide a pre-formulated solution to problems based on the experience of other programmers. This can save you a lot of time.
Design patterns also help in communication of a programming solution, and provide a common technical vocabulary between programmers.
Design pattern and Framework are not same thing. Design patterns are more like general guidelines on how to solve specific programming problems, but they do not specify the detailed code that’s necessary to solve those problems.
 Of course, using the wrong design pattern can have a very negative effect on your code. So, it takes good judgement to use the correct design pattern. The term “anti-pattern” is used to describe a poor programming practice that leads to ineffective code.

In general, a pattern has four essential elements:
1.The pattern name is a handle we can use to describe a design problem
2.The problem describes when to apply the pattern. It explains the problem and its context.
3.The solution describes the elements that make up the design, their relationships, responsibilities, and collaborations.
4.The consequences are the results and trade-offs of applying the pattern.


We classify design patterns by two criteria (Table 1.1). The first criterion,  called purpose, reflects what a pattern does. Patterns can have either creational,  structural, or behavioral purpose. Creational patterns concern the process of  object creation. Structural patterns deal with the composition of classes or  objects. Behavioral patterns characterize the ways in which classes or objects interact and distribute responsibility.

The second criterion, called scope, specifies whether the pattern applies primarily to classes or to objects. Class patterns deal with relationships between classes and their subclasses. These relationships are established through inheritance, so they are static—fixed at compile-time. Object patterns deal with object relationships, which can be changed at run-time and are more dynamic. Almost all patterns use inheritance to some extent. So the only patterns labeled "class patterns" are those that focus on class relationships. Note that most patterns are in the Object scope.

Creational class patterns defer some part of object creation to subclasses, while Creational object patterns defer it to another object. The Structural class patterns use inheritance to compose classes, while the Structural object patterns describe ways to assemble objects. The Behavioral class patterns use inheritance to describe algorithms and flow of control, whereas the Behavioral object patterns describe how a group of objects cooperate to perform a task that no single object can carry out alone.

Sunday, April 12, 2015

Perm Space in Java

It stands for permanent generation.

The permanent generation is special because it holds meta-data describing user classes (classes that are not part of the Java language). Examples of such meta-data are objects describing classes and methods and they are stored in the Permanent Generation. Applications with large code-base can quickly fill up this segment of the heap which will cause java.lang.OutOfMemoryError: PermGen no matter how high your -Xmx and how much memory you have on the machine.

The permanent Generation contains the following class information:
  • Methods of a class.
  • Names of the classes.
  • Constants pool information.
  • Object arrays and type arrays associated with a class.
  • Internal objects used by JVM.
  • Information used for optimization by the compilers.
‘Java.Lang.OutOfMemoryError: PermGen Space’ occurs when JVM needs to load the definition of a new class and there is no enough space in PermGen. The default PermGen Space allocated is 64 MB for server mode and 32 MB for client mode. There could be 2 reasons why PermGen Space issue occurs.
The 1st reason could be your application or your server has too many classes and the existing PermGen Space is not able to accommodate all the classes. And the 2nd reason could be memory leak. How the class definitions that are loaded could can become unused.

Friday, April 10, 2015

Heap Space in Java

When a Java program started Java Virtual Machine gets some memory from Operating System. Java Virtual Machine or JVM uses this memory for all its need and part of this memory is call java heap memory. Heap in Java generally located at bottom of address space and move upwards. whenever we create object using new operator or by any another means object is allocated memory from Heap and When object dies or garbage collected ,memory goes back to Heap space in Java.

1. Java Heap Memory is part of memory allocated to JVM by Operating System.


2. Whenever we create objects they are created inside Heap in Java.

3. Java Heap space is divided into three regions or generation for sake of garbage collection,called New Generation, Old or tenured Generation or Perm Space. Permanent generation is garbage collected during full gc in hotspot JVM.

4. You can increase or change size of Java Heap space by using JVM command line option -Xms, -Xmx and -Xmn. don't forget to add word "M" or "G" after specifying size to indicate Mega or Gig. for example you can set java heap size to 258MB by executing following command java -Xmx256m HelloWord.

5. You can use command "jmap" to take Heap dump in Java and "jhat" to analyze that heap dump.

6. Java Heap space is different than Stack which is used to store call hierarchy and local variables.

7. Java Garbage collector is responsible for reclaiming memory from dead object and returning to Java Heap space.

8. Don’t panic when you get java.lang.OutOfMemoryError, sometimes its just matter of increasing heap size but if it’s recurrent then look for memory leak in Java.

9. Use Profiler and Heap dump Analyzer tool to understand Java Heap space and how much memory is allocated to each object.



ArrayList, LinkedList, and Vector

ArrayList, LinkedList, and Vector are all implementations of the List interface.

ArrayList and Vector each use an dynamic array to store the elements of the list. Bother Vector and ArrayList are derived from AbstractList and implements List interface, which means both of them are ordered collection and allows duplicates. Another similarity between Vector vs ArrayList is that both are index based Collection and you can use get(index) method to retrieve objects from Vector and ArrayList. When an element is inserted into (or removed from) the middle of the list, the elements that follow must all be shifted accordingly. Vector is synchronized, so if a thread-safe implementation is not needed, it is recommended to use ArrayList rather than Vector.There is a different in Data Growth method for ArrayList and Vector also. When an element is inserted into an ArrayList or a Vector, the object will need to expand its internal array if it runs out of room. A Vector defaults to doubling the size of its array, while the ArrayList increases its array size by 50 percent.


LinkedList, on the other hand, is implemented using a doubly linked list. As a result, an inserting or removing an element only requires updating the links that immediately precede and follow the element being inserted or removed.


Among them, LinkedList is generally going to give you the best performance.

However, it is worth noting that if performance is that critical, it’s better to just use an array and manage it yourself, or use one of the high performance 3rd party packages such as Trove or HPPC.

Thursday, April 9, 2015

Java Collection


Some key information on Collection:

  • List can contain duplicate elements whereas Set contains only unique elements.
  • Set contains values only whereas Map contains key and values both.
  • HashSet maintains no order whereas TreeSet maintains ascending order.
  • HashSet contains only values whereas HashMap contains entry(key,value). HashSet can be iterated but HashMap need to convert into Set to be iterated.
  • HashMap maintains no order but TreeMap maintains ascending order.
  • Collection is an interface whereas Collections is a class. Collection interface provides normal functionality of data structure to List, Set and Queue. But, Collections class is to sort and synchronize collection elements.

Thread Safety in Java

Thread safety is the process to make our program safe to use in multithreaded environment, there are different ways through which we can make our program thread safe. Concurrent programming is bounded by the norms of thread safety.

Code that is safe to call by multiple threads simultanously is called thread safe. If a piece of code is thread safe, then it contains no race conditions. Race condition only occur when multiple threads update shared resources. Therefore it is important to know what resources Java threads share when executing.

Each thread has its own stack. Two different threads never shares the same stack. All local variables defined in a method will be allocated memory in stack. As soon as method execution is completed by the current thread, stack frame will be removed. So, local variables are thread safe in Java. If an object created locally never escapes the method it was created in, it is thread safe.Local references to objects are a bit different. The reference itself is not shared. The object referenced however, is not stored in each threads's local stack.


  • Synchronization is the easiest and most widely used tool for thread safety in java.
  • Use of Atomic Wrapper classes from java.util.concurrent.atomic package. For example AtomicInteger
  • Use of locks from java.util.concurrent.locks package.
  • Using thread safe collection classes, i.e ConcurrentHashMap for thread safety.
  • Using volatile keyword with variables to make every thread read the data from memory, not read from thread cache.

Tuesday, April 7, 2015

Life Cycle of Servlet

The following figure depicts a typical servlet life-cycle scenario.
  • First the HTTP requests coming to the server are delegated to the servlet container.
  • The servlet container loads the servlet before invoking the service() method.
  • Then the servlet container handles multiple requests by spawning multiple threads, each thread executing the service() method of a single instance of the servlet.

  • The servlet is initialized by calling the init () method.
  • The servlet calls service() method to process a client's request.
  • The servlet is terminated by calling the destroy() method.
  • Finally, servlet is garbage collected by the garbage collector of the JVM

Monday, April 6, 2015

JVM, Java Processor

Every Java program is first compiled into an intermediate language called Java bytecode. 
The JVM is used primarily for 2 things:

1. The first is to translate the bytecode into the machine language for a particular computer,
2.The second thing is to actually execute the corresponding machine-language instructions as well. 

The JVM and bytecode combined give Java its status as a "portable" language – this is because Java bytecode can be transferred from one machine to another.

Machine language is OS dependent

Given the previous information, it should be easier to figure out an answer to the original question. Since the JVM must translate the bytecode into machine language, and since the machine language depends on the operating system being used, it is clear that the JVM is platform (operating system) dependent – in other words, the JVM is not platform independent.

Almost all JVMs are implemented in software. However, a JVM is anything that interprets Java bytecode in a manner that complies with the JVM specification, and there are some hardware-based JVMs as well.
Java processor is the implementation of the Java Virtual Machine (JVM) in hardware. In other words the bytecodes that make up the instruction set of the abstract machine become the instruction set of a concrete machine. These are today the most popular form of a high-level language computer architecture.

Creating a thread in Java; Two ways; Why

To define a class that is a derived from the Thread class which is built into Java. An object of this derived class will be a thread. Thread class has a method called run, which you must override in order to have your thread do whatever you want it to do.

Java does not support multiple inheritance, which means that we can not derive from multiple classes at once. So, there may be a situation in which we want to create a thread, but we also want to derive from a class that is not the Thread class. For this reason, Java provides an alternative way of creating a thread – so that you don’t have to create a class that derives from the Thread class. Java provides an interface called Runnable that our class can implement in order to become a thread. The Runnable interface has only one method heading that we must implement .

Sunday, April 5, 2015

Difference between equals() and == in Java

Before discussing the difference between “==” and the equals() method, it’s important to understand that an object has both a location in memory and a specific state depending on the values that are inside the object.

In Java, when the “==” operator is used to compare 2 objects, it checks to see if the objects refer to the same place in memory.

The equals method is defined in the Object class, from which every class is either a direct or indirect descendant.By default equals() will behave the same as the “==” operator and compare object locations. But, when overriding the equals() method, you should compare the values of the object instead.

In Java, == always just compares two references (for non-primitives, that is) - i.e. it tests whether the two operands refer to the same object.
However, the equals method can be overridden - so two distinct objects can still be equal.
For example:
String x = "hello";
String y = new String(new char[] { 'h', 'e', 'l', 'l', 'o' });

System.out.println(x == y); // false
System.out.println(x.equals(y)); // true
Additionally, it's worth being aware that any two equal string constants (primarily string literals, but also combinations of string constants via concatenation) will end up referring to the same string. For example:
String x = "hello";
String y = "he" + "llo";
System.out.println(x == y); // true!
Here x and y are references to the same string, because y is a compile-time constant equal to "hello".