Home  >>  Core Java  >>  

1. What is OOPS?

ans) OOPS is abbreviated as Object Oriented Programming system in which programs are considered as a collection of objects. Each object is nothing but an instance of a class.

What are access modifiers?

Modifiers are keywords that you add to those definitions to change their meanings. The Java language has a wide variety of modifiers, including the following:

1)Java Access Modifiers

2)Non Access Modifiers

Java Access Modifiers:

 For better understanding, member level access is formulated as a table: 

Access Modifiers
 
Same Class Same Package Subclass Other packages
public Y Y Y Y
protected Y Y Y N
no access modifier Y Y N N
private Y N N N

Visible to the package. the default. No modifiers are needed.

Visible to the class only (private).

Visible to the world (public).

Visible to the package and all subclasses (protected).

Variables and methods can be declared without any modifiers, as in the following examples:

String version = "4.5.6";

boolean processOrder() {
   return true;
}
To use a modifier, you include its keyword in the definition of a class, method, or variable. The modifier precedes the rest of the statement, as in the following 

example:

public class className {

// ...}

private boolean myFlag;

static final double weeks = 9.5;

protected static final int BOXWIDTH = 42;

public static void main(String[] arguments) {


Non Access Modifiers:

1)Java provides a number of non-access modifiers to achieve many other functionality.

2)The static modifier for creating class methods and variables

3)The final modifier for finalizing the implementations of classes, methods, and variables.

4)The abstract modifier for creating abstract classes and methods.
     

5)The synchronized and volatile modifiers, which are used for threads.
 

what string method in java?

Here some important strings methods with description are given bellow:

                                       methods                                     Description
int compareTo(String anotherString) Compares two strings lexicographically.
 
int compareToIgnoreCase(String str) Compares two strings lexicographically, ignoring case differences.
String concat(String str) Concatenates the specified string to the end of this string.
char charAt(int index) Returns the character at the specified index
int compareTo(Object o) Compares this String to another Object.
 
boolean contentEquals(StringBuffer sb)
 
Returns true if and only if this String represents the same sequence of characters as the specified StringBuffer.
static String copyValueOf(char[] data, int offset, int count) Returns a String that represents the character sequence in the array specified.
boolean endsWith(String suffix) Tests if this string ends with the specified suffix.
 
static String copyValueOf(char[] data) Returns a String that represents the character sequence in the array specified.
 
boolean equalsIgnoreCase(String anotherString)
 
Compares this String to another String, ignoring case considerations.
int hashCode() Returns a hash code for this string.
 
int indexOf(int ch) Returns the index within this string of the first occurrence of the specified character.
 
int indexOf(int ch, int fromIndex) Returns the index within this string of the first occurrence of the specified character, starting the search at the specified index.
 
int indexOf(String str)
 
Returns the index within this string of the first occurrence of the specified substring.
 
int indexOf(String str, int fromIndex) Returns the index within this string of the first occurrence of the specified substring, starting at the specified index.
 
