(678) 643-7777
(678) 248-0302
Java SE Tutorials RSS feed for this section

What is a native method?

A native method is a method that is implemented in a language other than Java.

Comments Off on What is a native method? Continue Reading →

In System.out.println(), what is System, out and println?

System is a predefined final class, out is a PrintStream object and println is a built-in overloaded method in the out object.

Comments Off on In System.out.println(), what is System, out and println? Continue Reading →

What is implicit casting?

Implicit casting is the process of simply assigning one entity to another without any transformation guidance to the compiler. This type of casting is not permitted in all kinds of transformations and may not work for all scenarios. Example int i = 1000; long j = i; //Implicit casting

Comments Off on What is implicit casting? Continue Reading →

How to convert String to Number in java program?

The valueOf() function of Integer class is is used to convert string to Number. Here is the code example: String numString = “1000″; int id=Integer.valueOf(numString).intValue();

Comments Off on How to convert String to Number in java program? Continue Reading →

Why there are no global variables in Java?

Global variables are globally accessible. Java does not support globally accessible variables due to following reasons: The global variables breaks the referential transparency Global variables create collisions in namespace.

Comments Off on Why there are no global variables in Java? Continue Reading →

What is the Java API?

The Java API is a large collection of ready-made software components that provide many useful capabilities, such as graphical user interface (GUI) widgets.

Comments Off on What is the Java API? Continue Reading →

What is the difference between final, finally and finalize? What do you understand by the java final keyword?

final – declare constant finally – handles exception finalize – helps in garbage collection Variables defined in an interface are implicitly final. A final class can’t be extended i.e., final class may not be subclassed. This is done for security reasons with basic classes like String and Integer. It also allows the compiler to make […]

Comments Off on What is the difference between final, finally and finalize? What do you understand by the java final keyword? Continue Reading →

What if the static modifier is removed from the signature of the main method?

Program compiles. But at runtime throws an error “NoSuchMethodError”.

Comments Off on What if the static modifier is removed from the signature of the main method? Continue Reading →

What are the differences between == and .equals() ?

The == operator compares two objects to determine if they are the same object in memory i.e. present in the same memory location. It is possible for two String objects to have the same value, but located in different areas of memory. == compares references while .equals compares contents. The method public boolean equals(Object obj) […]

Comments Off on What are the differences between == and .equals() ? Continue Reading →

Expain the reason for each keyword of public static void main(String args[])?

public – main(..) is the first method called by java environment when a program is executed so it has to accessible from java environment. Hence the access specifier has to be public. static : Java environment should be able to call this method without creating an instance of the class , so this method must […]

Comments Off on Expain the reason for each keyword of public static void main(String args[])? Continue Reading →

What is an immutable object?

Immutable objects whose state (i.e. the object’s data) does not change once it is instantiated (i.e. it becomes a read-only object after instantiation). Immutable classes are ideal for representing numbers (e.g. java.lang.Integer, java.lang.Float, java.lang.BigDecimal etc are immutable objects)

Comments Off on What is an immutable object? Continue Reading →

What is the default value of the local variables?

The local variables are not initialized to any default value, neither primitives nor object references.

Comments Off on What is the default value of the local variables? Continue Reading →

What if I write static public void instead of public static void?

Program compiles and runs properly.

Comments Off on What if I write static public void instead of public static void? Continue Reading →

If I don’t provide any arguments on the command line, then the String array of Main method will be empty or null?

It is empty. But not null.

Comments Off on If I don’t provide any arguments on the command line, then the String array of Main method will be empty or null? Continue Reading →

What is classloader?

The classloader is a subsystem of JVM that is used to load classes and interfaces.There are many types of classloaders e.g. Bootstrap classloader, Extension classloader, System classloader, Plugin classloader etc.

Comments Off on What is classloader? Continue Reading →

What gives Java its ‘write once and run anywhere’ nature?

The bytecode. Java is compiled to be a byte code which is the intermediate language between source code and machine code. This byte code is not platform specific and hence can be fed to any platform.

Comments Off on What gives Java its ‘write once and run anywhere’ nature? Continue Reading →

What is the main difference between Java platform and other platforms?

The Java platform differs from most other platforms in the sense that it’s a software-based platform that runs on top of other hardware-based platforms.It has two components: Runtime Environment API(Application Programming Interface)

Comments Off on What is the main difference between Java platform and other platforms? Continue Reading →

What is JIT compiler?

Just-In-Time(JIT) compiler:It is used to improve the performance. JIT compiles parts of the byte code that have similar functionality at the same time, and hence reduces the amount of time needed for compilation.Here the term “compiler” refers to a translator from the instruction set of a Java virtual machine (JVM) to the instruction set of […]

