I started learning Java. But, until recently, I had no idea about the same. I didn't knew that something magical existed that would perform thisconversion. But now since I know a bit, I thought I better share it.
Java Decompiler
As you would have guessed by now, a Java Decompiler is a computer program capable of reversing the work done by a Compiler. In essence, it can convert back the Bytecode (the .class file) into the source code (the .java file).
There are many decompilers that exist today, but we will talk about the most widely used JD - Java Decompiler, which is available both as astand-alone GUI program and as an Eclipse-plugin.
To install and use these tools are a breeze and would not take you more than a few minutes to get accustomed to it. Hence, I would not repeat the process that's already mentioned on their site.One thing that we must note here is that the process of conversion mightNOT result into 100% exact code, i.e. the generated Java file might not match the actual Java code character by character. However, most of the code would be replicated but things like variable & function names or some other minor details may differ.L
ets have a look at the JD-GUI, stand-alone tool, written in C++;making it pretty fast to execute(decompile) and display the result. Also, it isindependent of the the Java Runtime Environment and thus no setup is required to install it.
Lets test the tool now.
Example Java Code:
public class test{public static void main(String[] args){System.out.println("Hello world");}}
Compile it: javac test.java
so that we have ByteCode (test.class file) with us now.
Decompile it using any one of the following ways:
Execute the following on the command line: jdi-gui.exe test.class
Select 'Open File' from the menu, browse to get to the test.class file and open it
Drag and Drop the test.class file into the JD-GUI tool
All of the above situations result in generating the following Java Code, have a look:
import java.io.PrintStream; public class test{public static void main(String[] paramArrayOfString){System.out.println("Hello world");}
Well just by seeing JD perform really well on this simple example,we cannot decide how efficient is this tool. But, still it is a tool thatevery Java Developer must be aware of. Because, in case you have accidently deletedyour Java files and are left with only the .class files, this is the tool that can save your neck.
Flow control in java is a key part as these are widely used in source code of any of the programs that are written in Java. In java, flow controls include if statement , switch statement, loops like for, while, do - while loop. These flow controls are described as following with it syntax and sample of source code.
These are oftenly called as decision statements. This is because whenever you use decision statements, you need to provide some mathematical expression that gets executed and decide which sort of action is to be taken.
if statement
Syntax for if statement is as follows:
if (expression) {
// any source code
}
In above syntax, expression is any mathematical expression that returns boolean value. Here, expression needs to be mandatorily boolean.
This expression can be anything like be "x" any variable whose value is to be compared with 1.
for example, if(x == 1) {
System.out.println("In if statement");
}
Above example shows that "x == 1" is checked and if value of "x" is "1" , then the expression will return "true" as value and then the control will move inside the if statement and print "In if statement" because "System.out.println()" is used to display any text on screen.
if statement also gets attached with else block. Its syntax would be
if (expression) {
// source code
} else {
// source code
}
In above syntax, if value of expression becomes "true" then only the control will enter into "if" block else control will enter into "else" block.
For example, if(x == 3) {
System.out.println("Value is 3.");
} else {
System.out.println("Value is not 3.");
}
In above example, if value of "x" is 3 then the control will enter inside "if" block and print "Value is 3." on screen and then control will not enter else block because "if" block has got executed. Similarly, if expression value has come out to be "false" then the control have directly entered into "else" block and would have printed "Value is not 3." on screen.
Furthermore, there is one more block which java provides and it is "else if " block. Its syntax would be something like this
if (expression1) {
// source code
} else if(expression2) {
// source code
} else {
// source code
}
In above syntax, if "expression1" gets satisfied then the control will enter into "if" block , execute the code written in it and come out of the block. Control will enter neither into "else if" block nor into "else" block.
If "expression1" is not satisfied, then the control will execute "else if" bloack and validate the expression. If "expression2" becomes true then the control will enter into "else if" block and execute the code written in "else if" block. But, if "expression1" and "expression2" are not satisfied too, then the control will enter directly into "else" block and execute the code written in it.
for example, if(x == 1) {
System.out.println("Value is 1.")
} else if( x == 2) {
System.out.println("Value is 2.")
} else {
System.out.println("Value is neither 1 nor 2.");
}
In above example, if "value" is 1 then "Value is 1." will get printed into screen. If value is 2 then "Value is 2." will get printed and if value is neither 1 nor 2, then "Value is neither 1 nor 2" will get printed or displayed.
There are following rules for using "else" and "else if" :
1: Zero or one "else" for a given "if" can be used and it must come after any else ifs.
2: We can have zero to many else ifs for a given "if" and they must come before the "else". "else" is optional.
3: If one "else if" gets executed then none of the remaining elses or else ifs will be tested.
Furthermore, two expressions can be given in one "if" statement.
Its syntax will be like this
if(expression1 && expression2) {
// Source code
}
Here, in above syntax, to make control of the program enter into "if" block, both "expression1" and "expression2" needs to be satisfied i.e. values of both expressions must be "true".
For example, consider value of x=1, y=2 then
if(x == 1 && y == 2) {
System.out.println("Values are 1 and 2.");
}
Here, in above example, if values of "x" and "y" are 1 and 2 respectively then only control of the program will enter into "if" block and print "Values are 1 and 2." on the screen. If either of the two values fails then control will not enter into "if" block and that's because of the use of logical AND operator " && " which demands both expressions to be mandatorily be "true" for execution.
We can use other operators as well like ! (NOT operator, which requires only one expression), !! (OR operator, which gets executed even if either of the expressions succeeds).
Syntax for using NOT operator will be something like this
if( !expression) {
// source code
}
Here, it will make the value of expression exactly the opposite i.e. if value of expression is "true" then by use of NOT (!) operator, value will get changed to "false" and vice-versa.
Similarly, with OR operator, its syntax will be
if(expression1 !! expression2) {
// source code
}
Here, if either "expression1" or "expression2" or both succeeds then the control will enter into "if" block but if neither of the expressions succeeds, "if" block will not get executed.
As the title suggests "Mobile operating system", Android is a java based mobile operating system with which mobile applications can be developed. Android strongly supports java. Any other programming language is not supportive to android. Cell phones with Android as operating system are not much in market. Cell phones of HTC comes with Android as their operating system. Recently, HTC mobile named as "Hero" was launched with operating system as Android. Android is an open source and very easy to install. Recently, 1.6 version of android sdk has been released.
All you need is to download SDK (Software Development Kit) which can be downloaded from developer.google.com/android.sdk/ . You also need to have Eclipse Ganymede or Eclipse Europa. SDK comes with virtual emulator which gets launched when any application is built in eclipse and ready for its execution or testing. Emulator gives exact look and feel of how your application will look on actual cell phone. Emulator, on its execution, gives UI of display sreen of a cell phone with num pad. When installed for first time, at the time of execution, virtual emulator takes time, may be 5 minutes or may be half an hour because it is running for the first time. APIs are also provided alongwith SDK.
Android is not in use much in indian market as most of cell phone companies use symbian as operating system for their sell phones. But sooner, android will be in demand and will occupy the market, for sure.
hi friends,
i myself found the solution for the java prog which i was unable to do, in my last article..
the solution is
the connecting function in the 2nd class..
public boolean UsrAuthPw(String username, String password){
boolean status = false;
try{
Connection con = getconnect();
Statement s = con.createStatement();
System.out.println("Username : "+ username +" Password : "+ password );
ResultSet rs = s.executeQuery("SELECT UserId, Password from usrauth where UserId = '"+ username +"' and Password = '"+ password +"'");
while (rs.next()){
status = true;
}
}
catch(java.sql.SQLException sqlexcp){
sqlexcp.printStackTrace();
System.out.println("SQL Exception");
status = false;
}
return status;
}
and the actionPerformed function of the 3rd class is,
public void actionPerformed(ActionEvent e){
String s1 = t1.getText();
String s2 = t2.getText();
if (s1.equals(s2)){
l3.setText("Both are same");
} else {
UsrConn uc = new UsrConn();
uc.getconnect();
boolean b = uc.UsrAuthPw(s1, s2);
if (b == true){
l3.setText("User logged in");
}
else{
l3.setText("Incorrect UserId or Password");
}
}
hi friends,
i was trying one java program, which gets the username and password from the user and has to check them if they r present in the database (MySQL) and has to give the result as soon as the OK button has been clicked..
i've created the GUI interface using eclipse and database in MySQL. My prob is that, i want to grab the text from the both text boxes, and have to search in MySQL with the texts typed in the text boxes.
i've used 3 classes, one for getting n setting the user id and password to MySQL, another one is for connecting the java and MySQL and the final is for GUI..
--> this is a function which i used in the 2nd class.. here, i pass the 3rd class's object to this function
public boolean UsrAuthPw(UsrVerf uv){
boolean status = false;
try{
Connection con = getconnect();
Statement s = con.createStatement();
String s1 = uv.t1.getText();
String s2 = uv.t2.getText();
ResultSet rs = s.executeQuery("SELECT UserId, Password from usrauth where UserId = ' "+s1+" ' and Password = ' "+s2+"' ");
System.out.println("UserId = '"+s1+"' and Password = '"+s2+"");
while (rs.next()){
System.out.println("1234");
status = true;
}
}
catch(java.sql.SQLException sqlexcp){
sqlexcp.printStackTrace();
System.out.println("SQL Exception");
status = false;
}
return status;
}
--> this is the main function of the 3rd class..
public static void main(String args[]){
JFrame frame = new JFrame("User Authentication");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
UsrVerf uv = new UsrVerf();
UsrConn uc = new UsrConn();
boolean status = false;
uc.getconnect();
uv.panelaction(frame);
uc.UsrAuthPw(uv);
if (status == true){
System.out.println("12345");
}else {
System.out.println("123456");
}
frame.pack();
frame.setVisible(true);
}
--> this wat i gave for the action to be done as soon as, the button is pressed..
public void actionPerformed(ActionEvent e){
String s1 = t1.getText();
String s2 = t2.getText();
if (s1.equals(s2)){
l3.setText("Both are same");
} else {
l3.setText("Processing....");
}
}
when i run the prog, i'm getting the GUI and if i give the correct user id and password, the output is like this..
UserId = ' ' and Password = ' '
123456
am i correct with this one..
can anyone get me clear..