Java Training

Core Java

Trending Questions and Lessons

Follow 34,729 Followers

Ask a Question

Feed

All

All

Lessons

Discussion

Lesson Posted on 05 Feb IT Courses/Java/Core Java

Thread Class In JAVA

SR-IT Academy

SR - IT Academy is one of the leading tutorial point providing services like tutoring and computer training...

Thread Class: Thread class is the main class on which Java's Multithreading system is based. Thread class, along with its companion interface Runnable will be used to create and run threads for utilizing Multithreading feature of Java. Constructors of Thread class: Thread ( ) Thread (String str) Thread... read more

Thread Class: Thread class is the main class on which Java's Multithreading system is based. Thread class, along with its companion interface Runnable will be used to create and run threads for utilizing Multithreading feature of Java.

Constructors of Thread class:

  1. Thread ( )
  2. Thread (String str)
  3. Thread (Runnable r)
  4. Thread (Runnable r, String str)

You can create new thread, either by extending Thread class or by implementing Runnable interface. Thread class also defines many methods for managing threads. Some of them are:

Method

Description

setName()

to give thread a name

getName()

return thread's name

getPriority()

return thread's priority

isAlive()

checks if thread is still running or not

join()

Wait for a thread to end

run()

Entry point for a thread

sleep()

suspend thread for a specified time

start()

start a thread by calling run() method

read less
Comments
Dislike Bookmark

Answered on 07 Mar IT Courses/Java/Core Java

Why Java is an independent language platform? Explain briefly.

Chinmay Karadkar

Expert Selenium And Appium Tutor

Java was created by James Gosling. And today Java became next widely used language for application development because of its platform independant nature. What does platform independancy means? It means your code will work on any machine i.e. any combination of OS and processor.A few combinations that... read more

Java was created by James Gosling. And today Java became next widely used language for application development because of its platform independant nature.

What does platform independancy means?

It means your code will work on any machine i.e. any combination of OS and processor.A few combinations that we see around are WinTel (Windows + Intel), LinTel (Linux + Intel), etc.

Java has a module called 'JVM' (java Vertual Machine). That interprits and compiles the java source code into an object code that can be used by the residing platform. Hence the source file is independant of the platform and object file is dependant on platform. The point to note here is that JVM is NOT platform independant.

If you have written a few LOC on windows and shift it to Mac, the code will be compiled by JVM of Mac and will be executed. If you have LOC on Mac and port it to windows it will be compiled by JVM of windows.

But if you port the object code from windows to Mac and vice-versa, code will not work.

read less
Answers 1 Comments
Dislike Bookmark

Lesson Posted on 02 Feb IT Courses/Java/Core Java IT Courses/Java

Understanding Object Serialization In Java

Vedant Kekan

I am working as a software developer, Worked with technologies such as Java,Spring Framework,Rest Webservice,...

Simple walkthrough: What is Serialization? Converting an object to bytes and bytes back to object (Deserialization): When is serialization used? When we want to Persist the Object. When we want the object to exist beyond the lifetime of the JVM: Real World Example. ATM:... read more

Simple walkthrough:

  • What is Serialization?

Converting an object to bytes and bytes back to object (Deserialization):

  • When is serialization used?

When we want to Persist the Object. When we want the object to exist beyond the lifetime of the JVM:

  • Real World Example.

ATM: When the account holder tries to withdraw money from the server through ATM, the account holder information like withdrawl details will be serialized and sent to server where the details are deserialized and used to perform operations:

  • How serialization is performed in java?
  1. Implement java.io.Serializable interface (marker interface so no method to implement).

  2. Persist the object: Use java.io.ObjectOutputStream class, a filter stream which is a wrapper around a lower-level byte stream (to write Object to file systems or transfer a flattened object across a network wire and rebuilt on the other side).

    • writeObject(<>) - to write an object
    • readObject() - to read an serialized Object
  • Remember:

When you serialize an object, only the object's state will be saved, not the object's class file or methods.

When you serialized a 2 byte object, you see 51 bytes serialized file.

Steps how the object is serialized and de-serialized.

Answer for: How did it convert to 51 bytes file?

  • First writes the serialization stream magic data (STREAM_MAGIC= "AC ED" and STREAM_VERSION=version of the JVM).
  • Then it writes out the metadata of the class associated with an instance (length of the class, the name of the class, serialVersionUID).
  • Then it recursively writes out the metadata of the superclass until it finds java.lang.Object.
  • Then starts with the actual data associated with the instance.
  • Finally writes the data of objects associated with the instance starting from metadata to actual content.

This will answer a few frequent questions:

  1. How not to serialize any field in class.
    Ans: use transient keyword

  2. When child class is serialized does parent class get serialized?
    Ans: No, If parent is not extending Serializable interface parents field don't get serialized.

  3. When parent is serialized does child class get serialized?
    Ans: Yes, by default child class also get serialized.

  4. How to avoid child class from getting serialized?
    Ans: a. Override writeObject and readObject method and throw NotSerializableException.

    b. also you can mark all fields transient in child class.

  5. Some system-level classes such as Thread, OutputStream and its subclasses, and Socket are not serializable.
read less
Comments
Dislike Bookmark

Looking for Java Training Classes

Find best Java Training Classes in your locality on UrbanPro.

FIND NOW

Lesson Posted on 31 Jan IT Courses/Java/Core Java

Crux Of The Basic Interview Question Asked Around It Professionals

Chinmay Karadkar

I kick-started my career as SDET in IT industry with a renowned firm. I have worked with Center of Excellence...

Question: Explain PSVM() [Public Static Void Main()] in Java. Answer: This question is asked from a differnet persctive. Person asking this question is looking for deep java concepts. If answer in your mind is something like this, "Public is used so that main() will be accssible everywhere, static... read more

Question: Explain PSVM() [Public Static Void Main()] in Java.

Answer:

This question is asked from a differnet persctive. Person asking this question is looking for deep java concepts.

If answer in your mind is something like this, "Public is used so that main() will be accssible everywhere, static is used so that no need to create object, void is because its not returning anything"

Then you are rejected stright-away.

Actual answer to this question is:

1. Public:

  • It is access modifier.
  • It is kept public since JVM should be able to access the main() from outside the package / project.

2. Static:

  • It is kept static so that JVM should be able to call the main() without creating an object. (Why to waste memory just to start something).

3. Void:

  • It is void since returning something from the main() is not something we intend to do.
  • However, you can return something indeed [from the main()].

4. Main:

  • It is a pre-specified word that the JVM searched for.
  • This name can be changed as well.
read less
Comments
Dislike Bookmark

Lesson Posted on 16 Jan IT Courses/Java/Core Java

Final, Finally And Finalize In Java

Md Ajmat

Currently working as a Senior Software Trainer at APTECH Malviya Nagar. I am having than 5+ years of...

Final: 1. It is a non access modifier that can be applied to variables,methods and to class. 2. Final means non-changable. Final variable: 1. If a variable is declared as final it can't be re-assigned. 2. If there is any final variable in class simply compiler replaces its original value to that... read more

Final:

1. It is a non access modifier that can be applied to variables,methods and to class.

2. Final means non-changable.

 

Final variable:

1. If a variable is declared as final it can't be re-assigned.

2. If there is any final variable in class simply compiler replaces its original value to that variable at compile time only,hence at runtime direct the constant value participates.

3. Final variable should must be initialized at the declaration time.

4. Final variable doesn't get any default value by compile or jvm,the programmer needs to initialize.

 

Final Method:

1. If we are declaring method as final in class, that method can't be re-defined or override.

2. If parent class want that their child can't re-define the method then parent class can define the final method in their class.

 

Final Class:

1. If we are declaraing class as final, that class can't be inherited.