Comments Off on What is JIT compiler? Continue Reading →

How many types of memory areas are allocated by JVM?

Class(Method) Area Heap Stack Program Counter Register Native Method Stack

Comments Off on How many types of memory areas are allocated by JVM? Continue Reading →

What is difference between JDK,JRE and JVM?

JVM JVM is an acronym for Java Virtual Machine, it is an abstract machine which provides the runtime environment in which java bytecode can be executed. JVMs are available for many hardware and software platforms (so JVM is plateform dependent). JRE JRE stands for Java Runtime Environment. It is the implementation of JVM and physically […]

Comments Off on What is difference between JDK,JRE and JVM? Continue Reading →

What is Java Serial Version ID?

Say you create a ‘Car’ class, instantiate it, and write it out to an object stream. The flattened car object sits in the file system for some time. Meanwhile, if the ‘Car’ class is modified by adding a new field. Later on, when you try to read (i.e. deserialize) the flattened ‘Car’ object, you get […]

Comments Off on What is Java Serial Version ID? Continue Reading →

What are the usages of Java packages?

It helps resolve naming conflicts when different packages have classes with the same names. This also helps us organize files within project. For example: java.io package do something related to I/O and java.net package do something to do with network and so on. If we tend to put all .java files into a single package, […]

Comments Off on What are the usages of Java packages? Continue Reading →

What are wrapped classes?

Wrapped classes are classes that allow primitive types to be accessed as objects.

Comments Off on What are wrapped classes? Continue Reading →

What does it mean that a method or field is “static”?

Static variables and methods are instantiated only once per class. In other words they are class variables, not instance variables. If you change the value of a static variable in a particular object, the value of that variable changes for all instances of that class. Static methods can be referenced with the name of the […]

Comments Off on What does it mean that a method or field is “static”? Continue Reading →

What is a local, member and a class variable?

Variables declared within a method are “local” variables. Variables declared within the class i.e not within any methods are “member” variables (global variables). Variables declared within the class i.e not within any methods and are defined as “static” are class variables.

Comments Off on What is a local, member and a class variable? Continue Reading →

What modifiers are allowed for methods in an Interface?

Only public and abstract modifiers are allowed for methods in interfaces.

Comments Off on What modifiers are allowed for methods in an Interface? Continue Reading →

What is transient variable?

Transient variable can’t be serialize. For example if a variable is declared as transient in a Serializable class and the class is written to an ObjectStream, the value of the variable can’t be written to the stream instead when the class is retrieved from the ObjectStream the value of the variable becomes null

Comments Off on What is transient variable? Continue Reading →

What is reflection API? How are they implemented?

Reflection is the process of introspecting the features and state of a class at runtime and dynamically manipulate at run time. This is supported using Reflection API with built-in classes like Class, Method, Fields, Constructors etc. Example: Using Java Reflection API we can get the class name, by using the getName method.

Comments Off on What is reflection API? How are they implemented? Continue Reading →

Explain working of Java Virtual Machine (JVM)?

JVM is an abstract computing machine like any other real computing machine which first converts .java file into .class file by using Compiler (.class is nothing but byte code file.) and Interpreter reads byte codes.

Comments Off on Explain working of Java Virtual Machine (JVM)? Continue Reading →

What are the differences between C++ and Java?

Both C++ and Java use similar syntax and are Object Oriented, but: Java does not support pointers. Pointers are inherently tricky to use and troublesome. Java does not support multiple inheritances because it causes more problems than it solves. Instead Java supports multiple interface inheritance, which allows an object to inherit many method signatures from […]

Comments Off on What are the differences between C++ and Java? Continue Reading →

Advantage of using Java?

