Friday, March 31, 2017

Java BufferedReader with example

In this article we will talk about BufferedReader class in Java with examples. While writing the data by using File Writer,program is responsible to insert line separators manually. We can read the data character by character by using FileReader.It increases the number of I/O operations and effect performance. To overcome this problems sun people has introduced BufferedReader and BufferedWriter classes.

BufferedReader is a wrapper for both "inputStreamReader/FileReader",which buffers the information each time a native I/O is called.BufferedReader improves the performance of the buffering input. It has two constructors. They are

  1. BufferedReader(Reader inputStream)
  2. BufferedReader(Reader inputStream,int bufSize)
The first one creates a buffered character stream using a default buffer size.In the second,the size of the buffer is passed in bufSize.

BufferedReader never communicates directly with the file.It communicates with some reader object only.BufferedReader  class has some important methods they are


  • int read()
  • int read(char[] ch)
  • String readLine();//it is used to reads the next line present in the file.If there is no next line it returns the null
  • void close()
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));

In the above statement BufferedReader is a class from Java.io package. This class is used to read text from a character input stream,buffering characters so as to provide for the efficient reading of characters,arrays and lines. 

br is a identifier(variable) to hold the input data.

new is used to instantiate or construct the new class

BufferedReader() method is used to instantiate or construct  an instance of the BufferedReader class.

InputStreamReader() class is come from java.io package. It is used as a bridge from byte streams to character streams. it reads bytes and decodes them into characters.It usually wrapped inside a BufferedReader.

System.in has an object representing input from a buffer that means standard input device on a computer system,usually a keyboard.

Example:

import java.io.*;
class test
{
public static void main(String arg[])throws IOException
{
FileReader fr = new FileReader("myfile.txt");
BufferedReader br = new BufferedReader(fr);
String s = br.readLine();
while(s != null)
{
System.out.println(s);
s = br.readLine();
}
br.close();
}
}

Note: Whenever we are closing BufferedReader,automatically FileReader object will be closed.

Example 2:

The following program shows to read data from any text file

import java.io.*;
class ReadFile
{
public static void main(String[] args)throws IOException
{
//to accept file name from the keyboard

BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
System.out.println("Enter file name:");
String fname=br.readLine();
//attach the file to the FileInputStream
FileInputStream fin=null;//assign nothing to fin
//check if file exists or not
try{
fin=new FileInputStream(fname);

}
catch(FileNotFoundException fe)
{

System.out.println("File Not Found");
return;
}
//attach FileInputStream to BufferedInputStream
BufferedInputStream bin=new BufferedInputStream(fin);
System.out.println("file contents:");
//read characters from BufferedInputStream and write them into monitor.Repeat this till the end of file
int ch;
while(ch=bin.read()!=-1)
System.out.println((char)ch);
//close the file
bin.close();
}
}

Output:
Enter file name: myfile.txt
File contents:
hi how are you

Note:  If you entered wrong file name that means does not exist file name in your computer then it display as result File Not Found





Packages in Java with Examples

In this post we will talk about Java packages with examples. This is one of the core concept in Java. A package is represents a directory that contains related group of classes and interfaces. We can also define a package is a mechanism to encapsulate group of classes,interfaces and Sub packages. It is easy to organize class files into packages.Packages can help programmer to avoid name conflicts and to control access of classes,interfaces and enumeration etc..Therefore by using packages we can prevent naming conflicts.

Advantages of package:


  • packages are useful to arrange related classes and interfaces into a group.This makes all their classes and interfaces performing the same task to put together in the same package. For example,in Java,all the classes and interfaces which perform input and output operations are stored in java.io package 
  • packages hide the classes and interfaces in a separate sub directory,so that accidental deletion of classes and interfaces will not take place
Types of packages:

There are two different types of packages in Java. They are

  1. Built-in package
  2. User-defined package
Built-in package:

Built-in packages means which are already available in Java language. These packages provides all most all necessary classes,interfaces and methods for the programmer to perform any task in his programs. This makes the programming easy.

Examples:
java.lang package
java.util package
java.io package
java.awt package
java.net package
java.applet package
java.sql package

User-defined package:
The users of the java language can also create their own packages. They are also called user-defined packages. User-defined packages can also be imported into other classes and used exactly in the same way as the Built-in packages.

