9lessons Programming Blog - Tutorials about Angular, ReactJS, PHP, MySQL and Web Development
Showing posts with label Java. Show all posts
Showing posts with label Java. Show all posts
Saturday, October 25, 2008

Java (JDK) Bin Directory Files Information


JAVAC.EXE
"javac" is the standard compiler in JDK.
"-sourcepath" specifies places where to search for source definitions of new types.
"-classpath" specifies places where to search for class definitions of new types.
Two types of "import" statements behave differently with "javac".
Never distribute your class files with debugging information in them.

>javac 9lesson.java

JAVA.EXE
"java" is the standard application launcher in JDK.
"-sourcepath" specifies places where to search for class definitions of new types.
"-jar" specifies a JAR file and launches the class specified in the manifest file.
"javaw" is identical to "java" except that it will not create the console window.

>java 9lesson

JDB.EXE
"jdb" is a nice debugging tool. But it only offers a command line interface, not so easy to use. It is much more efficient to use graphical interface debugger.
JPDA is well designed, allowing us to debug Java applications remotely.
Debugging multi-thread application is tricky. The following "jdb" notes may help you.
Whenever one thread reaches a break point, all other threads are stopped also.
The command prompt tells what is the current thread.
"where all" tells where the execution are currently in all threads.
"threads" lists all the threads with thread indexes as Hex numbers.

>jdb 9lesson

JAR.EXE
JAR files are ZIP files.
JAR files can have attributes stored in the META-INF/MANIFEST.MF file.
JAR files can be used in Java class paths.
JAR files can be "executable".

>jar xf src.jar

JAVAP.EXE
Used to get back the discription of bitecode:
Eg. If you deleted original source file (9lesson.java). You have only 9lesson.class file

>javap 9lesson

JAVADOC.EXE
Used to create Html file for webpage. 9lesson.java to 9lesson.html

>javadoc 9lesson.java

JVISUALVM.EXE
VisualVM is a visual tool integrating several commandline JDK tools and lightweight profiling capabilities. Designed for both production and development time use, it further enhances the capability of monitoring and performance analysis for the Java SE platform.


JRUNSCRIPT.EXE
Using jrunscript to test regular expressions

>jrunscript.exe
js> "!if:companyname[a!=b]".split(":")[0]
!if
js> "abcdef".match(/bc/)[0];
bc
js>

JAVA-RMI.EXE
If java-rmi.exe is running on your PC, you should verify that it is authentic. A file name alone is insufficient for identification. Run ProgramChecker Personal Edition and FileAnalyzer to be sure you are running the actual version.

JCONSOLE.EXE
jconsole is a GUI tool that allows you to monitor a local or remote JVM process using the JMX (Java Management Extension) technology.
JVM processes must be launched with the default JMX properties turned on in order to be connected by jconsole.
jconsole displays monitoring diagrams for heap memory usage, counts on loaded classes, counts on threads, and CPU usages.

KEYTOOL.EXE
A key entry in keystore contains a private key and a certificate of the public key.
Certificates can be exported into certificate files out of keystore.
Certificates can be imported from certificate back into keystore.
There seems be to no way to export private keys.
There seems be to no way to generate a certificate of a given public key - signing a public key.

native2ascii.exe
"native2ascii": A command line tool that reads a text file stored in a non-ASCII encoding and converts it to an ASCII text file. All non-ASCII characters will be converted into \udddd sequences, where dddd is the Unicode code value of the non-ASCII character.

"native2ascii" is an important Java tool, because Java compiler and other Java tools can only process files which contain ASCII characters and \udddd Unicode code sequences. If you have any non-ASCII character strings written in a native encoding included in your Java source code, you need to run this "native2ascii" tool to convert your Java source code.

"native2ascii" has the following command syntax:
native2ascii [options] inputfile outputfile

JSTAT.EXE
JDK 1.6 offers 3 nice JVM monitoring tools: jps, jstatd, and jstat.
jps is simple tool that allows you to list all running JVM processes on the local machine or a remote machine.
jstatd is an RMI server that allows you to access local JVM processes by jps and jstat from remote machines.
jstat is a monitoring tool that allows you to obtain sample data periodically from a local or remote JVM process.

APPLETVIEWER.EXE
We talked about how a web browser uses the applet tag to resolve and load an applet from a web server to the browsers JVM. Also, during class we commented that for development purposes, reasons for creating an extra source file. If the Appletviewer is a tool used during development, and if all that it does is scan the HTML file for the applet tag, why not include the applet tag within the Java source file as part of your program documentation.

/*
<APPLET CODE="HelloWorld.class" WIDTH=300 HEIGHT=300>
</APPLET>
*/

>appletviewer HelloWorld.java

Post your information. Please comment
Friday, October 24, 2008

Why Java is The Most Popular Language now?

Java is definitely the most popular programming language now, why? Why C,C++ and C# is not popular like Java?

Every Operating system having some executable formats
Eg. Windows - .exe, .cmd, .bat
Eg. Linux - .bin

These files operating system execute directly. Then what about .mp3,.class,.avi...... file. These files Windows can not execute directly its taking media player(Supporters) help.

