Find the best tutors and institutes for BCA Tuition

Find Best BCA Tuition

Please select a Category.

Please select a Locality.

No matching category found.

No matching Locality found.

Outside India?

Search for topics

BCA Tuition Updates

Ask a Question

Post a Lesson

All

All

Lessons

Discussion

Lesson Posted on 07 Feb IT Courses/Java Tuition/BTech Tuition/Java Programming IT Courses/Java/Core Java +2 Tuition/BCA Tuition/Java Programming Tuition/Engineering Diploma Tuition/Java Programming less

What Is Java? Explain The History Of Java

Dev Group

Dev Group provides an in-depth IT & accounts training in Delhi. All the courses and training classes...

i. Ovierview: Java programming language was originally developed by Sun Microsystems which was initiated by James Gosling and released in 1995 as core component of Sun Microsystems' Java platform (Java 1.0 ). The latest release of the Java Standard Edition is Java SE 8. With the advancement of Java... read more

i. Ovierview: Java programming language was originally developed by Sun Microsystems which was initiated by James Gosling and released in 1995 as core component of Sun Microsystems' Java platform (Java 1.0 [J2SE]).

The latest release of the Java Standard Edition is Java SE 8. With the advancement of Java and its widespread popularity, multiple configurations were built to suit various types of platforms. For example: J2EE for Enterprise Applications, J2ME for Mobile Applications.

The new J2 versions were renamed as Java SE, Java EE, and Java ME respectively. Java is guaranteed to be Write Once, Run Anywhere.

 

ii. Java:

• Object Oriented: In Java, everything is an Object. Java can be easily extended since it is based on the Object model.

• Platform Independent: Unlike many other programming languages including C and C++, when Java is compiled, it is not compiled into platform specific machine, rather into platform independent byte code. This byte code is distributed over the web and interpreted by the Virtual Machine (JVM) on whichever platform it is being run on.

• Simple: Java is designed to be easy to learn. If you understand the basic concept of OOP Java, it would be easy to master.

• Secure: With Java's secure feature it enables to develop virus-free, tamper-free systems. Authentication techniques are based on public-key encryption.

• Architecture-neutral: Java compiler generates an architecture-neutral object file format, which makes the compiled code executable on many processors, with the presence of Java runtime system.

• Portable: Being architecture-neutral and having no implementation dependent aspects of the specification makes Java portable. Compiler in Java is written in ANSI C with a clean portability boundary, which is a POSIX subset.

• Robust: Java makes an effort to eliminate error prone situations by emphasizing mainly on compile time error checking and runtime checking.

• Multithreaded: With Java's multithreaded feature it is possible to write programs that can perform many tasks simultaneously. This design feature allows the developers to construct interactive applications that can run smoothly.

• Interpreted: Java byte code is translated on the fly to native machine instructions and is not stored anywhere. The development process is more rapid and analytical since the linking is an incremental and light-weight process.

• High Performance: With the use of Just-In-Time compilers, Java enables high performance.

• Distributed: Java is designed for the distributed environment of the internet.

• Dynamic: Java is considered to be more dynamic than C or C++ since it is designed to adapt to an evolving environment. Java programs can carry extensive amount of run-time information that can be used to verify and resolve accesses to objects on run-time.

 

iii. History of Java:

James Gosling initiated Java language project in June 1991 for use in one of his many set-top box projects. The language, initially called ‘Oak’ after an oak tree that stood outside Gosling's office, also went by the name ‘Green’ and ended up later being renamed as Java, from a list of random words.

Sun released the first public implementation as Java 1.0 in 1995. It promised Write Once, Run Anywhere (WORA), providing no-cost run-times on popular platforms.

On 13 November, 2006, Sun released much of Java as free and open source software under the terms of the GNU General Public License (GPL).

On 8 May, 2007, Sun finished the process, making all of Java's core code free and open-source, aside from a small portion of code to which Sun did not hold the copyright.

read less
Comments
Dislike Bookmark

Answered on 20 Jan Tuition/BCA Tuition/Java Programming

What is the difference between final, finally and finalize?

Md Ajmat

Sr. Software Trainer

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... 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
Answers 1 Comments
Dislike Bookmark

Lesson Posted on 20/11/2017 IT Courses/Java/Core Java IT Courses/Java Tuition/BCA Tuition/Java Programming +3 Tuition/BTech Tuition/Java Programming Tuition/Engineering Diploma Tuition/Java Programming Tuition/BA Tuition/Programming in JAVA less

Java: A Quick Overview

Vivek Ranjan Sahu

Experienced and qualified teachers are everywhere now-a-days. But along with that, I am also an analyser...

