Friday, August 25, 2017

Why it shows error when we keep different class name in different program

If you want to keep different class name, just remove 'public' keyword before class name.

It should be taken care that if a class is declared public, the java file name should be same as class name.

Monday, August 14, 2017

Why Char array is preferred over String to store password

String is immutable in java and stored in a separate pool called String pool pool of interned String. Once it's created it stays in the pool until unless it is 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.
If we use char array to store password, we can set it to blank once we are done with it. So we can control for how long it's available in memory that avoids the security threat with String.

String strPassword="Unknown";
char[] charPassword= new char[]{'U','n','k','w','o','n'};
System.out.println("String password: " + strPassword);
System.out.println("Character password: " + charPassword);

String password: Unknown
Character password: [C@110b053]

15 facts about computer program

https://youtu.be/Ayh8Fc2CVPw

Saturday, August 5, 2017

Find the second smallest number among three

import java.util.*;
public class Prog{
public static void main(String... args){
       Scanner in = new Scanner(System.in);
       int a,b,c,d,e;
       System.out.print("Enter 1st num: ");
       a = in.nextInt();
       System.out.print("Enter 2nd num: ");
       while((b=in.nextInt())==a){
             System.out.print("Duplicate.. Try again : ");
       }
       System.out.print("Enter 3rd num: ");
       while((c=in.nextInt())==b || c ==a){
               System.out.print("Duplicate.. Try again : ");
        }
        d = Math.min(a,b);
        e = Math.max(d,c);
        System.out.println(+e);
    }
}

Saturday, April 1, 2017

What is the purpose of creating an object?

मैं सामान्य भाषा में बात को समझने का आदि हूं.
आप सोंचिये कि आपने अपने रहने के लिये एक मकान का नक्शा बनवा लिया. तो क्या आप उस नक्शे में दर्शाये गये शयनकक्ष में आराम कर सकते हैं, या फिर उस नक्शे में दिखाये गये रसोईघर में गैस चूल्हा रख सकते हैं? क्या वहां आप भोजन पका सकते है?
नहीं न?
क्युंकि ये तो एक नक्शा है और आपको जरूरत होगी कि इस नक्शे पर आधारित किसी भूभाग पर मकान बनवाई जाय, ताकि आप इसका उपयोग कर सकें.
नक्शे से मकान बनाने की आवश्यकता को आप object बनाने के purpose सेे relate कर सकते हैं. इस उदाहरण में नक्शे को class और बनाये जानेवाले मकान को object समझें.
धन्यवाद

Tuesday, March 28, 2017

Configure your new jiofi router

You can perform this part before SIM activation as well. [You will have Internet connectivity only after the SIM is activated] Connect your PC (recommended) or Phone to the JioFi 2 hotspot with the default password listed on box.

  1. Open browser, type 192.168.1.1 or jiofi.local.html in the address bar and hit the enter key.
  2. The JioFi 2 router settings page will open, login with administrator as username and password.
  3. Jump into the WiFi section and change the SSID and security key as per your choice. The Security Key you set will be the WiFi password from now on.
  4. Press Apply and then OK to reboot the router. 
  5. Once the boot up completes you would need to re-connect using the new password.
  6. Again login to the Router settings page, and click on User Management. 
  7. Change the default user name and add a new password for router admin settings.
  8. Once done, click on Apply and OK.

Friday, March 24, 2017

Is JVM physically exist?

JVM (Java Virtual Machine) is not physical entity. It is just a Virtual machine. Here Virtual means not having physical existence.

What is Virtual machine?

Virtual machine is a simple software program which simulates the functions of a physical machine. This is not having physical existence, but which can perform all operations like physical machines. Physical machine whatever it is doing, all those things we can able to do on the virtual machine. Best example of virtual machine is computer; it is worked like physical calculator.

All virtual machines categorized in to 2 types

1. Hardware based or System based Virtual Machine

2. Software based or Application based or process based Virtual Machine

Hardware based virtual machines

Physically only one physical machine is there but several logical machines we can able to create on the single physical machine with strong isolation (worked independently) of each other. This type of virtual machines is called hardware based virtual machines.