Winamp software understant the .mp3 file formate. So Windows, Linux Operting System execute this file with the help of Media Players.

Same way after compile the C, C++ programs Compiler creates a executable file (.exe)

Eg : 9lessons.c ----> 9lessons.exe

Windows Operating System Directly access this 9lessons.exe file and print the output. But in Linux(os) can not understand this *.exe format. So C, C++ Dependent Languages

But Java Compiler convert .java file to .class format. Windows execute this file with the help of JRE (Java Runtime Enviroment).

Sun Microsystems Providing Different JREs for Different Operating System


Virus Programmer's Main Aim to interrupt the User's work. So the programmer creates a virus file in Operating System Executable format like .exe, .cmd, .bat (for windows)

If you did a project in C, C++ Language. If any virus attack means it damage the total executable(.exe) files. so C, C++ project files also damage. But java file creates a .class file its like byte code formate. If attact means JRE (Java Runtime Enviroment) only damage. So you java project safe....

What about .Net. It is a best software development package. Why it's not independent ?.

Microsoft People can Write the code for .Net Independent platform. If they will make the next moment onwards no one will buy the Windows Operating System.

Company business aspects they will give Preference to open source operating System like Linux and Solaris.

C, C++ --> Console application programs
Java --> Console - Windows Frames - Web

Links :
Java (JDK) Bin Directory Files Information
Analysis of a Java Class
What Web Server Do?
Google Search Architecture Diagram Overview
The Stock Market Story

Most Popular Articles:-Most Popular Articles Links

If any mistakes please comment me...
Wednesday, October 15, 2008

Java Access Modifiers Lesson

A modifiers assigns characteristics to the methods, data and variables. It specifies the availability of the method to other methods or classes. Variables and methods can be at any of the following access levels:

Default | Public | Private | Protected



public :

No doubt public variable any one can acess, class or methods are universally accessible.

Oxigen public propery...

default :

Classes can be at default level. If you do not give any explicit modifier to a variable, class or method they will be automatically treated as Default.
It means that access is permitted from any method only in classes that are members of the same package as the target.

Eg:

class 9lesson
{
int i; (Default)
}


private :

private variables or methods can be accessed only from the methods of the class to which it belongs. A subclass also does not have access to the private variables.

Debit card having security pin number

protected :

a protected variable or method is accessible from any class of the same package or from any subclass is in a different package.

This is like father and child relation.





The first class is SubclassInSamePackage.java which is present in pckage1 package. This java file contains the Base class and a subclass within the enclosing class that belongs to the same class as shown below.


package pckage1;

class BaseClass {

public int x = 10;
private int y = 10;
protected int z = 10;
int a = 10; //Implicit Default Access Modifier
public int getX() {
return x;
}
public void setX(int x) {
this.x = x;
}
private int getY() {
return y;
}
private void setY(int y) {
this.y = y;
}
protected int getZ() {
return z;
}
protected void setZ(int z) {
this.z = z;
}
int getA() {
return a;
}
void setA(int a) {
this.a = a;
}
}

public class SubclassInSamePackage extends BaseClass {

public static void main(String args[]) {
BaseClass rr = new BaseClass();
rr.z = 0;
SubclassInSamePackage subClassObj = new SubclassInSamePackage();
//Access Modifiers - Public
System.out.println("Value of x is : " + subClassObj.x);
subClassObj.setX(20);
System.out.println("Value of x is : " + subClassObj.x);
//Access Modifiers - Public
// If we remove the comments it would result in a compilaton
// error as the fields and methods being accessed are private
/* System.out.println("Value of y is : "+subClassObj.y);

subClassObj.setY(20);

System.out.println("Value of y is : "+subClassObj.y);*/
//Access Modifiers - Protected
System.out.println("Value of z is : " + subClassObj.z);
subClassObj.setZ(30);
System.out.println("Value of z is : " + subClassObj.z);
//Access Modifiers - Default
System.out.println("Value of x is : " + subClassObj.a);
subClassObj.setA(20);
System.out.println("Value of x is : " + subClassObj.a);
}
}

Output

Value of x is : 10
Value of x is : 20
Value of z is : 10
Value of z is : 30
Value of x is : 10
Value of x is : 20

The second class is SubClassInDifferentPackage.java which is present in a different package then the first one. This java class extends First class (SubclassInSamePackage.java).


import pckage1.*;

public class SubClassInDifferentPackage extends SubclassInSamePackage {

public int getZZZ() {
return z;
}

public static void main(String args[]) {
SubClassInDifferentPackage subClassDiffObj = new SubClassInDifferentPackage();
SubclassInSamePackage subClassObj = new SubclassInSamePackage();
//Access specifiers - Public
System.out.println("Value of x is : " + subClassObj.x);
subClassObj.setX(30);
System.out.println("Value of x is : " + subClassObj.x);
//Access specifiers - Private
// if we remove the comments it would result in a compilaton
// error as the fields and methods being accessed are private
/* System.out.println("Value of y is : "+subClassObj.y);

subClassObj.setY(20);

System.out.println("Value of y is : "+subClassObj.y);*/
//Access specifiers - Protected
// If we remove the comments it would result in a compilaton
// error as the fields and methods being accessed are protected.
/* System.out.println("Value of z is : "+subClassObj.z);

subClassObj.setZ(30);

System.out.println("Value of z is : "+subClassObj.z);*/
System.out.println("Value of z is : " + subClassDiffObj.getZZZ());
//Access Modifiers - Default
// If we remove the comments it would result in a compilaton
// error as the fields and methods being accessed are default.
/*

System.out.println("Value of a is : "+subClassObj.a);

subClassObj.setA(20);

System.out.println("Value of a is : "+subClassObj.a);*/
}
}

