Adobe Interview Question for Quality Assurance Engineers


Country: United States
Interview Type: In-Person




Comment hidden because of low score. Click to expand.
1
of 1 vote

/* 
 * Write a java program to read a file and get different words and also print number of occurrences of each word.
 */

package ccup.files;

import java.io.File;
import java.io.FileReader;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;
import java.util.TreeMap;
import java.util.StringTokenizer;

public class Files_17499665 {

	public static void main(String [] args){
		
		//Creating BufferedReader to accept the file name from the user
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		
		String fileName = null;
		System.out.print("Please enter the file name with path: ");
		try{
			fileName = (String) br.readLine();
			
			//Creating the BufferedReader to read the file
			File textFile = new File(fileName);
			BufferedReader input = new BufferedReader(new FileReader(textFile));
			
			//Creating the Map to store the words and their occurrences
			TreeMap<String, Integer> frequencyMap = new TreeMap<String, Integer>();
			String currentLine = null;
			
			//Reading line by line from the text file
			while((currentLine = input.readLine()) != null){
				
				//Parsing the words from each line
				StringTokenizer parser = new StringTokenizer(currentLine, " \t\n\r\f.,;:!?'\""); 
				while(parser.hasMoreTokens()){
					String currentWord = parser.nextToken();
					
					Integer frequency = frequencyMap.get(currentWord); 
					if(frequency == null){
						frequency = 0;						
					}
					//Putting each word and its occurrence into Map 
					frequencyMap.put(currentWord, frequency + 1);
				}
				
			}
			
			//Displaying the Result
			System.out.println(frequencyMap);
			
		}catch(IOException ie){
			ie.printStackTrace();
			System.err.println("Your entered path is wrong");
		}		
		
	}
	
}

Console: Please enter the file name with path: C:/Workspaces/CoreJava/CoreJava/src/ccup/files/spring.txt
{Before=1, J2EE=1, Java=1, Spring=2, a=1, and=3, bean=2, business=2, component=1, components=1, developers=1, development=1, entity=1, framework=1, implement=1, integration=1, is=1, light=1, logic=1, session=1, to=1, used=1, using=1, weight=1}

- Srinivas_Java April 18, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

How to get output of the above program in alphabetical order?

- Vasudev January 07, 2015 | Flag
Comment hidden because of low score. Click to expand.
1
of 1 vote

public static void collectDataFromFileAndPutIntoMap(String loc)
	{
		Map<String,Integer> m=new HashMap<String,Integer>();
		File f=new File(loc);
		try {
			BufferedReader br=new BufferedReader(new FileReader(f));
			String s=null;
			String[] tok;
			while((s=(br.readLine()))!=null)
			{
				for(String s1: s.split(" "))
				{
					if(m.get(s1)==null)
				      m.put(s1,1);
					else
						m.put(s1, m.get(s1)+1);
				}
				iterateOverHashMap(m);
			}
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

	private static void iterateOverHashMap(Map<String, Integer> m) {
		Iterator it=m.entrySet().iterator();
		while(it.hasNext())
		{
		Map.Entry pairs=(Map.Entry) it.next();
		System.out.println(pairs.getKey() + "----" + pairs.getValue());
		}
	}

This is definitely not the most efficient solution but still a working one at that :)

- teli.vaibhav April 19, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

1. Use Hashing, store hash of every word and keep incrementing its counter.
2. Use trie tree, store frequency of word within the trie node.
3. Use map, e.g. map<string, int> word_count

- Cerberuz April 18, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

class FileCountWords {
public static void main(String[] args) throws Exception {
Scanner input = new Scanner(System.in);
System.out.println("Enter File name with path: ");
String filename = input.next();
File f = new File(filename);
BufferedReader br = new BufferedReader(new FileReader(f));
StringBuffer buffer = new StringBuffer();
String str;
while ((str = br.readLine()) != null) {
buffer.append(str);
buffer.append(" ");
}
ArrayList<String> list = new ArrayList<String>();
StringTokenizer st = new StringTokenizer(buffer.toString()
.toLowerCase());
while (st.hasMoreTokens()) {
String s = st.nextToken();
list.add(s);
}
while (!list.isEmpty()) {
int i = 0;
String uniqueStr = list.get(i);
int index = list.lastIndexOf(uniqueStr);
int uniqueStrCount = 1;
while (i != index) {
uniqueStrCount++;
list.remove(index);
index = list.lastIndexOf(uniqueStr);
}
System.out.println("count of word " + "-" + uniqueStr + "-"
+ " in the file is : " + uniqueStrCount);
list.remove(i);
i++;
}
}
}

- Anil April 30, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

package pracise;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.util.HashMap;

public class fileReader {

	public static void main(String[] args) throws IOException{
		HashMap<String, Integer> h = new HashMap<String, Integer>();
		BufferedReader input = new BufferedReader(new FileReader(new File("//Users//a")));
		try {
	        String line = null;
	        while ((line = input.readLine()) != null) {
	        	String[] l = line.split(" ");
	        	for(String s : l){
	        		if(h.containsKey(s)){
	        			int counter = h.get(s);
	        			counter++;
	        			h.put(s, counter);
	        		}else{
	        			h.put(s, 1);
	        		}
	        	}
	        }
	    } finally {
	        input.close();
	    }
		System.out.println(h);
	}
}

- Anonymous January 18, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

your code is taking capital and small letter as a differnet letter so if two terms are repeated one start from capital and other from small it tells wrong frequcy

- Anonymous May 07, 2015 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

sxsd

- Anonymous May 11, 2016 | Flag Reply
Comment hidden because of low score. Click to expand.
-1
of 1 vote

so is this adobe standard...?

- gr81 April 22, 2013 | Flag Reply


Add a Comment
Name:

Writing Code? Surround your code with {{{ and }}} to preserve whitespace.

Books

is a comprehensive book on getting a job at a top tech company, while focuses on dev interviews and does this for PMs.

Learn More

Videos

CareerCup's interview videos give you a real-life look at technical interviews. In these unscripted videos, watch how other candidates handle tough questions and how the interviewer thinks about their performance.

Learn More

Resume Review

Most engineers make critical mistakes on their resumes -- we can fix your resume with our custom resume review service. And, we use fellow engineers as our resume reviewers, so you can be sure that we "get" what you're saying.

Learn More

Mock Interviews

Our Mock Interviews will be conducted "in character" just like a real interview, and can focus on whatever topics you want. All our interviewers have worked for Microsoft, Google or Amazon, you know you'll get a true-to-life experience.

Learn More