What is Java?
Java is a high-level platform-independent object oriented programming language.
List some features of Java?Object Oriented, Platform Independent, Multi-threaded, Interpreted, Robust, pass-by-value.
Talk about Java Object Oriented features?Inheritance: subclasses can inherit properties from superclasses.
Overriding: subclasses can override the existing method of superclasses.
Polymorphism: the object has the ability to take on many forms. for example, ...
Abstraction: it means hiding the implementation details from the user.
Encapsulation: it means wrapping the variables and code together as a single unit, known as data hiding, can be accessed only through their current class.
Interface: it is a collection of abstract methods and cannot be instantiated.
Packages: it is used to prevent naming conflicts and control access.
Java"s compiler generates an architectural neutral object file format, which makes the compiled code executable on many processors with the presence of Java runtime system.
Why is Java considered dynamic?Java programs carries runtime information that can be used to verify and resolve accesses to objects on runtime.
What is JVM and how it represents Java"s platform-independent feature?JVM is available for many hardware and software platforms, it is a abstract machine that provides the runtime environment in which Java byte code can be executed.
When Java code is compiled into platform-independent byte code, this byte code is interpreted by JVM on whatever platform it is being run.
JRE: Java Runtime Environment is an implementation of JVM, it provides the minimum requirements for executing a Java application.
JDK: Java Development Kit is bundle of software that you can use to develop Java based software, it contains one or more JRE"s and development tools like Java source compilers, debuggers and libraries, etc.
JAR: Java Archive File, it aggregates many files into one like a ZIP file.
WAR: Web Archive File, it is used to store XML, Java classes, JSP files and static web pages.
Eclipse, Netbeans, IntelliJ.
Define Object and Class?We use class, which contains fields and methods, to create an object. Object is a runtime entity with its state stored in field and its behavior shown via methods.
What are three variables that a class might have?Local Variable: they are inside methods, blocks or constructors.
Instance Variable: they are within a class but outside the methods. They are instantiated when the class is loaded.
Class Variable: they are declared with keyword static, inside a class but outside the methods.
What is Singleton class?Singleton pattern restricts the class to be instantiated into only one object.
What is Constructor?When a new object is created, a constructor is invoked. Therefore, every class has a default constructor if we do not write a explicit one.
By the way, constructor is not inherited and cannot be final.
Autoboxing is the Java compiler automatically transform the primitive type into their wrapper type for the ease of compilation.
Unboxing is the automatic transformation of wrapper types into their primitive types.
Declare the object, instantiate the object, initialize the object.
What is default value of data types: byte, float and double?For byte, 0; For float: 0.0f; For double: 0.0d.
When to use byte datatype?When we have some large int arrays, using byte(8 bit) can save more space than int(32 bit).
Define Access Modifier?Access Modifiers are used to set access level for classes, variables, methods and constructors.
What is protected Access Modifier?Variables, methods or constructors which are declared protected, can be accessed only by its subclasses(in this package or other package) or package member.
Class | Package | Subclass | World | ||
public | + | + | + | + | |
protected | + | + | + | ||
no modifier | + | + | |||
private | + |
+: accessible
: not accessible
The modifier synchronized indicates that the method can be accessed by only one thread at a time.
Which operator has highest precedence?Brackets () and square brackets [].
What variables can be used in a switch statement?Only 6 types: string, char, byte, short, int, enum.
Compare String, StringBuilder and StringBuffer?String is considered immutable because once created, the String object cannot be changed. Thus String is important in multithreading programming. e.g. str = str + "hello"; Here the original String str is not changed, but internally a new object is created.
StringBuilder is faster than StringBuffer, but StringBuffer is thread safe.
Exception is the problem occurs during the execution of a program.
Unchecked Exception:
Unchecked exception inherits from RuntimeException.
Runtime exception can be avoided by the programmer and can be ignored during compilation, you will need to extend the RuntimeException class if you want to write a runtime exception.
Checked Exception:
Checked Exception is a problem that cannot be foreseen by the programmer and cannot be ignored in compilation;
The client code has to handle the checked exceptions either in try-catch clause or has to be thrown for the super class.
A Checked Exception thrown by subclass enforces a contract on the superclass to catch or throw it.
You will need to extend the Exception class if you want to write a Checked Exception.
Error:
usually thrown for more serious problems and not easy to handle. e.g. OutOfMemoryError.
What is the difference between throws and throw?throws: declared at the end of method signature if a method does not handle checked exception.
throw: used to throw an explicit exception that you just caught or instantiated.
finally keyword is used to create a block of code following a try block.
The finally block always executes whether an exception occurs or not.
Inheritance is the process that one class A extends the properties of class B. Class A is known as child class or subclass, class B is known as superclass or parent class.
When to use super keyword?If a method overrides its superclass"s method, we can use the keyword super to invoke the overridden method.
What is Polymorphism?Polymorphism is the ability of an object to take on many forms and do different things. For example:
public class sedan extends automobile implements car { sedan camry = new sedan(); }
Therefore, camry is a car, is an automobile, is a sedan, is an Object. As it has multiple inheritances, camry is polymorphic.
What is Abstract class?Abstract class helps to reduce complexity and improves maintainability and reusability of the system. The implementation of abstract class is determined by its child classes.
What is Encapsulation?Encapsulation means hiding the implementation details from users.
Declare fields private, and provide the access to the fields via public methods within the class.
Example:
public class people { private String name; private int age; public String getName() { return name; } public int getAge() { return age; } public void setName(String n) { name = n; } public void setAge(int a) { age = a; } }Interface vs. Abstract?
An interface is a collection of abstract methods. When a class implements an interface, it would inherit all the abstract methods of the interface.
Interface has some features:
It cannot be instantiated.
It does not have constructors.
Its methods are all abstract.
What is Packages?A package is a group of related classes or interfaces, providing access protection and namespace management. It is used to prevent naming conflicts and to control access for easier usage of classes, interfaces, annotations and enumerations.
What is Multithreading?A multithreaded program contains two parts that can run concurrently. Each part is called a thread and each thread defines a separate path of execution.
How is Thread created?By implementing runnable interface, or extending the Thread class.
Compare overloading and overriding?Method Overloading is: a class has multiple functions with same name but different parameters.
Method Overriding is: a subclass has a specific implementation of a method provided by its superclass. Same Parameters.
Constructor is used to create an instance of a class.
Constructor is invoked only once while a class is being instantiated.
Constructor can be public, private, protected.
Constructor doesn"t return a value, but you don"t need to specify it as void.
Java doesn"t support Copy Constructor.
Final class cannot be inherited. The methods in final class cannot be overridden.
How can a thread enter the waiting state?By invoking its sleep() method or (deprecated) suspend() method;
By blocking on IO;
By unsuccessfully acquiring an object"s lock;
By invoking an object"s wait() method;
ArrayList | linkedList |
Random Access | Sequential Access |
Only objects can be added | ListNode contains prev/next node link and its own value |
An object that implements Enumeration interface allows sequential access to all the elements in the collection.
What is the difference between Iterator and Enumeration Interface?They all give successive elements.But, Iterator makes the method name shorter, and Iterator has remove() method while Enumeration doesn"t.
Enumeration | Iterator |
hasMoreElement() | hasNext() |
nextElement() | next() |
N/A | remove() |
Their common limitation is: can only move forward; cannot add or replace object.
Why do we use Vector class?If we don"t know the size of the array or we want to change the size over the program"s lifetime, we can use Vector class to implement a growable array of objects.
What are Wrapper classes?Wrapper classes are used to access primitive types as objects.
What is a transient variable?It is a variable that cannot be serialized during serialization.
What is Synchronization?Synchronization is used to control the access of multiple threads to shared resources. Using keyword synchronized will provide locking to ensure mutual access of shared resources and prevent data race.
List Primitive Data Types?byte, int, short, long, float, double, char, boolean.
What are Java run-time exceptions?RuntimeException and Error exceptions.
What is the life cycle of a thread?Newborn state, Runnable state, Running state, Blocked state, Dead state.
What is Sockets?Client application creates a socket and attempts to connect it to the server. Sockets provide communication between two computers using TCP.
What is classloader?Classloader is a subsystem of JVM and is used to load classes and interfaces, like Bootstrap classloader, plugin classloader.
Can Interface extend another Interface?Yes, and an Interface can extend more than one interface.
Talk about pass-by-value and pass-by-reference?Yes, Java is pass-by-value.
A variable, aka: an object"s reference, will tell the JVM how to get to the referenced object in memory.
So when passing arguments to a method, you are not passing the reference variable but the copy of the bits in the reference variable.
So what is that? That is the value of the reference, not the reference itself, not the object.
public class Main { public static void main(String[] args) { Student s = new Student("John"); changeName(s); System.out.printf(s); // will print "John" modifyName(s); System.out.printf(s); // will print "Dave" } public static void changeName(Student a) { Student b = new Student("Mary"); a = b; } public static void modifyName(Student c) { c.setAttribute("Dave"); } }
Another Example
public static void changeContent(int[] arr) { // If we change the content of arr. arr[0] = 10; // Will change the content of array in main() } public static void changeRef(int[] arr) { // If we change the reference arr = new int[2]; // Will not change the array in main() arr[0] = 15; } public static void main(String[] args) { int [] arr = new int[2]; arr[0] = 4; arr[1] = 5; changeContent(arr); System.out.println(arr[0]); // Will print 10.. changeRef(arr); System.out.println(arr[0]); // Will still print 10.. // Change the reference doesn"t reflect change here.. }
文章版權歸作者所有,未經允許請勿轉載,若此文章存在違規行為,您可以聯系管理員刪除。
轉載請注明本文地址:http://specialneedsforspecialkids.com/yun/66208.html
摘要:原文鏈接猛戳這里構造函數下面生成實例這時和會自動含有一個屬性,指向它們的構造函數。這個對象的所有屬性和方法,都會被構造函數的實例繼承。 JavaScript的嚴格模式和正常模式 use strict; 顧名思義也就是 JavaScript 會在所謂嚴格模式下執行,其一個主要的優勢在于能夠強制開發者避免使用未聲明的變量。對于老版本的瀏覽器或者執行引擎則會自動忽略該指令。 在正常模式中,...
摘要:注意目前發現有其他人以團隊名義進行招聘,發出的郵箱皆為私人郵箱。為防止在投遞簡歷出現誤會,在此提醒各位注意團隊沒有以任何個人名義或郵箱進行招聘。的面試過程我們一般會有輪面試,對于高級別的工程師可能會有輪面試。 fex-team/interview-questions 注意 目前發現有其他人以 FEX 團隊名義進行招聘,發出的郵箱皆為私人郵箱。 為防止在投遞簡歷出現誤會,在此提醒各位注意...
摘要:注意目前發現有其他人以團隊名義進行招聘,發出的郵箱皆為私人郵箱。為防止在投遞簡歷出現誤會,在此提醒各位注意團隊沒有以任何個人名義或郵箱進行招聘。的面試過程我們一般會有輪面試,對于高級別的工程師可能會有輪面試。 fex-team/interview-questions 注意 目前發現有其他人以 FEX 團隊名義進行招聘,發出的郵箱皆為私人郵箱。 為防止在投遞簡歷出現誤會,在此提醒各位注意...
摘要:注意目前發現有其他人以團隊名義進行招聘,發出的郵箱皆為私人郵箱。為防止在投遞簡歷出現誤會,在此提醒各位注意團隊沒有以任何個人名義或郵箱進行招聘。的面試過程我們一般會有輪面試,對于高級別的工程師可能會有輪面試。 fex-team/interview-questions 注意 目前發現有其他人以 FEX 團隊名義進行招聘,發出的郵箱皆為私人郵箱。 為防止在投遞簡歷出現誤會,在此提醒各位注意...
閱讀 1267·2023-04-25 23:22
閱讀 1668·2023-04-25 20:04
閱讀 2643·2021-11-22 15:24
閱讀 2801·2021-11-11 16:54
閱讀 1879·2019-08-30 14:03
閱讀 1480·2019-08-29 16:35
閱讀 1700·2019-08-26 10:29
閱讀 2643·2019-08-23 18:01