Java is a fun language. Some of the reasons to use it are: Built-in support for multi-threading, socket communication, and memory management (automatic garbage collection). Object Oriented (OO). Better portability than other languages across operating systems. Supports Web based applications (Applet, Servlet, and JSP), distributed applications (sockets, RMI, EJB etc) and network protocols (HTTP, JRMP […]

Comments Off on Advantage of using Java? Continue Reading →

How are this() and super() used with constructors?

this() is used to invoke a constructor of the same class. super() is used to invoke a superclass constructor.

Comments Off on How are this() and super() used with constructors? Continue Reading →

What restrictions are placed on method overloading?

Two methods may not have the same name and argument list but different return types.

Comments Off on What restrictions are placed on method overloading? Continue Reading →

How are parameters passed in Java, by value or by reference?

By value but in the case of objects, the value is a reference.

Comments Off on How are parameters passed in Java, by value or by reference? Continue Reading →

How do you call a method in a super class from a subclass?

Use the super keyword like so: super.someMethodCall(“some string parameter” ); Note that in most cases the super keyword may be omitted.

Comments Off on How do you call a method in a super class from a subclass? Continue Reading →

How do you call a constructor of a super class? Where would you call it?

A call to the default super class constructor is implicitly the first line of each constructor unless a different constructor is explicitly provided by the developer. So for the first line of a constructor that calls a non-default super class constructor, one might write: super(“some string”); It’s a compilation error if it is not the […]

Comments Off on How do you call a constructor of a super class? Where would you call it? Continue Reading →

Where would you use the keyword extends and implements?

extends is the keyword used to declare that this class is a subclass of the class that follows the extends keyword. Implements is a keyword that designates this class as an implementer of the specified interface.

Comments Off on Where would you use the keyword extends and implements? Continue Reading →

What is an abstract class?

An abstract class is a class declared with the abstract keyword. Although references to such a class may be used, the class may not be directly instantiated. Abstract classes may define methods or just declare them and may contain variables.

Comments Off on What is an abstract class? Continue Reading →

What are the four types of nested classes?

1. static nested class 2. inner (non-static) nested class 3. local class 4. anonymous class A static nested class is just like a normal Java class. If it is public, it can be accessed or used to create objects just like any other class. A non-static inner class requires an object of the containing class. […]

Comments Off on What are the four types of nested classes? Continue Reading →

Why would you declare a class final?

Making a class final adds some security and consistency to the class behaviour. E.g. by making the String class final, you cannot override its length method. The compiler may optimize the code and make it run faster when a class is declared final.

Comments Off on Why would you declare a class final? Continue Reading →

What is a static method?

A static method is associated with a class rather than an object of that class. It can be invoked without using an instance of that class. For example: public class A { static public doStuff(){ } } //Usage: A.doStuff();

Comments Off on What is a static method? Continue Reading →

What is the difference between constructors and other methods?

A constructor has no return type and has the same name as the class.

Comments Off on What is the difference between constructors and other methods? Continue Reading →

What are primitive wrapper classes?

Wrapper classes are used to wrap a primitive type in an Object, mainly to make it easier to use them in a collection and for using reflection. The action of converting from a primitive type to a wrapper type is called boxing. The other way around ( wrapper to primitive ) is called unboxing. Some […]

Comments Off on What are primitive wrapper classes? Continue Reading →

What does the default toString() method implementation do?

Returns the class name and hash code. If this is not the desired representation of the object, the developer should override it.

Comments Off on What does the default toString() method implementation do? Continue Reading →

What are some methods defined in the Object class and how are they useful?

getClass() returns the class object. hashCode() and equals() are useful for comparison and in collections. notify(), notifyAll() and wait() are used in thread synchronization. toString() is used to get a string representation of the object. clone() is used to get a deep copy of the object. finalize() is useful for clean up just before garbage […]

Comments Off on What are some methods defined in the Object class and how are they useful? Continue Reading →

What are some advantages of all classes deriving from a common class like Object?

Every class inherits all the methods defined in Object. These include methods to get the class name, getClass() and various methods related to synchronization like, wait() or notify() and methods useful for storing an object in a collection like hashCode() or equals().

Comments Off on What are some advantages of all classes deriving from a common class like Object? Continue Reading →

Given an interface, how would you make your class behave like the interface.

//Where Class A uses interface B public class A implements B { // Must define methods declared in B }

Comments Off on Given an interface, how would you make your class behave like the interface. Continue Reading →

How do you derive a new class from a class?

Where A is a subclass of B, public class A extends B { // class contents }

Comments Off on How do you derive a new class from a class? Continue Reading →

What is the difference between an abstract class and an interface?

  Interfaces don’t define methods. Also, classes cannot inherit from more than one class, abstract or not, while a class may implement many interfaces. Both can have constant declarations but in an interface they are implicitly public static and final. How do you derive a new class from a class? Where A is a subclass […]

Comments Off on What is the difference between an abstract class and an interface? Continue Reading →

What is jar in Java

JAR file (Java ARchive) A JAR file is actually just a ZIP file. It can contain anything – usually it contains compiled Java code (*.class), but sometimes also Java sourcecode (*.java). The Java Archive (JAR) file format enables you to bundle multiple files into a single archive file. Typically a JAR file contains the class files […]

Comments Off on What is jar in Java Continue Reading →

Java Programming Basics

Introduction to Java Programming Java technology is used to develop applications for a wide range of environments, from consumer devices to heterogeneous enterprise systems. Java programs are portable across operating systems and hardware environments. Like any programming language, the Java language has its own structure, syntax rules, and programming paradigm. The Java language’s programming paradigm is […]

Comments Off on Java Programming Basics Continue Reading →
Watch BA Video

summer-java-ap-new-copy