Main advantage of hardware based virtual machine is effective utilization of hardware resources. Most of the times these types of virtual machines associated with admin role (System Admin, Server Admin etc). Programmers never associated with the hardware based virtual machines.

Examples of hardware based virtual machines are

1. KVM (Kernel Based VM) for Linux systems

2. VMware

3. Xen

4. Cloud Computing

Software based virtual machines

These virtual machines acts as run time engine to run a particular programming language applications. Examples of software based virtual machines are

1. JVM (Java Virtual Machine) acts as runtime engine to run Java applications

2. PVM (Parrot Virtual Machine) acts as runtime engine to run Perl applications

3. CLR (Common Language Runtime) acts as runtime engine to run .NET based applications

Thanks,

Regards
Ashok Kumar, Software Developer at Vistata IT

Wednesday, March 22, 2017

How to convert String into integer array

If the string is something like “12 41 21 19 15 10” and we want an into array, do like follows:

String test = "12 41 21 19 15 10";
// The string to be extracted to an integer array.
String[] intAsString = test.split(" ");
// Splits each space separated integer into a String array.
int[] integers = new int[intAsString.length];
// Creates the integer array.
int i=0;
for (String no : intAsString){
integers[i++] = Integer.parseInt(no);
}



Or if numbers are comma separated:
// String source = "1,2,3,56789,42";
private static int[] getIntsFromString(String source ) {
  String[] integersAsText =  
  source.split(",");
  int[] results = new 
  int[ integersAsText.length ];
  int i = 0;   for ( String textValue :
  integersAsText ) {
  results[i++] = 
  Integer.parseInt( textValue );
  }
  return results ;
}

How do you convert integer to String in Java?

Different possible ways to convert integer into String!
The first one is the easiest and the simplest:
int i = 1234;
String s = "" + i;
The second method uses the valueOf()function of the String class:
int i = 1234;
String s = String.valueOf(i);
The third one requires wrapper class Integer and uses its toString() function:
int i = 1234;
String s = new Integer(i).toString();
One more program
public class Test { public static void main(String[] args) {
// First Method
System.out.println(String.valueOf(12345));
// Second Method
System.out.println(Integer.toString(12345));
// Third Method
System.out.println(new Integer(12345).toString());
// Fourth Method
System.out.println(String.format("%d", 12345));
// Fifth Method
System.out.println(new StringBuffer().append(12345).toString());
// Six Method
System.out.println(new StringBuilder().append(12345).toString()); // Seventh Method
int num = 12345; String numString = "" + num; System.out.println(numString);
}
}
Output
12345
12345
12345
12345
12345
12345
12345


What is JVM?

What is the JVM?
6 ANSWERS
Assil Ksiksi

Some background first. Any native software (say written in C or C++) you run on your computer is, in simplified terms, a list of very basic instructions that your computer’s processor (or CPU) can understand directly.

The best way to think of the JVM is that it’s avirtual CPU (or virtual machine) that sits between your Java program and your computer’s real CPU i.e. Intel, AMD, etc.

A Java program contains a list of instructions that only the Java Virtual Machine (JVM) will understand. If you provide these instructions to your CPU directly, it won’t understand them, and your program will obviously fail to run.

So what does the JVM do then? Well, it executes the instructions provided by your Java program, and converts them to instructions that your CPU can understand behind the scenes.

OK, so why have the JVM at all? Why not have the Java program consist of real CPU instructions so it can run faster?

The answer to that is simple. Your Java program can run on any operating system that can run the JVM, which means that you can compile your Java code once and run it anywhere!

As for speed, thanks to the thousands of man-years of effort put into the amazing piece of technology that is the JVM, it shouldn’t be too much of a concern unless you need every last bit of performance.

Abhishek Katiyar

JVM is

  • runtime engine to run java based applications
  • to run program, classes line by line
  • part of JRE, JRE is a part of JDK
  • responsible to load .class files

Let me give you a detailed overview about JVM and its working. Basically there are 3 major parts in JVM which are illustrated in figure below



JVM is divided into three major parts

Class loader sub-system: Is responsible to load .class file

Memory area: There are five memory areas

  • Method area
  • Heap area
  • Stack area
  • PC register
  • Runtime method Stacks

