Command Line Arguments, String Class and Its Method, Byte Code
Command Line Arguments, String Class and Its Method, Byte Code
The java command-line argument is an argument i.e. passed at the time of running the java
program.
The arguments passed from the console can be received in the java program and it can be
used as an input.
So, it provides a convenient way to check the behavior of the program for the different
values. You can pass ‘N’ numbers of arguments from the command prompt.
Example :
class Example
{
public static void main(String args[])
{
for(int i=0;i<args.length;i++)
System.out.println(args[i]);
}
}
Java Byte Code
What is Java Bytecode?
java bytecode is the machine code in the form of a .class file. With the help of java
bytecode we achieve platform independence in java.
1.When we write a program in Java, firstly, the compiler compiles that program and a
bytecode is generated for that piece of code.
3. After the first compilation, the bytecode generated is now run by the Java Virtual
Machine and not the processor in consideration. This essentially means that we only
need to have basic java installation on any platforms that we want to run our code on.
4. Resources required to run the bytecode are made available by the Java Virtual Machine,
which calls the processor to allocate the required resources.
Advantages of Java Bytecode
1. Platform independence is one of the soul reasons for which James Gosling started the
formation of java and it is this implementation of bytecode which helps us to achieve this.
Hence bytecode is a very important component of any java program.
2. The set of instructions for the JVM may differ from system to system but all can interpret
the bytecode.
3. A point to keep in mind is that bytecodes are non-runnable codes and rely on the
availability of an interpreter to execute and thus the JVM comes into play.
4. Bytecode is essentially the machine level language which runs on the Java Virtual
Machine.
5.Whenever a class is loaded, it gets a stream of bytecode per method of the class.
Whenever that method is called during the execution of a program, the bytecode for that
method gets invoked. Javac not only compiles the program but also generates the bytecode
for the program. Thus, we have realized that the bytecode implementation makes Java a
platform-independent language.
Why java is important to the
Internet?
Java expands the universe of objects that can move about freely in cyberspace. In a
network, two very broad categories of objects are transmitted between the server and your
personal computer: passive information and dynamic, active programs.
Note : For example, when you read your e-mail, you are viewing passive data. Even when
you download a program, the program’s code is still only passive data. Even when you
download a second type of object can be transmitted to your computer: a dynamic, self-
executing program. Such a program is and the server yet initiates active agent on the client
computer.
* The Java platform provides the String class to create and manipulate strings.
Creating Strings
* We can create String objects by using the new keyword and a constructor in Java.
Note : The String class has 11 constructors that allow you to provide the initial value of
the string using different sources, such as an array of characters.
Example :
System.out.println( helloString );
}
}
String Length :
1. Methods used to obtain information about an object are known as accessor methods.
2. One accessor method that we can use with strings is the length() method, which
returns the number of characters contained in the string object.
Example :
Syntax
string1.concat(string2);
Outcome : This returns a new string that is string1 with string2 added to it at the end.