) What are the
prerequisites to run Java code on your local machine. List all the steps
(downloading and installing Java, setting up path and classpath (exact syntax),
commands to compile and run)
download java and run
the .exe to install Java on your machine
you would need to set
environment variables to point to correct installation directories:
·
Right-click on 'My
Computer' and select 'Properties'.
·
Click on the
'Environment variables' button under the 'Advanced' tab.
·
Now, alter the 'Path'
variable so that it also contains the path to the Java executable. Example, if
the path is currently set to 'C:\WINDOWS\SYSTEM32', then change your path to
read 'C:\WINDOWS\SYSTEM32;c:\Program Files\java\jdk\bin'.
Write java program in
notepad or eclpse…and save as xxx.java
public class MyFirstJavaProgram {
/* This is my first java program.
* This will print 'Hello World' as the output
*/
public static void main(String []args) {
System.out.println("Hello World"); // prints Hello World
}
}
·
Open a command prompt
window and go o the directory where you saved the class. Assume it's C:\.
·
Type ' javac
MyFirstJavaProgram.java ' and press enter to compile your code. If there are no
errors in your code, the command prompt will take you to the next line
(Assumption : The path variable is set).
·
Now, type ' java
MyFirstJavaProgram ' to run your program.
·
You will be able to see
' Hello World ' printed on the window.
For all class names the
first letter should be in Upper Case.
·
All method
names should start with a Lower Case letter. Name
of the program file should exactly match the class name Examples
of legal identifiers: age, $salary, _value, __1_value
·
Examples of illegal
identifiers: 123abc, -salary
Java programme:
import java.io.*;
public class Employee{
String name;
int age;
String designation;
double salary;
// This is the constructor of the class Employee
public Employee(String name){
this.name = name;
}
// Assign the age of the Employee to the variable age.
public void empAge(int empAge){
age = empAge;
}
/* Assign the designation to the variable designation.*/
public void empDesignation(String empDesig){
designation = empDesig;
}
/* Assign the salary to the variable salary.*/
public void empSalary(double empSalary){
salary = empSalary;
}
/* Print the Employee details */
public void printEmployee(){
System.out.println("Name:"+ name );
System.out.println("Age:" + age );
System.out.println("Designation:" + designation );
System.out.println("Salary:" + salary);
}
}
As mentioned previously in
this tutorial, processing starts from the main method. Therefore in-order for
us to run this Employee class there should be main method and objects should be
created. We will be creating a separate class for these tasks.Save the
following code in EmployeeTest.java file
import java.io.*;
public class EmployeeTest{
public static void main(String args[]){
/* Create two objects using constructor */
Employee empOne = new Employee("James Smith");
Employee empTwo = new Employee("Mary Anne");
// Invoking methods for each object created
empOne.empAge(26);
empOne.empDesignation("Senior Software Engineer");
empOne.empSalary(1000);
empOne.printEmployee();
empTwo.empAge(21);
empTwo.empDesignation("Software Engineer");
empTwo.empSalary(500);
empTwo.printEmployee();
}
}
Now,
compile both the classes and then run EmployeeTest to see the result as follows:
C :> javac Employee.java
C :> vi EmployeeTest.java
C :> javac EmployeeTest.java
C :> java EmployeeTest
Name:James Smith
Age:26
Designation:Senior Software Engineer
Salary:1000.0
Name:Mary Anne
Age:21
Designation:Software Engineer
Salary:500.0
2) What is the difference
in the versioning format in Java (Eg:- 1.5 vs 5.0)
Where there was 1.5.0
now make into 5.0
3) Name a bug that
I missed while testing in my previous project and what did I learn from that
After 3 incorrect validation code, there will be a message box showing error message with ok button, once user clicks on ok button, he will be locked out. But in that case, user will be able to click on ceo drop down menu and would be able to anything else without locking out
After 3 incorrect validation code, there will be a message box showing error message with ok button, once user clicks on ok button, he will be locked out. But in that case, user will be able to click on ceo drop down menu and would be able to anything else without locking out
4) More
on how I designed my automation framework in Java
-----------------------------------------------------------------------------------------------------------------------------------------------------------
1) Java basics (Threads,
Collections, synchronization, etc)
Thread:All Java programs have at least one thread,
known as the main thread, which is created by the JVM at the program’s start,
when the main() method is invoked with the main thread. In Java, creating a
thread is accomplished by implementing an interface and extending a class.
Every Java thread is created and controlled by the java.lang.Thread class.
When a thread is created, it is assigned a priority. The thread with higher priority is executed first, followed by lower-priority threads
When a thread is created, it is assigned a priority. The thread with higher priority is executed first, followed by lower-priority threads
Collections: is set of interfaces like collection interface, list, set, map,sorted map, sorted set etc
What is difference between ArrayList and vector?
Ans: )
The ArrayList class extends AbstractList and implements the List interface. ArrayList supports dynamic arrays that can grow as needed. import java.util.*; public class ArrayListDemo { public static void main(String args[]) { // create an array list ArrayList al = new ArrayList(); System.out.println("Initial size of al: " + al.size()); // add elements to the array list al.add("C"); al.add("A"); al.add("E"); al.add("B"); al.add("D"); al.add("F"); al.add(1, "A2"); System.out.println("Size of al after additions: " + al.size()); // display the array list System.out.println("Contents of al: " + al); // Remove elements from the array list al.remove("F"); al.remove(2); System.out.println("Size of al after deletions: " + al.size()); System.out.println("Contents of al: " + al); } }
This would produce the following result:
Initial size of al: 0 Size of al after additions: 7 Contents of al: [C, A2, A, E, B, D, F] Size of al after deletions: 5Contents of al: [C, A2, E, B, D | |||||||
Q2) How can Arraylist be synchronized without using Vector?
Ans) Arraylist can be synchronized using:
|
How to sort list of strings - case insensitive?
Ans) using Collections.sort(list, String.CASE_INSENSITIVE_ORDER);
2) Differences between
Java and Ruby
·
Memory is managed via a
garbage collector.
Differences
·
You don’t need to
compile your code. You just run it directly.
·
Everything is an object,
including numbers like 2 and 3.14159.
·
All member variables are
private. From the outside, you access everything via methods.
·
There’s no static type
checking. Variable names are just
labels. They don’t have a type associated with them. There are no type declarations.
·
There’s no casting. Just
call the methods.
·
The constructor is
always named “initialize” instead of the name of the class.
·
You have “mixin’s”
instead of interfaces.
·
== and equals() are
handled differently in Ruby. Use == when you want to test equivalence in Ruby
(equals() is Java). Use equal?() when you want to know if two objects are the
same (== in Java).
3) What I did in my
previous work place (what tools, testing frameworks I used, how I programmed
the automation framework, Selenium, etc)
4) General QA questions
such as how to deal with opening bugs, what kind of bugs were found, how do I
come up with testcases
5) Writing a small
program in any language for a small problem
------------------------------------------------------------------------------------------------------------------------------------------------------------------
1) Most recent
experience: What I did, technologies, languages, What kind of development
process was used in my team
2) Questions on Java:
Really basic questions: Overriding and Overloading, Classes, objects, methods,
how to install Java and set environment on a PC, Does Java5 and Java1.5 refer
to the same thing?
3) UNIX / LINUX shell
commands, shell programming, editors and tools to login the UNIX
server and how I used those in my previous experience
4) Testing and
Automation: How I came up with test cases,
how I developed my atomation
framework,
what is the difference between Verification and Validation,
other
keywords in software testing. Given an application that needs testing,
how
would I develop my automation, i.e., Step-by-step programming solution to
the problem
5) Teamwork: How I
handled pressure, Deadlines, relationship between testers, developers, etc..by organising things in advance, try to finish u r work as per plan and ahead , think of this situation ahead and work accordingly, work late if needed, take help when required..communication, mutual coordination....