Let us see how to create a package of our own and use it in any other classes as shown below.

The general form of the package statement:

package pkg;

Here pkg means name of the package

Example: 
package myPackage;

package pkg.subpackagename;//to create a sub package within a package

Let us understand how to create a package with example:

package pack;
public class sum
{
private int a,b;
public sum(int x,int y)
{
a=x;
b=y;
}
//method to find sum of two numbers
{
public void sum()
{
System.out.println("sum="+(a+b));

}
}

output:
c:\>javac -d . sum.java
c:\>

Here -d option tells the java compiler to create a separate sub directory and place the .class file there. The dot(.)after -d indicates that package should be created in the current directory i.e. C:\>

That means our package with sum class is ready. Now to create an object to sum class we can write as:
pack.sum obj=new pack.sum(13,23);

class packDemo
{
public static void main(String args[])
{
//create sum class object
pack.sum obj=new pack.sum(13,23);
//call the sum method
obj.sum();
}
}

Output:
c:\> javac packDemo.java
c:\> java packDemo
sum=36

Every time we refer to a class of a package,we should write the package name before the class name as pack.sum in the above program. This is not convenient for the programmer. To overcome this,we can use import statement only once in the beginning of the program as:

import pack.sum;

Once import statement is written as shown earlier,we need not use the package name before class name in the rest of the program and we can create the object to the sum class,in normal way as:

sum obj=new sum(13,23);

Example:
import pack.sum;
class packDemo
{
public static void main(String args[])
{
//create sum class object
sum obj=new sum(13,23);
//call the sum method
obj.sum();
}
}

Output:
C:\> javac packDemo.java
C:\java packDemo
sum=36

Note:

  • If we are not taking any package statement then the current working directory Acts as default package
  • The first non-comment statement in any java source file is package statement.
How to create sub package:

we can create a sub package in a package in the format:

package pack1.pack2;

That means we are creating pack2 inside pack1. To use the classes and interfaces of pack2,we can write import statement as:

import pack1.pack2;

This concept can be extended to create several sub packages.

Example:

package learnprograming.bylucky;
public class simple
{
public void display()
{
System.out.println("welcome to learnprogramingbyluckysir");
}
}
Output:
c:\>javac -d . sample.java
c:\>

When we compiled above program,the compiler creates a sub directory with the name learnprograming. Inside this,there would be another sub directory with the name bylucky is created.In this bylucky directory,sample class is stored.Suppose user wants to use sample class of learnprograming.byluucky package,he can write a statement as:

import learnprograming.bylucky.sample;

Example:

import learnprograming.bylucky.sample;
class packDemo
{
public static void main(String args[])
{
//create object to sample class
sample s=new sample();
//call the display() method
s.display();
}
}
Output:
c:\>javac packDemo.java
c:\>java packDemo
welcome to learnprogramingbyluckysir

Sunday, March 26, 2017

How to Prepare for Campus Placements

In this article, we will know how to get success in campus interviews. If you are a final year student, many organizations would conduct off-campus placements in your colleges. You are unsure about your own choices and goals. Everybody wants to get place in reputed organization.So what should you need to do is to prepare for it well, Here's how?

Here i am providing some tips to prepare for campus interviews:

Design Your Best Resume: 

To Design Your best Resume you could review some sample resumes that are available on the websites. Download sample resumes then adopt the layout and way it is presented as your template.Then change education details,skills and projects completed  which you have done in your semesters. When you are building resume keep in mind that use simple fonts,text and single color. 

Prepare for Aptitude Test:

You should expect aptitude test is 1st round in selection process-written examination. Many student fear about aptitude test but don't worry about it,here are the some topics you should focus before attend the interview. They are Reasoning problems,logical ability,Arithmetic problems and operating system questions . So practice them well for to clear this round.

Improve Your Communications Skills:

Now a days to get job in IT industry communication skills plays vital role.It is better to sharpen your skills from now itself by reading English newspapers,magazines,and read your interest web articles everyday. If you want survival and to reach Lead position early, you must have good speaking and writing skills in English Language.Therefore,every student should enhance their communication skills.

Prepare Your Favorite Subject:

If You are a Computer Science background student then the interviewer will ask the questions about some basic questions on programming language. This part is nothing but technical interview round in the selection process. You should prepare some basic interview questions on C,C++,JAVA and DBMS. The interviewer may ask which is your favorite Subject. So, whatever subject you have confident then answer him with your favorite subject. If you are not confident about on any subject then don't tell. Here, You can expect basic questions and their advantages.So prepare well to clear technical round as well.

Prepare For Group Discussion:

Some companies will conduct Group Discussion also. I have written Tips for Group Discussion how to prepare for it. Just click on it.

Learn some personal skills:

You must have some personal skills like maintaining eye contact is one of the main skill. When Interviewer ask the question you should answer him with eye contact. Learn when you meet new persons you must greet them. One of the main skill you must fallow is listening skills. Listen carefully and answer perfectly. When interviewer asking asking questions don't interrupt him,first listen completely and then answer him properly.

Be Confident:

Here confident means in interview process,believe yourself to develop self confidence.

See also:

Interview Procedure in Multinational companies 

HR Interview Questions for  off campus

Operating System Interview Questions

In this post we will learn Operating System(OS) Interview Questions which every IT developer must have knowledge on these Q & A. These questions and answers come across Technical Written Test also. Let us see what are those Questions and Answers as follows..

1) What is Operating System?