byte[] getBytes(String charsetName Encodes this String into a sequence of bytes using the named charset, storing the result into a new byte array.
 
void getChars(int srcBegin, int srcEnd, char[] dst, int dstBegin) Copies characters from this string into the destination character array.
boolean equals(Object anObject) Compares this string to the specified object.
 
String intern() Returns a canonical representation for the string object.
int lastIndexOf(int ch) Returns the index within this string of the last occurrence of the specified character.
String replace(char oldChar, char newChar) Returns a new string resulting from replacing all occurrences of oldChar in this string with newChar.
String replaceAll(String regex, String replacement Replaces each substring of this string that matches the given regular expression with the given replacement.
String replaceFirst(String regex, String replacement) Replaces the first substring of this string that matches the given regular expression with the given replacement.
String[] split(String regex) Splits this string around matches of the given regular expression.
String[] split(String regex, int limit) Splits this string around matches of the given regular expression.
boolean startsWith(String prefix) Tests if this string starts with the specified prefix.
boolean startsWith(String prefix, int toffset) Tests if this string starts with the specified prefix beginning a specified index.
 
int lastIndexOf(int ch, int fromIndex) Returns the index within this string of the last occurrence of the specified character, searching backward starting at the specified index.
int lastIndexOf(String str)
 
Returns the index within this string of the rightmost occurrence of the specified substring.
 
int lastIndexOf(String str, int fromIndex) Returns the index within this string of the last occurrence of the specified substring, searching backward starting at the specified index.
int length() Returns the length of this string.
boolean matches(String regex) Tells whether or not this string matches the given regular expression.
 
boolean regionMatches(boolean ignoreCase, int toffset, String other, int ooffset, int len) Tests if two string regions are equal.
boolean regionMatches(int toffset, String other, int ooffset, int len) Tests if two string regions are equal.
CharSequence subSequence(int beginIndex, int endIndex) Returns a new character sequence that is a subsequence of this sequence.
String substring(int beginIndex)
 
Returns a new string that is a substring of this string.
static String valueOf(primitive data type x)
 
Returns the string representation of the passed data type argument.
String trim() Returns a copy of the string, with leading and trailing whitespace omitted.
 
String toUpperCase(Locale locale)
 
Converts all of the characters in this String to upper case using the rules of the given Locale.
 
String toUpperCase() Converts all of the characters in this String to upper case using the rules of the default locale.
 
String toString()
This object (which is already a string!) is itself returned.
 
String toLowerCase(Locale locale) Converts all of the characters in this String to lower case using the rules of the given Locale.
 
String toLowerCase() Converts all of the characters in this String to lower case using the rules of the default locale.
 
char[] toCharArray()
 
Converts this string to a new character array.
 
String substring(int beginIndex, int endIndex) Returns a new string that is a substring of this string.
 






  

Which HTTP method is non-idempotent?

A HTTP method is said to be idempotent if it returns the same result every time the request process. HTTP methods like GET, PUT, DELETE, HEAD, and OPTIONS are idempotent method becouse they return th same result at ech request processed ove the server and we should implement our application to make sure these methods always return same result. HTTP method POST is non-idempotent method and we should use post method when implementing something that that dynamic in nature or we can say changes with every request.

For example, to access resources sucah as an HTML page JSP page tales from database or image, we should use GET method because it will always return the same object but if we have to save some information to database like customer info users info or other data, we should use POST method. Idempotent methods are also known as safe methods and we donít care about the repetitive request from the client for safe methods. 

Which HTTP method is non-idempotent?

A HTTP method is said to be idempotent if it returns the same result every time the request process. HTTP methods like GET, PUT, DELETE, HEAD, and OPTIONS are idempotent method becouse they return the same result at each request processed over the server and we should implement our application to make sure these methods always return same result. HTTP method POST is non-idempotent method and we should use post method when implementing something that that dynamic in nature or we can say changes with every request.

For example, to access resources such as an HTML page JSP page tales from database or image, we should use GET method because it will always return the same object but if we have to save some information to database like customer info users info or other data, we should use POST method. Idempotent methods are also known as safe methods and we donít care about the repetitive request from the client for safe methods. 

How to get file URI reference in java?.

Below example shows how to get URl reference to the given file. By calling toURl() method on file object, you can get the URl reference.

The following URLDemo program demonstrates the various parts of a URL.
 

import java.net.*;

import java.io.*;

public class URLDemotest    {

public static void main(String [] args)

{

try    {

URL url = new URL("http://www.java.com/myjava?language=j2se");

System.out.println("URL is " + url.toString());

System.out.println("protocol is "

+ url.getProtocol());

System.out.println("authority is "

+ url.getAuthority());

System.out.println("file name is " + url.getFile());

System.out.println("host is " + url.getHost());

System.out.println("path is " + url.getPath());

System.out.println("port is " + url.getPort());

System.out.println("default port is "

+ url.getDefaultPort());

System.out.println("query is " + url.getQuery());

System.out.println("ref is " + url.getRef());

}catch(IOException e)

{

e.printStackTrace();

}}}