BufferedWriter Constructors only accept another Writer as argument. BufferedReader helps to read the file line by line.
BufferedReader Constructors only accept another Reader as argument. PrintWriter provides advanced methods to write formatted text to the file. It supports printf function. Other than write function you can use format, printf, print, println functions to write to PrintWriter file. There is an Inheritance as well as Composition relationship between Vehicle and Car which is not permitted. We cannot initialize the parent class instance within the constructor. Call to super is illegal. There is no problem.
Which are the different segments of memory? Heap Segment - Contains all created objects in runtime, objects only plus their object attributes instance variables , Static variables are also stored in heap. Code Segment - The segment where the actual compiled Java bytecodes resides when loaded.
Code Segment. Class Segment. Stack Memory Segment. Heap Memory Segment. Runtime Constant Pool within Heap Segment. Which of following memory segment is cleaned by Garbage Collection Mechanism? Does garbage collection guarantee that a program will not run out of memory?
Garbage collection does not guarantee that a program will not run out of memory. It is possible for programs to use up memory resources faster than they are garbage collected. It is also possible for programs to create objects that are not subject to garbage collection. Try 1 Question s Test. Which of the following about Garbage collection is false? We can call Garbage collection explicitly.
Garbage Collection guarantees that the application will not run out of memory. Garbage Collection Mechanism delete unclaimed objects that are no longer required. Why Char array is preferred over String for storing password? String is immutable in java and stored in String pool. Once it's created it stays in the pool until unless garbage collected, so even though we are done with password it's available in memory for longer duration and there is no way to avoid it.
It's a security risk because anyone having access to memory dump can find the password as clear text. Instead of a process calling series of processes, this model stresses on communication between objects. Objects that all self sustained, provide security by encapsulating it's members and providing abstracted interfaces over the functions it performs. OOP's facilitate the following features 1. Inheritance for Code Reuse 2.
Abstraction for modularity, maintenance and agility 3. Encapsulation for security and protection 4. Polymorphism for flexibility and interfacing. What are different ways to create String Object?
There are total six ways 1. If found, it just returns the reference to that String object else it creates a new String object with given value and stores it in the String pool. We can use intern method to store the String object into String pool or return the reference if there is already a String with equal value present in the pool. Frequently asked at Manhattan Associates Based on 2 feedback. What is a Lambda Expression? What's its use? Its an anonymous method without any declaration.
Lambda Expression are useful to write shorthand Code and hence saves the effort of writing lengthy Code. It promotes Developer productivity, Better Readable and Reliable code. Sample Code for lambda. Java 5. Java 7. Java 8. Java 9. Why do we need Inner classes?
Cant we just work with outer classes wherever we implement Inner classes? Yes, we can substitute outer classes wherever we need to have inner classes but Inner classes have advantage in certain cases and hence preferred - Ease - Why to implement a class outside if its objects are only intended to be part of an outer object. Its easy to define the class within another class if the use is only local. Protection - Making a call an outer exposes a threat of it being used by any of the class.
Why should it be made an outer class if its object should only occur as part of other objects. For example - You may like to have an class address whose object should have a reference to city and by design thats the only use of city you have in your application.
Making Address and City as outer class exposes City to any of the Class. Making it an inner class of Address will make sure that its accessed using object of Address. Sample Code for inner class. Simple Inner Class. Static Nested Inner Class. Method Nested Static Inner Class. Anonymous Inner Class. What is the difference between declaration, instantiation and initialization? Declaration is intimation to the compiler about the nature of Data a reference is going to hold. For example - List myList; Instantiation is reservation of memory.
The only difference is that 2nd will initialized the member elements to their default values whereas 3rd will initialized it with the elements from set. Very frequently asked to Fresh graduates. What is the difference between Encapsulation and Abstraction? Abstraction solves the problem at design level while encapsulation solves the problem at implementation level 2. Abstraction is used for hiding the unwanted data and giving relevant data.
Abstraction lets you focus on what the object does instead of how it does it while Encapsulation means hiding the internal details or mechanics of how an object does something. For example: Outer Look of a Television, like it has a display screen and channel buttons to change channel it explains Abstraction but Inner Implementation detail of a Television how CRT and Display Screen are connect with each other using different circuits , it explains Encapsulation.
Try 2 Question s Test. Which of the following Java feature promotes Code Re usability? What do you mean by "Java is a statically typed language"?
It means that the type of variables are checked at compile time in Java. The main advantage here is that all kinds of checking can be done by the compiler and hence will reduce bugs. Favorite question in Walk in Drive of many Indian service companies. What is the difference between final, finally and finalize? The finally block is optional and provides a mechanism to clean up regardless of what happens within the try block. Use the finally block to close files or to release other system resources like database connections, statements etc.
A method that is invoked before an object is discarded by the garbage collector, allowing it to clean up its state. Which of the following is wrong for final instance variables? They cannot be changed after initialization. They can be initialized directly within static method. They can be declared and initialized together at the same place. They can be initialized within constructor. Final methods cannot be overriden.
Java is still an object oriented language where everything is done keeping objects data in mind. But, with the introduction of new features in Java 8, you can use Java as a functional programming language also. You can treat it as as an added advantage over the other languages which are either object oriented or functions oriented. From Java 8, you can use Java either in an object-oriented programming paradigm or in a functional programming paradigm.
It supports both. Lambda expressions, functional interfaces and Stream API are the three main features of Java 8 which enables developers to write functional style of programming in Java also.
How this feature has changed the way you write code in Java? Explain with some before Java 8 and after Java 8 examples? Lambda Expressions can be defined as methods without names i. Like methods, they also have parameters, a body, a return type and possible list of exceptions that can be thrown. But unlike methods, neither they have names nor they are associated with any particular class.
Lambda expressions are used where an instance of functional interface is expected. Before Java 8, anonymous inner classes are used for this purpose.
After Java 8, you can use lambda expressions to implement functional interfaces. These lambda expressions have changed the style of programming in Java significantly.
They have made the Java code more clear, concise and readable than before. For example,. Below code shows how Comparator interface is implemented using anonymous inner class before Java 8. Implementation of Runnable interface using anonymous inner class before Java 8 :. The signature of lambda expressions are derived from the signature of abstract method of functional interface. In this example, target type of lambda expression is Runnable. Compiler uses run method of Runnable interface to check the return type of lambda expression.
Only final local variables are allowed to use inside a lambda expressions just like anonymous inner classes. See More : Java 8 Lambda Expressions. Do they exist before Java 8 or they are the whole new features introduced in Java 8? Functional interfaces are the interfaces which has exactly one abstract method. Functional interfaces provide only one functionality to implement. There were functional interfaces exist before Java 8. It is not like that they are the whole new concept introduced only in Java 8.
Runnable , ActionListener , Callable and Comaprator are some old functional interfaces which exist even before Java 8. The new set of functional interfaces are introduced in Java 8 for writing lambda expressions. Lambda expressions must implement any one of these new functional interfaces. In which package they have kept in? Below is the list of new functional interfaces introduced in Java 8.
They have kept in java. Predicate is a functional interface which represents a boolean operation which takes one argument. BiPredicate is also functional interface but it represents a boolean operation which takes two arguments. Function is a functional interface which represents an operation which takes one argument of type T and returns result of type R.
0コメント