Ans:  An Operating System is a software program that enables the computer hardware to communicate and operate with the computer software. Without a computer Operating system, a computer would be useless.

2) What are the different Operating Systems?

Ans: There are different types OS they are

1) Multi-programming OS
2) Distributed OS
3)Batched OS
4)Time-sharing OS
5)Real-time OS

3) Why paging is used in OS?

Ans: Paging is solution to external fragmentation problem which is to permit the logical address space of a process to be noncontinuous,thus allowing a process to be allocating physical memory wherever the latter is available.

4) What is the state of the processor,when a process is waiting for some event to occur?

Ans: The state of the processor is : Waiting state

5) What is Virtual Memory?

Ans: Virtual Memory is hardware technique where the system appears to have more memory that it actually does. This is done by time-sharing ,the physical memory and storage parts of the memory one disk when they are not actively being used.

6) What is fragmentation?

Ans:  Fragmentation occurs in a dynamic memory allocation system when many of the free blocks are too small to satisfy any request.

7) What is the cause of thrashing? How does the system detect thrashing?

Ans:  Once it detects thrashing,what can the system do to eliminate this problem? Thrashing is caused by under allocation of the minimum number of pages required by a process,forcing it to continuously page fault. The system can detect thrashing by evaluating the level of CPU utilization as compared to the level of multi programming. It can be eliminated by reducing the level of multi programming.

8) While running DOS on PC,which command would be used to duplicate the entire diskette?

Ans: This command will be use to duplicate the entire diskette diskcopy.

9) What is cache-memory?

Ans: Cache memory is random access memory(RAM) that a computer microprocessor can access more quickly that it can access regular RAM. As the microprocessor process data,it looks first in the cache memory and if if finds the data there(from the previous reading of data). It does not have to do the more time-consuming reading of data from larger memory.

10) What is Kernal?

Ans: Kernal is the core and essential part of computer operating system that provides basic services for all parts of OS.

11) What is a process?

Ans: A program in execution is called a process or it may be called unit of work. A process needs some system resources as CPU time,memory,files and I/O devices to accomplish the task.

12) What is semaphore?

Ans: Semaphore is a variable,whose status reports common resources,Semaphore is of two types one is Binary semaphore and other is Counting semaphore.

13) What is deadlock?

Ans: Deadlock is a situation or condition where two processes are waiting for each other to complete so that they can start. This result both the processes to hang

14) What are system calls?

Ans: System calls provide the interface between process and the OS. System calls for modern Microsoft windows platforms are part of the win 32 API. Which is available for all the compilers written for Microsoft Windows.

15) What are the states of Process?

Ans: There are 5 states of Process. They are

1) NEW
2) Running
3) Waiting
4) Ready
5) Terminated

16) What is the Real-Time System?

Ans: A Real-Time process is a process that must respond to the events within a certain time period. A real time operating system is an OS that can run real time processes successfully.

17) What is FCFS?

Ans: FCFS stands for First-come First-served is one type of scheduling algorithm.In this Scheme, the process that requests the CPU first is allocated the CPU first,implementation is managed by FIFO queue.

18) What is logical and physical address space?

