GenSpark Java Interview Questions

Pataasin ang iyong marka sa homework at exams ngayon gamit ang Quizwiz!

How to reverse a string in Java?

"String str = "Hello"; String reverse(String str){ StringBuilder sb = new StringBuilder(); sb.append(str); sb.reverse(); return sb.toString(); }

what is enumeration in Java?

Enumeration means a list of named constant. In Java, enumeration defines a class type. An Enumeration can have constructors, methods and instance variables. It is created using enum keyword. Each enumeration constant is public, static and final by default. Even though enumeration defines a class type and have constructors, you do not instantiate an enum using new. Enumeration variables are used and declared in much a same way as you do a primitive variable.

what is api in Java?

Java application programming interface(API) is a list of all classes that are part of the java development kit (JDK). It includes all Java packages, classes, and interfaces, along with their methods, fields, and constructors

why multiple inheritance is not supported in java?

Java supports multiple inheritance through interfaces only. A class can implement any number of interfaces but can extend only one class. Multiple inheritance is not supposed because it leads to a deadly diamond problem.

how to take input in Java?

Scanner in = new Scanner(System.in); System.out.print(""Please enter hour 1: ""); int hour1 = in.nextInt(); System.out.print(""Please enter hour 2: ""); int hour2 = in.nextInt(); System.out.print(""Please enter minute 1: ""); int min1 = in.nextInt(); System.out.print(""Please enter minute 2: ""); int min2 = in.nextInt();

what is an abstract class in java?

a class that is declared using the "abstract" keyword. it can have abstract methods (methods without body) as well as concrete methods(regular methods with body). a normal class (non-abstract class) cannot have abstract methods

What is java?

a general-purpose computer programming language that is class-based, object-oriented designed to produce programs that will run on any computer system.

what is static in Java?

a static member is a member of a class that isn't associated with an instance of a class. Instead, the member belongs to the class itself. As a result, you can access the static member without first creating a class instance.

what is collection in java?

containers that group multiple items in a single unit.

how to check java version?

execute 'java -version' on a command prompt/terminal

how to sort an array in Java?

import java.util.Arrays; Arrays.sort(array);

how to initialize array in Java?

int[ ] arr = new int[5]; String [ ] cars = ("Volvo", "BMW", "Ford", "Mazda");

how to compare two strings in Java?

new String ("test").equals("test")

what is abstraction in java?

objects are the building blocks of Object-oriented programming. An object contains some properties and methods. We can hide them from the outer world through access modifiers. We can provide access only for required functions and properties to the other programs.

what is inheritance in Java?

the process by which one class acquires the properties and functionalities of another class. -child class: the class that extends the features of another class. -parent class: the class whose properties and functionalities are used (inherited) by another class.

what is encapsulation in java?

to hide the implementation details from users.

what is exception in java?

An exception is an event, which occurs during the execution of a program, that disrupts the normal flow of the program's instructions.When an error occurs within a method, the method creates an object and hands it off to the runtime system. The object, called an exception object, contains information about the error, including its type and the state of the program when the error occurred. Creating an exception object and handing it to the runtime system is called throwing an exception.

what is method in java?

a block of code which only runs when it is called. you can pass data, known as parameters, into a method. Methods are used to perform certain actions, and they are also known as functions

what is a thread in java?

threads allow a program to operate more efficiently by doing multiple things at the same time. -can be used to perform complicated tasks in the background without interrupting the main program -syntax: public class MyClass extends Thread { public void run() { System.out.println("This code is running in a thread"); } }

what is package in java?

used to group related classes. think of it as a folder in a file directory. we use packages to avoid name conflicts, and to write a better maintainable code -built-in packages (packages from the java API) -user-defined packages (create your own packages)

what is core java?

used to refer to Java SE, the standard edition and a set of related technologies, like the Java VM, CORBA, etc.

how to take input from user in java?

import java.util.Scanner; Scanner console = new Scanner(System.in); int num = console.netInt(); console.nextLine() String str = console.nextLine();

what is a string in java?

string is a sequence of characters. in java, string is an immutable object which means it is constant and cannot be changed once it has been created

what is a class in java?

the basic building block of an object-oriented language. a template that describes the data and behavior associated with instances of that class. When you instantiate a class you create an object that looks and feels like other instances of the same class. The data associated with a class or object is stored in variables; the behavior associated with a class or object is implemented with methods


Kaugnay na mga set ng pag-aaral

List the steps taken to preserve a crime scene

View Set

Basic Java Quiz (AP Computer Science in Java (Mocha))

View Set

Chapter 26- Face and Neck Injuries

View Set

Market Equilibrium and Policy SmartBook

View Set

Unit 4 Day 1 - Mood/Affect; Coping; Sexuality

View Set

UNIT #15: Insurance-Based Products

View Set

HI State Real Estate Practice Exam

View Set

Disaster Planning Adaptive Quizzing

View Set

Unit 3: Income Taxes and the Investor in Florida

View Set