2. For example-String class is final and we can't extends the String class.

 

Finally:

1. Finally is the keyword that comes along with try.

2. To write the clean-up code we can place the finally block. for example-Database closing logic,Stream closing logic or any other resource closing logic which we have opened.

3. This block must be executed irrespective of the Exception in the code.

 

Finalize:

1. This is the method of Object class and is applicable for all java objects.

2. Before destroying the objects, jvm calls the Garbage Collector and Garbage collector implicitly calls the finalize() method to perform the cleanup activity.

read less
Comments
Dislike Bookmark

Lesson Posted on 16 Jan IT Courses/Java/Core Java

Difference Between Checked And Un-Checked Exception

Md Ajmat

Currently working as a Senior Software Trainer at APTECH Malviya Nagar. I am having than 5+ years of...

1. Exception is an abnormal condition in the program, if raises program terminates abnormally. 2. Exception always occurs at runtime only, there is no chance of exception at compile time. 3. Syntactical mistakes or errors are occurs at compile time. 4. All Exceptions are the pre-defined class in java. 5.... read more

1. Exception is an abnormal condition in the program, if raises program terminates abnormally.

2. Exception always occurs at runtime only, there is no chance of exception at compile time.

3. Syntactical mistakes or errors are occurs at compile time.

4. All Exceptions are the pre-defined class in java.

5. Throwable is the root of all java Exceptions.

 

a. Checked Exception are Exception that has been checked by the compiler at compile time for the smooth execution of program at runtime. It doesn't mean the Excception has raised at compile time.

1. If there are any checked exception is raised at compile time means compiler concerned about how you will handle that condition at runtime. The Compiler will ask you for alternative code.

2. In case of checked exception compiler tries to know how you will handle the situation, so the alternate code they needed, by knowing this they will compile your code.

Ex-Except RuntimeException and Errors every Exceptions are checked in java.

Case 1.) If you are trying to read some file content through java code, in that case compile always concerned about "if file will not available at runtime then what will you do?". You have to give the alternate code by placing some local file.

FileReader fr=new FileReader("abc.txt");//it will throw Checke Exception

Case 2.) If you are tries to load some class at Runtime, in that case compiler will concerned about "if there is no availability of specified class, they how will you handle that situation".

Class.forName("oracle.jdbc.driver.OracleDriver"); //it will throw Checked Exception

Solution:This situation can be handled either by using 

1) Try-catch block,

2) Throws keyword,

 

Un-Checked Exception:

1. These are the exception about which compiler is not aware.

2. If there are any un-checked exceptions occurs,compiler won't ask for handling code.

3. All Errors and RuntimeException are un-checked by nature.

4. We can handle the situation only by using try-catch block.                                      

read less
Comments
Dislike Bookmark

Looking for Java Training Classes

Find best Java Training Classes in your locality on UrbanPro.

FIND NOW

Lesson Posted on 16 Jan IT Courses/Java/Core Java

Method Overloading vs Method Overriding

Md Ajmat

Currently working as a Senior Software Trainer at APTECH Malviya Nagar. I am having than 5+ years of...

1. Method Overloading: Method overloading means a same method with same name can have different implementations/body by changing one of the follwing thing: 1) Number of Parameters 2) Order of Parameters 3) Type of Parameter i. Method overloading can be performed only within class but not in the... read more

1. Method Overloading:

Method overloading means a same method with same name can have different implementations/body

by changing one of the follwing thing:

1) Number of Parameters

2) Order of Parameters

3) Type of Parameter

i. Method overloading can be performed only within class but not in the class in parent-child relations.

ii. Method overloading follows the Compile Time polymorphism means the "Method resolution is done by the comipler at compile time based on the object reference".

iii. Method overloading is also called as static polymorphism or Early binding or compile time polymophism.

class Test

{

           void m1()

            {

                      System.out.println("m1 with no-Parameter");

            }

            

           void m1(int x)

