0% found this document useful (0 votes)
35 views

Command Line Arguments, String Class and Its Method, Byte Code

The java command-line argument allows passing input to a Java program from the command prompt. Any number of arguments can be passed as strings and accessed within the program. Java bytecode is the machine-independent code generated by the Java compiler from Java source code. It allows Java programs to run on any platform with a Java Virtual Machine by translating the bytecode into native machine code. The String class in Java provides methods for creating and manipulating strings, including getting the length, concatenating strings, and converting case.
Copyright
© © All Rights Reserved
Available Formats
Download as ODP, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
35 views

Command Line Arguments, String Class and Its Method, Byte Code

The java command-line argument allows passing input to a Java program from the command prompt. Any number of arguments can be passed as strings and accessed within the program. Java bytecode is the machine-independent code generated by the Java compiler from Java source code. It allows Java programs to run on any platform with a Java Virtual Machine by translating the bytecode into native machine code. The String class in Java provides methods for creating and manipulating strings, including getting the length, concatenating strings, and converting case.
Copyright
© © All Rights Reserved
Available Formats
Download as ODP, PDF, TXT or read online on Scribd
You are on page 1/ 11

Java Command Line Arguments

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.

How does it works?

1.When we write a program in Java, firstly, the compiler compiles that program and a
bytecode is generated for that piece of code.

2. When we wish to run this .class file on any other platform.

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.

1. Java Applets and Applications


2. Security
3. Portability
String Class and Methods

* Strings are widely used in Java programming. It means sequence of characters.

* In Java programming language, strings are treated as objects.

* The Java platform provides the String class to create and manipulate strings.

Creating Strings

Simple method : String a = "Well come";

* 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 :

public class Demo


{
public static void main(String args[])
{
Char[ ] helloArray = { 'W', 'e', 'l', 'l', };

String helloString = new String(helloArray);

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 :

public class Demo


{

public static void main(String args[])


{
String p = "Well Come to CUK";
int leng = p.length();
System.out.println( "String Length is : " + leng );
}
}
Concatenating Strings

Syntax

string1.concat(string2);

Outcome : This returns a new string that is string1 with string2 added to it at the end.

* We can also use the concat() method with string literals

Example : "Well come ".concat(" to CUK");

* Strings are more commonly concatenated with the + operator

Example : "CUK," + " Kalaburagi"


Example :
public class Demo
{
public static void main(String args[])
{
String string1 = "come to cuk ";
System.out.println("Well " + string1 + "Kalaburagi");
}
}
Note : String class supports many methods

List of Methods and Its Descriptions

1. char charAt(int index) : Returns the character at the specified index.


2. int compareTo(Object o) : Compares this String to another Object.
3. String concat(String str) : Concatenates the specified string to the end of this string
4. int length() : Returns the length of the string
5. String toLowerCase() :Converts all of the characters in this String to lower case.
6. String toUpperCase() : Converts all of the characters in this String to upper case.

You might also like