Not purely Object Oriented: It doesn't support multiple inheritence, it supports primitive data types and static members. Doesn’t support multiple inheritance: Reason is diamond problem i.e., if both parent classes have same method & not overridden by child, then at runtime ambiguity occurs. Platform... read more
  • Not purely Object Oriented: It doesn't support multiple inheritence, it supports primitive data types and static members.
  • Doesn’t support multiple inheritance: Reason is diamond problem i.e., if both parent classes have same method & not overridden by child, then at runtime ambiguity occurs.
  • Platform Independent: Compiled into platform independent bytecode.
  • Robust: Provides compile-time and runtime checks in order to eliminate error prone situations.
  • Multithreaded: Supports performing multiple tasks simultaneously.
  • Interpreted: Java bytecode is translated on the fly to native machine instructions and is not stored anywhere.
  • High Performance: Uses JIT compiler.
  • Secure.
  • Architectural neutral.
  • Portable.
  • Distributed.
  • Dynamic.
read less
Comments
Dislike Bookmark

Looking for BCA Tuition

Find best BCA Tuition in your locality on UrbanPro.

FIND NOW

Lesson Posted on 20/11/2017 IT Courses/Java/Core Java IT Courses/Java Tuition/BCA Tuition/Java Programming +3 Tuition/BTech Tuition/Java Programming Tuition/Engineering Diploma Tuition/Java Programming Tuition/BA Tuition/Programming in JAVA less

Comparable vs Comparator

Vivek Ranjan Sahu

Experienced and qualified teachers are everywhere now-a-days. But along with that, I am also an analyser...

java.lang.Comparable java.util.Comparator For comparing some other object with its own object. Ex. I am comparing myself to some other employee. Method signature is: int compareTo (T object). For implementing Comparable, access to the original class is required. The class itself needs... read more
java.lang.Comparable java.util.Comparator
  1. For comparing some other object with its own object. Ex. I am comparing myself to some other employee.
  2. Method signature is: 
    int compareTo (T object).
  3. For implementing Comparable, access to the original class is required.
  4. The class itself needs to implement Comparable and hence it is inside java.lang package.
  5. It can be used to provide single way of sorting.
  1. For comparing two objects by a separate class. Ex. Manager is comparing two employees with each other.
  2. Method signature is:
    int compare (T object1, T object2).
  3. If the required class is not accessible i.e., present inside some jar, then a Comparator implementation can be used that just accepts the two objects and do the comparison.
  4. It is a utility that can be used by an external class to perform the required action and hence it is inside java.util package.
  5. It can be used to provide multiple sorting ways like NameComparator, SalaryComparator etc.
read less
Comments
Dislike Bookmark

Lesson Posted on 20/11/2017 IT Courses/Java/Core Java IT Courses/Java Tuition/BCA Tuition/Java Programming +3 Tuition/BTech Tuition/Java Programming Tuition/Engineering Diploma Tuition/Java Programming Tuition/BA Tuition/Programming in JAVA less

ClassNotFoundException vs NoClassDefFoundError

Vivek Ranjan Sahu

Experienced and qualified teachers are everywhere now-a-days. But along with that, I am also an analyser...

ClassNotFoundException NoClassDefFoundError It is an exception and happens due to programmer’s mistake and can be recovered by updating the code. Thrown when an application tries to load a class through its String name using Class.forName or ClassLoader.findSystem or ClassLoader.loadClass... read more
ClassNotFoundException NoClassDefFoundError
  1. It is an exception and happens due to programmer’s mistake and can be recovered by updating the code.
  2. Thrown when an application tries to load a class through its String name using Class.forName or ClassLoader.findSystem or ClassLoader.loadClass methods.
  3. Thrown by application.
  1. It is an error and doesn’t happen due to programmer’s mistake and can’t be recovered by updating the code.
  2. Thrown if JVM is unable to find the class during runtime which was present at compile time. Ex. removing .class file just before running, will throw error.
  3. Thrown by JVM.
read less
Comments
Dislike Bookmark

Answered on 20/06/2017 Tuition/BCA Tuition Tuition/BCA Tuition/Java Programming

Manoj Kumar Vishwakarma

DBA Trainer

you learn self Java by good book. otherwise should be take help by tutors.
Answers 27 Comments 1
Dislike Bookmark

Looking for BCA Tuition

Find best BCA Tuition in your locality on UrbanPro.

FIND NOW

Lesson Posted on 29/05/2017 IT Courses/Java Tuition/BTech Tuition Tuition/BTech Tuition/Java Programming +3 Tuition/BCA Tuition Tuition/BCA Tuition/Java Programming Java Certification Classes less