Ans: Logical address refers to the address that is generated by the CPU. On the other hand,physical address refers to the address that is seen by the memory unit.

19) What is the basic function of Paging?

Ans: Paging is a memory management scheme that permits the physical address space.

20) What is bounded-buffer problem?

Ans: Assume that a pool consists of n buffers each capable of holding one item.The semaphore provides mutual exclusion for accesses to the buffer pool and is initialized to the value 1.The empty and full semaphores count the number of empty and full buffers, respectively. Empty is initialized to n, and full is initialized to 0.

Top 10 JOB Portals in India

I am sharing today How to find your dream job and develop your career. Find the best jobs related to your skills. I am providing top employment search portals for freshers and experienced. Now a days, every one finding their jobs through online job forums and gained a lot of credence in the present time and totally helped people to find their choice.

Here is list of Top Job Websites in India. These websites provides various services such as job posting.

 


1) naukri.com: 

You can find the Best Jobs on Naukri.com and it is one of the India's No.1 job portal site. You can search & apply for job vacancies across Top companies in India. You can find all IT Jobs,freshers jobs,Sales Jobs,BPO jobs,Engineering jobs,manufacturing jobs,MBA jobs etc.. It was started in 1997 and has captured the complete internet marketing. It maintains 42 million job seekers and 12,600 resumes were added daily. It also maintains corporate customers around 33,700 unique corporate customers. You can download mobile app from Google play store (iphone,android) to find right kind of job what you are looking for.

Website Link : https://www.naukri.com



2) Monster India:

This is second highest job portal site in India. To search for job opportunities including Government jobs,IT Jobs,freshers jobs,banking jobs etc..It has popular and prominent leading online career and recruitment resource and provides relevant jobs. It has started its operation in 2001. The main Hardhearted is in Hyderabad.

 
Website Linkwww.monsterindia.com




3) TimesJobs:

This is one of the Best job portal in India. It was started in 2004 by Times Group. It has more than 1 core registered users and over 30,000 new candidates added their resume everyday in website.

 

Website Linkhttp://www.timesjobs.com



4) shine.com

It is also providing excellent service to companies and for job seekers. It has launched in 2008,within a short span of 8 years shine.com has become more popular and 1.9 core registered candidates  in India. It provides more than 3 lakh latest jobs vacancies in site.

 
Website Linkwww.shine.com



5) Freshersworld:

This site also counted in top 10 job portal list. Since, It is very popular for freshers hiring in India. In this job portal more than 3 lakh resumes are added every month from entry level graduates across the country. It is also maintains clients with more than 5000 corporate companies and some of the leading names are Facebook,wipro,ARM,infosys,EMC,AMAZON etc..

 


6) CareerBuilder:

It is also one of the finest job portal in India. Over last 20 years career builder has been at the forefront of innovation in the recruitment space.we have made it our business to help job seekers and employers around the world connect anytime and anywhere.






7) linkedIn:

 LinkedIn operates the world largest professional network on the internet with more than 467 million members in over 200 countries and territories. In this site professionals are joining at the rate of more than 2 new members per second. There are more than 40 million students and recent college graduates on linkedIn.

  The site is officially launched on may 5,2003 and founders are Allen Blue,Reid Hoffman,Eric.

 


 


8) FreshersLive:

 This is one of the leading job site for freshers who seek employment opportunities in both private and Government sectors in India. It was established 2009.Each month more than 2000 candidates are getting hired throgh fresherslive. It provides freshers jobs,government jobs, IT Jobjs,placement papers and offcampus interview etc..

 



 
9) careesma:

It is a brand new career website for the job market in India that specially caters to the needs of employers and aspiring job seekers. In this site over 120,000 employers & 9 million job seekers are already using across the globe.It has launched in 2004. The main objective and mission of the service provider to make people and go and work with a smile.

 

Website Linkhttp://www.careesma.in 

 


10) Jobsdb:

It is a leading job portal with substantial positions across Hong Kong,Indonesia,Philippines,Singapore,Thailand and other International partners.If you want find jobs in abroad then this is the best leading job portal.

 

Website Link: http://www.jobsdb.com 


  For more details visit in the video : Top 10 job websites  
Recommended to Read:



















































































































































































































































































































































































































































































High Paying Jobs after Learning Python

Everyone knows Python is one of the most demand Programming Language. It is a computer programming language to build web applications and sc...