            {

                      System.out.println("m1 with 1-Parameter");

            }

             public static void main(String[] args)

             {

                        Test t=new Test();

                         t.m1();//m1 with no Parameter

                         t.m1(10);//m1 with 1 Parameter

              }

}

 

2. Method Overriding:

i. If a child class is not satisfied with the method implementation/body of Parent class method, in that case child class can re-define the parent class method(can change the implementation/body) without changing the signature.

ii. Re-definfing the parent class method in child class is called as method overriding.

iii. Method Overriding follows Runtime polymorphism means the method resolution is done by the JVM at runtime based on the runtime object.

iv. Method Overriding is also called as Dynamic Polymorphism or Late Binding.

v. Method Overriding can be done only in Parent-Child relation.

vi. Method Overriding is best way to desing the "loose coupling System " in which the degree of dependency between the java components are very less.

 

class Parent 

{

             void m1()

             {

                        System.out.println("m1 Of Parent!!");

             } 

}

class Parent extends Child

{

             void m1()

             {

                        System.out.println("I am Changing the body of Parent method in child class!!");

                        System.out.println("m1 Of Child!!");

             } 

}

class OverrideDemo

{

          public static void main(String[] args)

          {

                    Parent p=new Child();

                    p.m1();

          }

}

Output

---------

I am Changing the body of Parent method in child class!!

m1 Of Child!

read less
Comments
Dislike Bookmark

Asked on 12 Jan IT Courses/Java/Core Java

What is difference between Path and Classpath?

Answer

Lesson Posted on 18/12/2017 IT Courses/Java/Core Java

Why We Should Go With Java?

Bhupendra Patidar

I am an experienced, qualified teacher and tutor with over 2 years of experience in teaching and development...

Java is widely used in the Desktop application, web application, mobile development, games etc. Java is an object-oriented programming language. Its follow all the oops concept Like Object, Class, polymorphism, Inheritance, Encapsulation, Abstraction etc. Java is platform independent and... read more
  • Java is widely used in the Desktop application, web application, mobile development, games etc.

  • Java is an object-oriented programming language. Its follow all the oops concept Like Object, Class, polymorphism, Inheritance, Encapsulation, Abstraction etc.

  • Java is platform independent and strongly secured programming language so we can develop enterprises application like banking application.

  • Java is very simple to code easy syntax based on C++ and supporting automatic garbage collection.

read less
Comments 1
Dislike Bookmark

Looking for Java Training Classes

Find best Java Training Classes in your locality on UrbanPro.

FIND NOW

Answered on 02/12/2017 IT Courses/Java/Core Java

I live away from India and am looking for a tutor who can teach online. Please help

Chinmay Patel

Java J2ee Spring Angular JS Training

Private Java Classes by 12 Yrs Experienced Sw Engineer. Training will proceed at student s speed of understanding. Student can clear all his doubts and gets his basics strong. Training can be through Skype and remote desktop sharing software.
Answers 1 Comments 2
Dislike Bookmark

About UrbanPro

UrbanPro.com helps you to connect with the best Java Training Classes in India. Post Your Requirement today and get connected.

Overview

Questions 11

Lessons 32

Total Shares  

Related Topics

Top Contributors

Connect with Expert Tutors & Institutes for Core Java

x

Ask a Question

Please enter your Question

Please select a Tag

UrbanPro.com is India's largest network of most trusted tutors and institutes. Over 25 lakh students rely on UrbanPro.com, to fulfill their learning requirements across 1,000+ categories. Using UrbanPro.com, parents, and students can compare multiple Tutors and Institutes and choose the one that best suits their requirements. More than 6.5 lakh verified Tutors and Institutes are helping millions of students every day and growing their tutoring business on UrbanPro.com. Whether you are looking for a tutor to learn mathematics, a German language trainer to brush up your German language skills or an institute to upgrade your IT skills, we have got the best selection of Tutors and Training Institutes for you. Read more