Finding a Majority Element

Paras Chawla

Working as a Senior Software Developer(R and D) in the following technologies. 1. Java 2. J2EE/J2ME 3....

Problem Description Task. The goal in this code problem is to check whether an input sequence contains a majority element. Input Format. The first line contains an integer, the next one contains a sequence of non-negative integers 0, 1, . . . ,−1. Constraints. 1 ≤ ?? ≤ 10^5 ; 0 ≤ ????... read more

Problem Description Task.

The goal in this code problem is to check whether an input sequence contains a majority element.

Input Format. The first line contains an integer, the next one contains a sequence of non-negative integers 0, 1, . . . ,−1. Constraints. 1 ≤ ?? ≤ 10^5 ; 0 ≤ ???? ≤ 10^9 for all 0 ≤ ?? < ??.

Output Format. Output 1 if the sequence contains an element that appears strictly more than??/2 times, and 0 otherwise.

Pseudo code

findCandidate(a[], size)

  1. Initialize index and count of majority element

     maj_index = 0, count = 1

  1. Loop for i = 1 to size – 1

    (a) If a[maj_index] == a[i]

          count++

    (b) Else

        count--;

    (c) If count == 0

          maj_index = i;

          count = 1

  1. Return a[maj_index]

 

Java Code

import java.util.Scanner;

 

// Moore - Voting algorithm . Run-time complexity O(n)

public class MajorityElement {

     public static void main(String[] args) {

           Scanner scan = new Scanner(System.in);

           int n = scan.nextInt();

           long array[] = new long[n];

           for (int i = 0; i < n; i++)

                array[i] = scan.nextLong();

           long candidate = findCandidate(array, n);

           System.out.println(candidate);

           int count = 0;

           for (int i = 0; i < n; i++)

                if (array[i] == candidate)

                     count++;

           if (count > (n / 2))

                System.out.println("1");

           else

                System.out.println("0");

     }

 

     static long findCandidate(long array[], int n) {

           int index = 0;

           long count = 1;

           for (int i = 1; i < n; i++) {

                if (array[index] == array[i])

                     count++;

                else

                     count--;

                if (count == 0)

                     {index = i;

                      count = 1;}

           }

           return array[index];

     }

}

 

Output:

10

2 124554847 2 941795895 2 2 2 2 792755190 756617003

 

2

 

1

read less
Comments
Dislike Bookmark

Lesson Posted on 29/05/2017 Advanced Java coaching Tuition/BA Tuition Tuition/BA Tuition/Programming in JAVA +9 Tuition/BCA Tuition Tuition/BCA Tuition/Java Programming IT Courses/Big Data IT Courses/Hadoop Tuition/BTech Tuition Tuition/BTech Tuition/Java Programming Tuition/Engineering Diploma Tuition Tuition/Engineering Diploma Tuition/Advanced Java Programming IT Courses/Java less

Design Pattern

Paras Chawla

Working as a Senior Software Developer(R and D) in the following technologies. 1. Java 2. J2EE/J2ME 3....

Prototype Design Pattern: Ø Prototype pattern refers to creating duplicate object while keeping performance in mind. Ø This pattern involves implementing a prototype interface which tells to create a clone of the current object. Ø This pattern is used when creation of object directly... read more

Prototype Design Pattern:

Ø Prototype pattern refers to creating duplicate object while keeping performance in mind.

Ø This pattern involves implementing a prototype interface which tells to create a clone of the current object.

Ø This pattern is used when creation of object directly is costly. For example, an object is to be created after a costly database operation.

Ø We can cache the object, returns its clone on next request and update the database as and when needed thus reducing database calls.

 Prototype DP involves cloning of object and thus object needs to:

 Ø Implement Cloneable interface

 Ø Override clone() of Object class

 public abstract class Payment implements Cloneable {

    

       protected double amount;

          

        public double getAmount() {

                return amount;

           }

 

           public void setAmount(double amount) {

                this.amount = amount;

           }

          

     public abstract void makePayment();

    

     public Object clone() {

                 Object clone = null;

                 try {

                    clone = super.clone();

                 } catch (CloneNotSupportedException e) {

                    e.printStackTrace();

                 }

                 return clone;

              }   

}

public class CreditCard extends Payment {

 

     public void makePayment() {

           System.out.println("Payment of "+amount+ " by Credit Card");

     }

 

}

 

public class CashPayment extends Payment {

 

     public void makePayment() {

           System.out.println("Payment of "+amount+" by Cash");

     }

    

}

 

public class PaymentCache {

 

     private Map<String, Payment> map = new HashMap();

 

     public Payment getPayment(String key) {

           Payment payment = map.get(key);

           return (Payment) payment.clone();

     }

 

