Latest Entries »

Java interview questions

Most of people generally aware of basic Java interview questions, real test for candidates comes with Advanced java.

1) Difference between Countdown latch and Cyclic Barrier
2) Could you please describe Java memory model
3) how to improve performance of an application ?
4) Blocking/Non-blocking queue implementation ?
5) Difference between NIO Channels and Streams ?
6) What is ByteBuffer, DirectByteBuffer, MappedByteBuffer ?
7) How does Garbage Collector (GC ) affects the performance of an application. How to tune GC params to achieve better results.
8) What are the different types of Garbage Collectors ?
9) How to analyze GC behaviour of an application ?
10) Difference between Serial, Parallel, Concurrent GC ?
11)  What is Young/Eden space and how is it different from perm space ?  Does changing size of young/eden space affects the performance ?
12) What is Java Serialization ? how is it different from Externalizable ? Whats the significance of SerialVersionUID ? how does it matter if not provided , does it affect deserialization ?
13) What is volatile ? how is it related to out of order write in memory ?
14) What are non-blocking data structures ? Can you show how to implement non-blocking stack ?
15) What is biased locking and how it can improve performance of an application ?

 

Using NIO Channels

Channels can be unidirectional or bidirectional.

ReadableByteChannel which defines the read() method is unidirectionale
WritableByteChannel which provide write() is also unidirectional

ByteChannel which extends both ReadableByteChannel and WriteabByteChannel is bidirectional.

Channel instances may not allow read() or write() , depending on the access mode of the underlying file handle. Ex: A channel instance connected to a read-only file cannot write even though the class to which that channel instance belongs may have a write() method. NonWritableChannelException will be thrown in this case.

How to copy data between Channels:
ByteBuffer buffer = ByteBuffer.allocateDirect(16*1024);
FileChannel source = randomAccessFile.getChannel();
FileChannel dest  = randomAccessFile.getChannel();
While ( source.read(buffer) != -1 ) {
buffer.flip();
While (buffer.hasRemaining()) {
dest.write(buffer);
}
}

// clear buffer, to make it available to use again
buffer.clear();
}

 

 

 

Java NIO – Channels and selectors

Channels

A Channel is something similar to pipe/tube that transfers data between byte buffers and file/socket. Implementations of channel may be different between Operating Systems. They often use native code to get access to low level IO services.

Below is a simple Channel Interface

public Interface Channel{
public boolean isOpen();
public void close() throws Exception;

}

 

Opening Channels:
There are two types of channels , File Channel and Socket Channel

File Channel 
RandomAccessFile randomAccessFile = new RandomAccessFile(“fileName”, “r”);
FileChannel fileChannel = randomAccessFile.getChannel();


Socket Channel
1) SocketChannel  sc = SocketChannel.open();
sc.connect(new InetSocketAddress(“IPhost”, “port”));

2) ServerSocketChannel  ssc = ServerSocketChannel.open();
ssc.socket().bind(new InetSocketAddress(somelocalport));

3) DatagramChannel dc = DatagramChannel.open();

 

 

Java articles series

We are going to start new series of articles focused on JAVA related technologies and help students master all technology aspects to complete any software projects successfully.

We would start with Java basics and then would cover around advanced JAVA. Also related technology area like Spring, hibernate, Struts, Ruby On Rails, UML, design patterns, Java script, HTML5, Cloud computing, node.js would be covered.

Java 5 new features
Java memory model

Java NIO package
- Channels for IO
- Managing locks and memory mappings with file
- Blocking/ Non-blocking IO’s
- Selectors for multiplexing
- Buffering/ custom buffering

Multithreading
- concurrency collection libraries
- Executor framework
- Thread Pools
- Semaphors, Mutexes, Cyclic barries, countdown latch
- Atomic variables
- Thread priority

 

 

 

 

 

 

 

 

Java vs C Performance

Java vs C Performance..
You might have discussed this topic many times and wondered which is better.
Is C/C++ faster than Java ? Well, it depends…

Java:
1) Platform independent
2) Garbage collection feature from JVM frees users from worrying about memory management.
3) Multi-threading /concurrency libraries

C/C++ :

* C++ has smaller footprint.

*Very small startup time

*Direct machine access,

# On the fly code generation & execute. Its easy to execute same machine instructions on a simple RISC chip whereas Java needs JIT to do a good job with bytecodes.

# OS’s. These need lots of direct machine access (e.g. hardware interrupt support; page table support)

# Direct code generation with exact machine instructions will be generated from the C compiler.  This is harder to do in Java because the translation layer is much more indirect.

Job interview preparation

With increasing competition and number of students applying for jobs, its important to get concepts cleared.
Generally, students fresh out of colleges, jump into real world without being well equipped to face the challenges.
We always tend to follow crowd & end up getting failures leading to frustation.
Smart move would be to understand what skillsets required to crack interviews and getting equipped with right tools.
For someone coming from computer science background, its expected of applicant to know operating systems, databases, system programming concepts well.
Start by reading book “Multiple Choice questions in Computer Science” by Timothy Williams.

Always try to get concepts cleared on one subject rather than trying to know the whole bunch of areas.
Employers don’t want someone who is jack of all trades but master of none.
Try to get expertise in one particular area and show how you are different and ahead of others.
Need to prove your worth among thousands of aspirants.
I have seen many candidates who are good technically but really poor communication. If you can’t explain your thoughts clearly, its very difficult to make the mark. Do some mock interviews to analyse your weak areas.
Spend some time to fill the gaps and focus on your strengths.
Confidence plays crucial role in any job interview. Make it a point to be confident and get going.

@NagpurStudents

———————————————————–

Nagpur, Nagpur Students, NagpurStudents

———————————————————–

Hello Students!

Welcome to Nagpur students website. http://www.nagpurstudents.com/
It has been started to empower students with wealth of knowledge on admissions, colleges, entrance exams, jobs etc and help them achieve greater success.Its an effort to make Nagpur an attractive education hub.

Powered by WordPress | Theme: Motion by 85ideas.