Output

Value of x is : 10
Value of x is : 30
Value of z is : 10

The third class is ClassInDifferentPackage.java which is present in a different package then the first one.


import pckage1.*;

public class ClassInDifferentPackage {

public static void main(String args[]) {
SubclassInSamePackage subClassObj = new SubclassInSamePackage();
//Access Modifiers - Public
System.out.println("Value of x is : " + subClassObj.x);
subClassObj.setX(30);
System.out.println("Value of x is : " + subClassObj.x);
//Access Modifiers - Private
// If we remove the comments it would result in a compilaton
// error as the fields and methods being accessed are private
/* System.out.println("Value of y is : "+subClassObj.y);

subClassObj.setY(20);

System.out.println("Value of y is : "+subClassObj.y);*/
//Access Modifiers - Protected
// If we remove the comments it would result in a compilaton
// error as the fields and methods being accessed are protected.
/* System.out.println("Value of z is : "+subClassObj.z);

subClassObj.setZ(30);

System.out.println("Value of z is : "+subClassObj.z);*/
//Access Modifiers - Default
// If we remove the comments it would result in a compilaton
// error as the fields and methods being accessed are default.
/* System.out.println("Value of a is : "+subClassObj.a);

subClassObj.setA(20);

System.out.println("Value of a is : "+subClassObj.a);*/
}
}

Output

Value of x is : 10
Value of x is : 30



Please Comment...
Tuesday, September 30, 2008

Analysis of a Java Class

When the JVM(Java Virtual Machine) starts running, it looks for the class you give it an the command line. Then its starts looking for a specially-written method that looks exactly like:


public static void main(String args[])

{
//your code......
}


Next, the JVM runs everything between the curly braces{} of your main method. Every Java application has to have at least one Class, and at least one main method (not one main per class; just one main per application).



In Java, everything goes in a class. Your'll type your source code file (with a .java extension), then compile it into a new class file (with a .class extension). When your run your program, you're really running a class.

Running a program means telling the Java Virtual Machine (JVM) to "Load the 9lessons class, then start executing its main() method. Keep running till all the code in main is finished.

The main() method is where your program starts running.

9lessons.java

public class 9lessons

{

public static void main(String[] args)

{

System.out.println("Programming Blog");

}

}



step 1: javac 9lessons.java

step 2: java 9lessons

The Big Difference Between public class and Default class

9lessons.java

public class program

{

public static void main(String[] args)

{

System.out.println("Programming Blog");

}

}


Above programe file name is (9lessons.java) and public class name (program) is different



Error : Class program is public, should be declared in a file named program.java

So public class means file name and class name must be same..

Here Default Class(no public)

9lessons.java

class program

{

public static void main(String[] args)

{

System.out.println("Programming Blog");

}

}




After compiling 9lesson.java creates program.class



In the Defalult class no need to give file name and class name same..

step 1: javac 9lessons.java

step 2: java program

If any mistakes please comment me..

Related Articles:

Connecting JSP To Mysql Database Lesson

Web.xml Deployment Descriptor
Tuesday, September 23, 2008

Web.xml Deployment Descriptor

Web.xml mapping servlet names improve web app's flexibility and security..The deployment descriptor (DD), provides a "declarative" mechanism for customizing your web applications without touching source code!

Tomcat Directory Structure

Login.java


import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;

public class Login extends HttpServlet{

public void doGet(HttpServletRequest request,
HttpServletResponse response)throws IOException{

PrintWriter out=response.getWriter();
java.util.Date tody=new java.util.Date();
out.println("out put html tags");

}
}


<servlet>Maps internal name to fully-qualified class name.


<servlet-mapping>Maps internal name to public URL name.

web.xml



<servlet-mapping> which servlet should i invoke for this requested URL?


<web-app xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee web-app_2_4.xsd" version="2.4">

<servlet>
<servlet-name>Servlet_login</servlet-name>
<servlet-class>Login</servlet-class>
</servlet>

<servlet>
<servlet-name>Servlet_inbox</servlet-name>
<servlet-class>inbox</servlet-class>
</servlet>


<servlet-mapping>
<servlet-name>Servlet_login</servlet-name>
<url-pattern>/signin.do</usr-pattern>
</servlet-mapping>

<servlet-mapping>
<servlet-name>Servlet_inbox</servlet-name>
<url-pattern>/view.do</usr-pattern>
</servlet-mapping>

</web-app>


signin.do file mapping to Login.class. So the client or users to get to the servlet.. but it's a made-up name that is NOT the name of the actual servlet class.
mailxengine Youtueb channel
Make in India
X