Execution engine

Method Interfaces

The methods which are not implemented in java instead they are implemented in some other languages are known as native methods ex: Clone methods, hash-code methods

Sometimes Java requires native methods libraries and Java Native interface is responsible to provide native libraries and Method Interfaces are responsible for providing such type of functionalities

Further more dividing Class loader sub system is divided into three categories :

  1. Loading
  2. Linking
    1. Verification
    2. Preparation
    3. Resolution
  3. Initialization

Loading :

  • Loading means reading .class file data and storing corresponding binary data in the method area of JVM
  • For each .class file JVM will store
  • Fully qualified name of class
  • Fully qualified name of immediate parent
  • Whether .class file represents class/interface/enum
  • Methods/Constructors/Variables information
  • Modifiers information
  • Constant pool information
  • After loading every .class file Immediately JVM will Creates an Object of the Type class Class to represent to represent Class Level Binary Information on the Heap Memory
  • Programmer can use Class Class object to access class information
  • .class class object will be loaded and created only once even though we are using multiple times in class class object.

Linking

(a) Verification

  • It is the process of ensuring that binary representation of a class is structurally correct or not
  • i.e. whether .class file is properly formatted or not
  • i.e. whether .class file is generated by valid compiler or not
  • Internally bytecode verifier is responsible for the following activities which is a part of class loader sub system
  • If verification fails then we get runtime exception saying java lang.VerifyError

(b) Preparation

  • In this phase, just default values will be assigned and original values will be assigned in the initialization phase

(c) Resolution

  • It is the process of replacing symbolic references from the type with direct references. It is done by searching into method area to locate the referenced entity.

Initialization

Initialization : In this phase, all static variables are assigned with their values defined in the code and static block(if any). This is executed from top to bottom in a class and from parent to child in class hierarchy.

Ashok Kumar
Ashok Kumar, Software Developer at Vistata IT


A Java virtual machine (JVM) is an abstract computing machine that enables a computer to run a Java program. There are three notions of the JVM specification, implementation and instance. ... An instance of a JVM is an implementation running in a process that executes a computer program compiled into Java bytecode.

A Java virtual machine (JVM), an implementation of the Java Virtual Machine Specification, interprets compiled binary code (called bytecode) for a computer's processor (or "hardware platform") so that it can perform a Java program's instructions.Java was designed to allow application programs to be built that could be run on any platform without having to be rewritten or recompiled by the programmer for each separate platform. A Java virtual machine makes this possible because it is aware of the specific instruction lengths and other particularities of the platform used java virtual machine is an abstract computing machine that enables a computer to run a Java program.

Singh Mani

A Java virtual machine (JVM), an implementation of the Java Virtual Machine Specification, interprets compiled Java binary code (called bytecode) for a computer'sprocessor (or "hardware platform") so that it can perform a Java program's instructions. Java was designed to allow application programs to be built that could be run on any platform without having to be rewritten or recompiled by the programmer for each separate platform. A Java virtual machine makes this possible because it is aware of the specific instruction lengths and other particularities of the platform.

Narasimha Prasanna HN

C and C++ programming languages when compiled forms an Object code which can be understood by the machine..u can see the files having extensions .o these object codes are not directly readable hence its difficult to write them. In order make the development easy we use Programming languages which are readable.

But the main disadvantage of object files is that they are some what Machine dependant. Machine independency is one of the main feature of Java beocz it uses JVM. Java Virtual Machine separates Programming land and Hardware land which allows Programmers to code without talking care of Hardware.. Whenever a Java program is compiled.. JVM generates a Byte Code or in simple terms a Class file. This Byte Code is understandable only by JVM.. JVM makes use of System Libraries and Hardware to run the program. The advantages of JVM is that it can be configured easily and Developers can test the project by modifying the memory resources used by JVM. Thus testing is easy becoz the developers will get to know how their application runs under different resources.

There are many types of JVMs available for different platforms ex . Dalvik VM which runs on Linux kernel powering Android Phones.

JVMs have eliminated the risk of developing a Java Based platform which can understand only bytecodes..beocz it is A Virtual Machine which can be used on any Platform with little or no Modifications..Thus Java is Portable.