Java Interview related

Source: Internet
Author: User
Tags access properties arithmetic operators bitwise operators float double java keywords

L JBS
1. List the advantages of the 10 Java languages
A: Free, open source, cross platform (platform independence), easy-to-use, fully functional, object-oriented, robust, multi-threaded, structured neutral, mature platform for enterprise applications, wireless application
2. List 10 object-oriented programming terminology in Java
A: Package, class, interface, object, attribute, method, constructor, inheritance, encapsulation, polymorphic, abstract, paradigm
3. List the 6 more commonly used packages in Java
Java.lang;java.util;java.io;java.sql;java.awt;java.net;java.applet;javax.swing
What are the functions and characteristics of identifiers in 4.JAVA
Role: Identifiers are used to name variables, classes, and methods
Features: You can start with a letter, an underscore "_", and a "$" character
The first character can be followed by letters, underscores "_" and "$" characters or numbers
Java is case-sensitive, and identifiers are no exception
What are the characteristics of keywords in 5.JAVA, listing at least 20 keywords
Some words in Java that are assigned a specific meaning and used for specialized purposes are called keywords (keyword).
All Java keywords are lowercase, TURE, FALSE, NULL, and so on are not Java keywords;
Goto and const, although never used, are also retained as Java keywords;
? In a total of 51 keywords Java
Abstract assert Boolean break byte continue
Case catch Char class const double
Default do extends else final float
For goto long If implements import
native new null instanceof int interface
Package private protected public return short
Static STRICTFP Super Switch synchronized this
While void throw throws transient try
Volatile

How are data types categorized in 6.JAVA?

Can be divided into simple data types and reference data types:
Simple data type: numeric (byte,short,int,long,float double), character type (char), Boolean (Boolean);
Reference data type: Class, interface, array.
Classification and examples of operators in 7.JAVA
? Separator:,,;, [], ()
? Arithmetic operators: +,―,*,/,%,++,――
? Relational operators: <,>=, <=,==,!=
? Boolean logical operators:!,&, ¦, ^, &&,¦¦
? Bitwise operators: &,¦,^,~, >>, < <,>>>
? Assignment Operator: = Extended assignment Operator: +=,―=,*=,/=
? String Join operator: +
? Styling Operator: ()

The function and usage of 8.super,this key words
? Use super in a Java class to refer to the composition of the parent class
– can be used to access properties defined in the parent class super
– can be used to call member methods defined in the parent class super
– Constructor super that can be used to call the parent class in the subclass constructor
– The traceability is not only to the direct parent class super
? In order to solve the naming conflict and uncertainty problem of variables, the keyword "This" is introduced to represent the current object of the method in which it resides. Java
– The new object created by the constructor is the middle of the constructor
– Method The object that called the method
? Usage of the keyword this
– Reference the instance variables and methods of the class in the method or constructor of the class itself
– Passing the current object as a parameter to another method or constructor
– The constructor used to invoke the other overloads

9. What is an expression in Java? What's the effect?
? Expressions are the combination of operators and operands, which are a key component of any programming language
? Expressions allow programmers to perform mathematical calculations, comparison of values, logical operations, and manipulation of objects in Java.
? Some examples of expressions:
–x
–x+10
–y=x+10
–ARR[10]
–student.gename ()

10. The table lists all the modifiers in Java and their scope of application (can not modify the constructor, attributes, free blocks, etc.)
Class Attribute method Builder free block inner classes
Publicly y y y y y
Protected y y x y y
(Default) Y-y y y y y
Private y y y y
Final y y y
Abstract y y y
Static Y y y