     // Map of Objects which are frequently used...

     // Original objects are acting as template objects...

 

     public void loadCache() {

           CashPayment cash = new CashPayment();

           cash.setAmount(2000);

           map.put("cash", cash);

 

           CreditCard credit = new CreditCard();

           credit.setAmount(4000);

           map.put("credit", credit);

     }

}

 

public class Client {

 

     public static void main(String[] args) {

           PaymentCache cache= new PaymentCache();

           cache.loadCache();

          

           Payment payment=cache.getPayment("cash");

           payment.makePayment();

          

           Payment payment1=cache.getPayment("credit");

           payment1.makePayment();

          

     }

}

 

Output:

Payment of 2000.0 by Cash

Payment of 4000.0 by Credit Card

Application:

Session replication from one server to another server.

Generating the GUI having many numbers of similar controls.

Advantage of Prototype Pattern:

It reduces the need of subclassing.

It hides complexities of creating objects.

The clients can get new objects without knowing which type of object it will be.

It lets you add or remove objects at runtime.

Usage of Prototype Pattern:

When the classes are instantiated at runtime.

When the cost of creating an object is expensive or complicated.

When you want to keep the number of classes in an application minimum.

When the client application needs to be unaware of object creation and representation.

 

read less
Comments
Dislike Bookmark

Lesson Posted on 25/05/2017 IT Courses/Java Tuition/BTech Tuition/Java Programming Advanced Java coaching +3 Tuition/BA Tuition/Programming in JAVA Tuition/BCA Tuition/Java Programming IT Courses/Java/Core Java less

How to create a Singleton class?

Gpcomptech

GPCompTech (GP Computer Technologies) is a software training institute located in Chandanagar Hyderabad,...

How to create a Singleton class: Q) What is a singleton class? A) In simple words, a singleton class is a class which can have only one instance at any point of time throughout the application and provides a global point of access to its instance. Q) How can you create a singleton class? A) class... read more

How to create a Singleton class:

Q) What is a singleton class?

A) In simple words, a singleton class is a class which can have only one instance at any point of time throughout the application and provides a global point of access to its instance.

 

Q) How can you create a singleton class?

A)

class Singleton {

       public static final Singleton INSTANCE = new Singleton();

       private Singleton() {

       }

}

                 This is a simple example for a singleton class where I used a public static final INSTANCE variable and initialized it with a Singleton object. Since INSTANCE is public static final, it can’t be reassigned and it is thread safe as well.

                 Singleton’s constructor is made private to prevent the instantiation of Singleton class from other classes. That means no other class can create an object for Singleton class with the new() operator and also no other class can extend this Singleton class with extends keyword. If any class wants to have an instance of Singleton it can have by accessing INSTANCE field of Singleton class like Singelton. INSTANCE as its static.

 

  1. Q) So here, Singleton instance will be created at the time of class loading that means when the Singleton class is loaded by JVM into memory. So it’s an early loading/instantiation of Singleton class and it occupies memory even when its not required yet, so what If we want this singleton instance to be created when it’s really required?

 

  1. A) I understand that you are interested in lazy loading/instantiation of Singleton. Here it is

 

class Singleton {

       private static Singleton INSTANCE;

       private Singleton() {

       }

       public static synchronized Singleton getInstance() {

              if (INSTANCE == null) {

                     INSTANCE = new Singleton();

              }

              return INSTANCE;

       }

}

 

  1. Q) You synchronized the whole method

       public static synchronized Singleton getInstance()

Don’t you see any performance overhead with this approach?

Only one thread can access the method getInstance at a time to get the Singleton instance and rest of all other threads need to wait even though INSTANCE is not null as its already created.

A) Let me create it using synchronized block instead of synchronized method, here how it goes

 

class Singleton {

       private static Singleton INSTANCE;

       private Singleton() {

       }

       public static Singleton getInstance() {

              if (INSTANCE == null) {             //----- 1st

                     synchronized (Singleton.class) {

                           if (INSTANCE == null) {   //----- 2nd

                                  INSTANCE = new Singleton();

                           }

                     }

              }

              return INSTANCE;

       }

}

 

  1. Q) Why do you use null check twice here?
  2. A) I think I don’t need to explain you why did I use first null check, as you know I am going to create Singleton instance in case INSTANCE is null otherwise I ll return the already created instance.

2nd null check is being used to ensure thread safety.

