Java Flashcards
What is an If Statement?
An if statement is a boolean expression followed by one more statements. The block of code inside the if statement will run if the boolean expression is true.
What is a Switch statement?
A switch statement allows a variable to be tested for equality against a list of values. Each value is called a case, and the variable being switched on is checked for each case.
What are Loop statements in Java?
A loop statement allows us to execute a statement or group of statements multiple times.
What is a While loop?
A while loop statement in Java programming language repeatedly executes a target statement as long as a given condition is true.
What is a For loop?
A for loop is a repetition control structure that allows you to efficiently write a loop that needs to be executed a specific number of times.
What is a do while loop?
A do…while loop is similar to a while loop, except that a do…while loop is guaranteed to execute at least one time.
What is an enhanced For loop?
This is mainly used to traverse collection of elements including arrays.
What is the usage of “This” keyword?
In java, this is a reference variable that refers to the current object.
Here is given the 6 usage of java this keyword.
this can be used to refer current class instance variable. this can be used to invoke current class method (implicitly) this() can be used to invoke current class constructor. this can be passed as an argument in the method call. this can be passed as argument in the constructor call. this can be used to return the current class instance from the method
What is the use of “new” keyword in Java?
The new keyword is a Java operator that creates an object. The new operator instantiates a class by dynamically allocating(i.e, allocation at run time) memory for a new object and returning a reference to that memory.
What is the use of the “super” keyword in Java?
The super keyword in Java is a reference variable which is used to refer immediate parent class object.
What is the use of “static” keyword in Java?
The static keyword belongs to the class than an instance of the class. The static variable can be used to refer to the common property of all objects (which is not unique for each object), for example, the company name of employees, college name of students, etc.
What is the use of “final” keyword in Java?
In the Java programming language, the final keyword is used in several contexts to define an entity that can only be assigned once. Once a final variable has been assigned, it always contains the same value
What is a String?
A string is an object that represents a sequence of characters. For example text.
What are some string handling methods?
char charAt(int index) - Returns the character at the specified index. int compareTo(Object o) - Compares this String to another Object. String concat(String str) - Concatenates the specified string to the end of this string. boolean equals(Object anObject) - Compares this string to the specified object. boolean equalsIgnoreCase(String anotherString) - Compares this String to another String, ignoring case considerations.
What is a package in Java?
A java package is a group of similar types of classes, interfaces and sub-packages.
Package in java can be categorized in two form, built-in package and user-defined package.
There are many built-in packages such as java, lang, awt, javax, swing, net, io, util, sql etc.