11. Write a method to print a 99 multiplication table with a for loop
/**
* One for loop print 99 multiplication table
*/
Publicvoid nineninemultitable ()
{
for (int i = 1,J = 1; J <= 9; i++) {
System.out.print (i+ "*" +j+ "=" +i*j+ "");
if (I==J)
{
i=0;
j + +;
System.out.println ();
}
}
}
12. Given a Java.util.Date object, how to convert the string to "2007-3-22 20:23:22" format
/**
* Convert a date into a string in a fixed format
* @paramdate
* @returnstr
*/
Public String datetostr (java.util.Date Date)
{
SimpleDateFormat SDF = new SimpleDateFormat ("Yyyy-mm-dd HH:mm:ss");
String str = sdf.format (date);
return str;
}
13. Write a method that can determine whether any integer is a prime number
/**
* Determine whether any integer is a prime number
* @paramn
* @returnboolean
*/
Publicboolean isprimes (int n)
{
for (int i = 2; I <= math.sqrt (n); i++) {
if (n%i==0)
{
Returnfalse;
}
}
Returntrue;
}
14. Write a method, enter any integer, and return its factorial
/**
* Get the factorial of any one integer
* @paramn
* @returnn!
*/
publicint factorial (int n)
{
Recursive
if (n==1)
{
return 1;
}
Return n*factorial (n-1);
Non-recursive
int multi = 1;
for (int i = 2; I <= n; i++) {
Multi*=i;
// }
return multi;
}
15. Write a method that uses a binary lookup method to determine whether an arbitrary integer exists in an array of arbitrary integers, and if it exists, returns its index position in the array, no return-1
/**
* Binary finds the position of a specific integer in an array of integers (recursive)
* @paramdataset
* @paramdata
* @parambeginIndex
* @paramendIndex
* @returnindex
*/
Publicint BinarySearch (int[] dataset,int data,int beginindex,int endIndex)
{
int midindex = (beginindex+endindex)/2;
if (data <dataset[beginindex]¦&brvbardata>dataset[endindex]¦&brvbarbeginindex>endindex) return-1 ;
if (data <dataset[midindex])
{
return BinarySearch (dataset,data,beginindex,midindex-1);
}elseif (Data>dataset[midindex])
{
return BinarySearch (Dataset,data,midindex+1,endindex);
}else
{
return midindex;
}
}

/**
* Binary finds the position of a specific integer in an array of integers (non-recursive)
* @paramdataset
* @paramdata
* @returnindex
*/
Publicint BinarySearch (int[] DataSet, int data)
{
int beginindex = 0;
int endIndex = dataset.length-1;
int midindex =-1;
if (data <dataset[beginindex]¦&brvbardata>dataset[endindex]¦&brvbarbeginindex>endindex) return-1 ;
while (Beginindex <= endIndex) {
Midindex = (beginindex+endindex)/2;
if (data <dataset[midindex]) {
EndIndex = midIndex-1;
} elseif (Data>dataset[midindex]) {
Beginindex = midindex+1;
}else
{
return midindex;
}
}
return-1;
}
16. An example of feeding a breeder to an animal is the object-oriented idea in Java, the usefulness of an interface (abstract class).
Package Com.softeem.demo;

/**
* @authorleno
* Animal Interface
*/
Interface Animal
{
Publicvoid Eat (food and food);
}
/**
* @authorleno
* One animal Category: Cat
*/
Class Cat implements Animal
{
Publicvoid Eat (food)
{
System.out.println ("Kitten Eats" +food.getname ());
}
}
/**
* @authorleno
* One animal Category: Dog
*/
Class Dog implements Animal
{
Publicvoid Eat (food)
{
System.out.println ("Puppy gnawing" +food.getname ());
}
}

/**
* @authorleno
* Food abstract class
*/
AbstractClass Food
{
protected String name;
Public String GetName () {
Returnname;
}

Publicvoid setName (String name) {
THIS.name = name;
}
}

/**
* @authorleno
* One food Category: Fish
*/
Class Fish extends Food
{
Public Fish (String name) {
THIS.name = name;
}
}
/**
* @authorleno
* One food Category: Bones
*/
Class Bone extends Food
{
Public Bone (String name) {
THIS.name = name;
}
}

/**
* @authorleno
* Breeder Class
*
*/
Class Feeder
{
/**
* A breeder feeds a certain animal to some kind of food
* @paramanimal
* @paramfood
*/
Publicvoid Feed (Animal animal,food food)
{
Animal.eat (food);
}
}

/**
* @authorleno
* Test keepers to feed animals
*/
Publicclass Testfeeder {

Publicstaticvoid Main (string[] args) {
Feeder feeder=new feeder ();
Animal animal=new Dog ();
Food food=new Bone ("Meat Bones");
Feeder.feed (Animal,food); To feed the dog to the meat bones
Animal=new Cat ();
Food=new Fish ("fishes");
Feeder.feed (Animal,food); Feed the cat to the fish


}
}
17. Describe the mechanism of exception handling in Java
? If an exception occurs during the execution of the program, an exception class object is automatically generated, and the exception object is referred to the Java Runtime System, which is called throw (throw) exception. Java
? When the Java runtime system receives an exception object, it looks for code that can handle the exception and hands the current exception object to its processing, a process known as catch (Catch) exception.
? If the Java runtime system cannot find a way to catch an exception, the runtime system terminates and the corresponding Java program exits.
? Programmers usually have to deal with violations (Exception), and they can do nothing about errors (error).

Java Interview related

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.