For suppose, 2 threads are concurrently trying to get the access for getInstance() and two threads are gone through the 1st null check and trying to enter into synchronized block, but only one thread(assume thread-1) got the lock on Singleton.class’s  object and enters the synchronized block while the other thread (assume thread-2)waiting for the lock. Once thread-1 went through 2nd null check then it creates a Singleton instance as INSTANCE is null and leaves the synchronized block and thus releases lock. Now, the waiting thread ( thread-2) holds the lock and enters the synchronized block.

 

If there is no 2nd null check there then there is a chance for the thread-2 to create another instance of Singleton class and thus it breaks the singleton here. For that reason we have 2nd null check here. So the thread-2 sees that INSTANCE is not null and comes out from the synchronized block without creating Singleton instance.

 

  1. Q) Ok. So double checking is for thread safety of a singleton.

 

 

  1. A) yes

 

Q) Do you think that, this Singleton class is still singleton?

I can break your singleton with the help of reflection like below

 

public class Test {

       public static void main(String args[]) {

              Singleton singleton1 = Singleton.getInstance();

              Singleton singleton2 = null;

              try {

                     // Test is package name contains Singleton class

                     Class singletonClass = Class.forName("Test.Singleton");

                     // as we know there is only one private constructor

                     Constructor cons = singletonClass.getDeclaredConstructor();

                     cons.setAccessible(true);

                     singleton2 = (Singleton) cons.newInstance();

                     System.out.println(singleton1 == singleton2 ? "Objects are equal" : "Objects are different");

              } catch (ClassNotFoundException | InstantiationException

                           | IllegalAccessException | IllegalArgumentException

                           | InvocationTargetException | NoSuchMethodException

                            | SecurityException e) {

                     e.printStackTrace();

              }

       }

}

 

  1. A) In that case I can implement Singleton like below for not to be broken with reflection

class Singleton {

       private static Singleton INSTANCE;

       private Singleton() {

              if (INSTANCE != null)

                     throw new RuntimeException(

                                  "Singleton can not be created more than once.");

       }

       public static Singleton getInstance() {

              if (INSTANCE == null) {

                     synchronized (Singleton.class) {

                           if (INSTANCE == null) {

                                  INSTANCE = new Singleton();

                           }

                     }

              }

              return INSTANCE;

       }

}

 

Private constructor will be called to instantiate the Singleton object through reflection. So we can throw some exception If INSTANCE field is not null (that means its already created).

 

  1. Q) So you think this implementation saves your Singleton from being broken from reflection. In my previous program, I am trying to create a Singleton object (singleton1) with the help of getInstance() and after that trying to create another object (singleton2) with the help of reflection. What happens If I do this in reverse like below

 

public class Test {

       public static void main(String args[]) {

//            Singleton singleton1 = Singleton.getInstance();

              Singleton singleton2 = null;

              try {

                     // Test is package name contains Singleton class

                     Class singletonClass = Class.forName("Test.Singleton");

                     // as we know there is only one private constructor

                     Constructor cons = singletonClass.getDeclaredConstructor();

                     cons.setAccessible(true);

                     singleton2 = (Singleton) cons.newInstance();

                     Singleton singleton1 = Singleton.getInstance();

                     System.out.println(singleton1 == singleton2 ? "Objects are equal" : "Objects are different");

              } catch (ClassNotFoundException | InstantiationException

                            | IllegalAccessException | IllegalArgumentException

                           | InvocationTargetException | NoSuchMethodException

                           | SecurityException e) {

                     e.printStackTrace();

              }

       }

}

 

Output:

 Objects are different

 

Here, If I try to create a Singleton object (singleton2) with the help of reflection first then it can proceed to create an Singleton object as the static field INSTANCE is still null at that time as getInstance() is not yet invoked. So we are allowed to create an many as objects we want for the Singleton using reflection before getInstance() is invoked and thus breaks the singleton. What do you say?

 

  1. A) Yeah, you are right. Let me come to you with slightly modified implementation of Singleton which protects itself from being broken with reflection.

 

class Singleton {

       private static Singleton INSTANCE;

       private static boolean instanceCreated = false;

       private Singleton() {

          & read less

Comments
Dislike Bookmark

Looking for BCA Tuition

Find best BCA Tuition in your locality on UrbanPro.

FIND NOW

Answered on 12/04/2017 Tuition/BCA Tuition Tuition/BCA Tuition/Java Programming

Manoj Kumar Vishwakarma

DBA Trainer

Please tell me which class you read then I can suggest you.
Answers 120 Comments
Dislike Bookmark

About UrbanPro

UrbanPro.com helps you to connect with the best BCA Tuition in India. Post Your Requirement today and get connected.

Overview

Lessons 22

Total Shares  

+ Follow 19,141 Followers

Related Topics

Top Contributors

Connect with Expert Tutors & Institutes for Java Programming

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